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