blob: 881a9cfa6a6d345c84d94d91d47b0fd0a3b8cb79 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (c) 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Marc-Andre Laperle - Initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg;
import java.io.File;
import org.eclipse.core.resources.IResource;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.swt.graphics.Image;
/**
* An ExportTraceElement representing the trace files of a trace.
*
* @author Marc-Andre Laperle
*/
public class TracePackageFilesElement extends TracePackageElement {
private static final String TRACE_ICON_PATH = "icons/elcl16/trace.gif"; //$NON-NLS-1$
private final String fFileName;
private final IResource fResource;
private long fSize = -1;
/**
* Constructs an instance of ExportTraceFilesElement when exporting
*
* @param parent
* the parent of this element, can be set to null
* @param resource
* the resource representing the trace file or folder in the
* workspace
*/
public TracePackageFilesElement(TracePackageElement parent, IResource resource) {
super(parent);
fFileName = null;
fResource = resource;
}
/**
* Constructs an instance of ExportTraceFilesElement when importing
*
* @param parent
* the parent of this element, can be set to null
* @param fileName
* the name of the file to be imported
*/
public TracePackageFilesElement(TracePackageElement parent, String fileName) {
super(parent);
fFileName = fileName;
fResource = null;
}
private long getSize(File file) {
if (file.isDirectory()) {
long size = 0;
for (File f : file.listFiles()) {
size += getSize(f);
}
return size;
}
return file.length();
}
@Override
public long getSize(boolean checkedOnly) {
if (checkedOnly && !isChecked()) {
return 0;
}
if (fSize == -1 && fResource.exists()) {
File file = fResource.getLocation().toFile();
fSize = getSize(file);
}
return fSize;
}
@Override
public String getText() {
return Messages.TracePackage_TraceElement;
}
@Override
public Image getImage() {
return Activator.getDefault().getImageFromImageRegistry(TRACE_ICON_PATH);
}
/**
* Get the file name for this trace file or folder
*
* @return the file name for this trace file or folder
*/
public String getFileName() {
return fFileName;
}
}
|