ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfTraceElement.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 Ericsson, École Polytechnique de Montréal
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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added supplementary files handling
12 * Geneviève Bastien - Moved supplementary files handling to parent class,
13 * added code to copy trace
14 * Patrick Tasse - Close editors to release resources
15 * Jean-Christian Kouame - added trace properties to be shown into
16 * the properties view
17 * Geneviève Bastien - Moved trace type related methods to parent class
18 *******************************************************************************/
19
20 package org.eclipse.linuxtools.tmf.ui.project.model;
21
22 import java.util.Arrays;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.eclipse.core.filesystem.EFS;
30 import org.eclipse.core.filesystem.IFileInfo;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IFolder;
33 import org.eclipse.core.resources.IResource;
34 import org.eclipse.core.runtime.CoreException;
35 import org.eclipse.core.runtime.IConfigurationElement;
36 import org.eclipse.core.runtime.IPath;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.Platform;
39 import org.eclipse.core.runtime.URIUtil;
40 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
41 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
42 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
43 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtEvent;
44 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
45 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition;
46 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlEvent;
47 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace;
48 import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition;
49 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
50 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
51 import org.eclipse.linuxtools.tmf.core.synchronization.TimestampTransformFactory;
52 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat;
53 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
54 import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
55 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
56 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
57 import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
58 import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
59 import org.eclipse.osgi.util.NLS;
60 import org.eclipse.swt.widgets.Display;
61 import org.eclipse.ui.IActionFilter;
62 import org.eclipse.ui.views.properties.IPropertyDescriptor;
63 import org.eclipse.ui.views.properties.IPropertySource2;
64
65 import com.ibm.icu.text.DateFormat;
66 import com.ibm.icu.text.NumberFormat;
67
68 /**
69 * Implementation of trace model element representing a trace. It provides
70 * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
71 * well as editor ID from the trace type extension definition.
72 *
73 * @version 1.0
74 * @author Francois Chouinard
75 */
76 public class TmfTraceElement extends TmfCommonProjectElement implements IActionFilter, IPropertySource2 {
77
78 // ------------------------------------------------------------------------
79 // Constants
80 // ------------------------------------------------------------------------
81
82 // Other attributes
83 /**
84 * Bundle attribute name
85 */
86 public static final String BUNDLE = "bundle"; //$NON-NLS-1$
87 /**
88 * IsLinked attribute name.
89 */
90 public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$
91
92 // Property View stuff
93 private static final String sfResourcePropertiesCategory = Messages.TmfTraceElement_ResourceProperties;
94 private static final String sfName = Messages.TmfTraceElement_Name;
95 private static final String sfPath = Messages.TmfTraceElement_Path;
96 private static final String sfLocation = Messages.TmfTraceElement_Location;
97 private static final String sfTraceType = Messages.TmfTraceElement_EventType;
98 private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
99 private static final String sfSourceLocation = Messages.TmfTraceElement_SourceLocation;
100 private static final String sfTimeOffset = Messages.TmfTraceElement_TimeOffset;
101 private static final String sfLastModified = Messages.TmfTraceElement_LastModified;
102 private static final String sfSize = Messages.TmfTraceElement_Size;
103 private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
104
105 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
106 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
107 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
108 private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfTraceType, sfTraceType);
109 private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
110 private static final ReadOnlyTextPropertyDescriptor sfSourceLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfSourceLocation, sfSourceLocation);
111 private static final ReadOnlyTextPropertyDescriptor sfTimeOffsetDescriptor = new ReadOnlyTextPropertyDescriptor(sfTimeOffset, sfTimeOffset);
112 private static final ReadOnlyTextPropertyDescriptor sfLastModifiedDescriptor = new ReadOnlyTextPropertyDescriptor(sfLastModified, sfLastModified);
113 private static final ReadOnlyTextPropertyDescriptor sfSizeDescriptor = new ReadOnlyTextPropertyDescriptor(sfSize, sfSize);
114
115 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
116 sfTypeDescriptor, sfIsLinkedDescriptor, sfSourceLocationDescriptor,
117 sfTimeOffsetDescriptor, sfLastModifiedDescriptor, sfSizeDescriptor };
118
119 static {
120 sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
121 sfPathDescriptor.setCategory(sfResourcePropertiesCategory);
122 sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
123 sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
124 sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
125 sfSourceLocationDescriptor.setCategory(sfResourcePropertiesCategory);
126 sfTimeOffsetDescriptor.setCategory(sfResourcePropertiesCategory);
127 sfLastModifiedDescriptor.setCategory(sfResourcePropertiesCategory);
128 sfSizeDescriptor.setCategory(sfResourcePropertiesCategory);
129 }
130
131 private static final TmfTimestampFormat OFFSET_FORMAT = new TmfTimestampFormat("T.SSS SSS SSS s"); //$NON-NLS-1$
132
133 private static final int FOLDER_MAX_COUNT = 1024;
134
135 // ------------------------------------------------------------------------
136 // Static initialization
137 // ------------------------------------------------------------------------
138
139 // The mapping of available trace type IDs to their corresponding
140 // configuration element
141 private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<>();
142 private static final Map<String, IConfigurationElement> sfTraceTypeUIAttributes = new HashMap<>();
143 private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<>();
144
145 /**
146 * Initialize statically at startup by getting extensions from the platform
147 * extension registry.
148 */
149 public static void init() {
150 /* Read the tmf.core "tracetype" extension point */
151 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
152 for (IConfigurationElement ce : config) {
153 switch (ce.getName()) {
154 case TmfTraceType.TYPE_ELEM:
155 String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
156 sfTraceTypeAttributes.put(traceTypeId, ce);
157 break;
158 case TmfTraceType.CATEGORY_ELEM:
159 String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
160 sfTraceCategories.put(categoryId, ce);
161 break;
162 default:
163 }
164 }
165
166 /*
167 * Read the corresponding tmf.ui "tracetypeui" extension point for this
168 * trace type, if it exists.
169 */
170 config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
171 for (IConfigurationElement ce : config) {
172 String elemName = ce.getName();
173 if (TmfTraceTypeUIUtils.TYPE_ELEM.equals(elemName)) {
174 String traceType = ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR);
175 sfTraceTypeUIAttributes.put(traceType, ce);
176 }
177 }
178 }
179
180 // ------------------------------------------------------------------------
181 // Classes
182 // ------------------------------------------------------------------------
183
184 private class FileInfo {
185 long lastModified;
186 long size;
187 int count;
188 }
189
190 // ------------------------------------------------------------------------
191 // Attributes
192 // ------------------------------------------------------------------------
193
194 private FileInfo fFileInfo;
195
196 // ------------------------------------------------------------------------
197 // Constructors
198 // ------------------------------------------------------------------------
199 /**
200 * Constructor. Creates trace model element under the trace folder.
201 *
202 * @param name
203 * The name of trace
204 * @param trace
205 * The trace resource.
206 * @param parent
207 * The parent element (trace folder)
208 */
209 public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
210 super(name, trace, parent);
211 }
212
213 /**
214 * Constructor. Creates trace model element under the experiment folder.
215 *
216 * @param name
217 * The name of trace
218 * @param trace
219 * The trace resource.
220 * @param parent
221 * The parent element (experiment folder)
222 */
223 public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
224 super(name, trace, parent);
225 }
226
227 // ------------------------------------------------------------------------
228 // Operations
229 // ------------------------------------------------------------------------
230
231 /**
232 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
233 * the corresponding extension.
234 *
235 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
236 */
237 @Override
238 public ITmfTrace instantiateTrace() {
239 try {
240
241 // make sure that supplementary folder exists
242 refreshSupplementaryFolder();
243
244 if (getTraceType() != null) {
245 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
246 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
247 if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) {
248 return new CustomTxtTrace(def);
249 }
250 }
251 }
252 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
253 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
254 if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) {
255 return new CustomXmlTrace(def);
256 }
257 }
258 }
259 IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
260 if (ce == null) {
261 return null;
262 }
263 ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
264 return trace;
265 }
266 } catch (CoreException e) {
267 Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e); //$NON-NLS-1$
268 }
269 return null;
270 }
271
272 /**
273 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
274 * the corresponding extension.
275 *
276 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
277 */
278 public ITmfEvent instantiateEvent() {
279 try {
280 if (getTraceType() != null) {
281 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
282 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
283 if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) {
284 return new CustomTxtEvent(def);
285 }
286 }
287 }
288 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
289 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
290 if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) {
291 return new CustomXmlEvent(def);
292 }
293 }
294 }
295 IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType());
296 if (ce == null) {
297 return null;
298 }
299 ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
300 return event;
301 }
302 } catch (CoreException e) {
303 Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$
304 }
305 return null;
306 }
307
308 @Override
309 public String getEditorId() {
310 if (getTraceType() != null) {
311 if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) {
312 return TmfEventsEditor.ID;
313 }
314 if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) {
315 return TmfEventsEditor.ID;
316 }
317 IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType());
318 if (ce == null) {
319 /* This trace type does not define UI attributes */
320 return null;
321 }
322 IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceTypeUIUtils.DEFAULT_EDITOR_ELEM);
323 if (defaultEditorCE.length == 1) {
324 return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR);
325 }
326 }
327 return null;
328 }
329
330 /**
331 * Returns the file resource used to store bookmarks after creating it if
332 * necessary. If the trace resource is a file, it is returned directly. If
333 * the trace resource is a folder, a linked file is returned. The file will
334 * be created if it does not exist.
335 *
336 * @return the bookmarks file
337 * @throws CoreException
338 * if the bookmarks file cannot be created
339 * @since 2.0
340 */
341 @Override
342 public IFile createBookmarksFile() throws CoreException {
343 IFile file = getBookmarksFile();
344 if (fResource instanceof IFolder) {
345 return createBookmarksFile(getProject().getTracesFolder().getResource(), TmfTrace.class.getCanonicalName());
346 }
347 return file;
348 }
349
350 /**
351 * Returns the file resource used to store bookmarks. The file may not
352 * exist.
353 *
354 * @return the bookmarks file
355 * @since 2.0
356 */
357 @Override
358 public IFile getBookmarksFile() {
359 IFile file = null;
360 if (fResource instanceof IFile) {
361 file = (IFile) fResource;
362 } else if (fResource instanceof IFolder) {
363 final IFolder folder = (IFolder) fResource;
364 file = folder.getFile(getName() + '_');
365 }
366 return file;
367 }
368
369 /**
370 * Returns the <code>TmfTraceElement</code> located under the
371 * <code>TmfTracesFolder</code>.
372 *
373 * @return <code>this</code> if this element is under the
374 * <code>TmfTracesFolder</code> else the corresponding
375 * <code>TmfTraceElement</code> if this element is under
376 * <code>TmfExperimentElement</code>.
377 */
378 public TmfTraceElement getElementUnderTraceFolder() {
379
380 // If trace is under an experiment, return original trace from the
381 // traces folder
382 if (getParent() instanceof TmfExperimentElement) {
383 for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) {
384 if (aTrace.getElementPath().equals(getElementPath())) {
385 return aTrace;
386 }
387 }
388 }
389 return this;
390 }
391
392 @Override
393 public String getTypeName() {
394 return Messages.TmfTraceElement_TypeName;
395 }
396
397 // ------------------------------------------------------------------------
398 // IActionFilter
399 // ------------------------------------------------------------------------
400
401 @Override
402 public boolean testAttribute(Object target, String name, String value) {
403 if (name.equals(IS_LINKED)) {
404 boolean isLinked = getResource().isLinked();
405 return Boolean.toString(isLinked).equals(value);
406 }
407 return false;
408 }
409
410 // ------------------------------------------------------------------------
411 // IPropertySource2
412 // ------------------------------------------------------------------------
413
414 @Override
415 public Object getEditableValue() {
416 return null;
417 }
418
419 /**
420 * Get the trace properties of this traceElement if the corresponding trace
421 * is opened in an editor
422 *
423 * @return a map with the names and values of the trace properties
424 * respectively as keys and values
425 */
426 private Map<String, String> getTraceProperties() {
427 for (ITmfTrace openedTrace : TmfTraceManager.getInstance().getOpenedTraces()) {
428 for (ITmfTrace singleTrace : TmfTraceManager.getTraceSet(openedTrace)) {
429 if (getElementUnderTraceFolder().getResource().equals(singleTrace.getResource())) {
430 if (singleTrace instanceof ITmfTraceProperties) {
431 ITmfTraceProperties traceProperties = (ITmfTraceProperties) singleTrace;
432 return traceProperties.getTraceProperties();
433 }
434 }
435 }
436 }
437 return new HashMap<>();
438 }
439
440 @Override
441 public IPropertyDescriptor[] getPropertyDescriptors() {
442 Map<String, String> traceProperties = getTraceProperties();
443 if (!traceProperties.isEmpty()) {
444 IPropertyDescriptor[] propertyDescriptorArray = new IPropertyDescriptor[traceProperties.size() + sfDescriptors.length];
445 int index = 0;
446 for (Map.Entry<String, String> varName : traceProperties.entrySet()) {
447 ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName.getKey(), varName.getKey()); //$NON-NLS-1$
448 descriptor.setCategory(sfTracePropertiesCategory);
449 propertyDescriptorArray[index] = descriptor;
450 index++;
451 }
452 for (int i = 0; i < sfDescriptors.length; i++) {
453 propertyDescriptorArray[index] = sfDescriptors[i];
454 index++;
455 }
456 return propertyDescriptorArray;
457 }
458 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
459 }
460
461 @Override
462 public Object getPropertyValue(Object id) {
463
464 if (sfName.equals(id)) {
465 return getName();
466 }
467
468 if (sfPath.equals(id)) {
469 return getPath().toString();
470 }
471
472 if (sfLocation.equals(id)) {
473 return URIUtil.toUnencodedString(getLocation());
474 }
475
476 if (sfIsLinked.equals(id)) {
477 return Boolean.valueOf(getResource().isLinked()).toString();
478 }
479
480 if (sfSourceLocation.equals(id)) {
481 try {
482 String sourceLocation = getElementUnderTraceFolder().getResource().getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
483 if (sourceLocation != null) {
484 return sourceLocation;
485 }
486 } catch (CoreException e) {
487 }
488 return ""; //$NON-NLS-1$
489 }
490
491 if (sfLastModified.equals(id)) {
492 FileInfo fileInfo = getFileInfo();
493 if (fileInfo == null) {
494 return ""; //$NON-NLS-1$
495 }
496 long date = fileInfo.lastModified;
497 DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM);
498 return format.format(new Date(date));
499 }
500
501 if (sfSize.equals(id)) {
502 FileInfo fileInfo = getFileInfo();
503 if (fileInfo == null) {
504 return ""; //$NON-NLS-1$
505 }
506 if (getResource() instanceof IFolder) {
507 if (fileInfo.count <= FOLDER_MAX_COUNT) {
508 return NLS.bind(Messages.TmfTraceElement_FolderSizeString,
509 NumberFormat.getInstance().format(fileInfo.size), fileInfo.count);
510 }
511 return NLS.bind(Messages.TmfTraceElement_FolderSizeOverflowString,
512 NumberFormat.getInstance().format(fileInfo.size), FOLDER_MAX_COUNT);
513 }
514 return NLS.bind(Messages.TmfTraceElement_FileSizeString, NumberFormat.getInstance().format(fileInfo.size));
515 }
516
517 if (sfTraceType.equals(id)) {
518 if (getTraceType() != null) {
519 TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
520 if (helper != null) {
521 return helper.getCategoryName() + " : " + helper.getName(); //$NON-NLS-1$
522 }
523 }
524 return ""; //$NON-NLS-1$
525 }
526
527 if (sfTimeOffset.equals(id)) {
528 long offset = TimestampTransformFactory.getTimestampTransform(getElementUnderTraceFolder().getResource()).transform(0);
529 if (offset != 0) {
530 return OFFSET_FORMAT.format(offset);
531 }
532 return ""; //$NON-NLS-1$
533 }
534
535 Map<String, String> traceProperties = getTraceProperties();
536 if (id != null && !traceProperties.isEmpty()) {
537 String key = (String) id;
538 key = key.substring(this.getName().length() + 1); // remove name_
539 String value = traceProperties.get(key);
540 return value;
541 }
542
543 return null;
544 }
545
546 private FileInfo getFileInfo() {
547 /* FileInfo is needed for both 'last modified' and 'size' properties.
548 * It is freshly computed for one, and reused for the other, then
549 * cleared so that the information can be refreshed the next time.
550 */
551 FileInfo fileInfo;
552 if (fFileInfo == null) {
553 try {
554 fileInfo = computeFileInfo(new FileInfo(), getResource());
555 } catch (CoreException e) {
556 return null;
557 }
558 fFileInfo = fileInfo;
559 } else {
560 fileInfo = fFileInfo;
561 fFileInfo = null;
562 }
563 return fileInfo;
564 }
565
566 private FileInfo computeFileInfo(FileInfo fileInfo, IResource resource) throws CoreException {
567 if (fileInfo == null || fileInfo.count > FOLDER_MAX_COUNT) {
568 return fileInfo;
569 }
570 if (resource instanceof IFolder) {
571 IFolder folder = (IFolder) resource;
572 for (IResource member : folder.members()) {
573 computeFileInfo(fileInfo, member);
574 }
575 return fileInfo;
576 }
577 IFileInfo info = EFS.getStore(resource.getLocationURI()).fetchInfo();
578 fileInfo.lastModified = Math.max(fileInfo.lastModified, info.getLastModified());
579 fileInfo.size += info.getLength();
580 fileInfo.count++;
581 return fileInfo;
582 }
583
584 @Override
585 public void resetPropertyValue(Object id) {
586 }
587
588 @Override
589 public void setPropertyValue(Object id, Object value) {
590 }
591
592 @Override
593 public boolean isPropertyResettable(Object id) {
594 return false;
595 }
596
597 @Override
598 public boolean isPropertySet(Object id) {
599 return false;
600 }
601
602 /**
603 * Copy this trace in the trace folder. No other parameters are mentioned so
604 * the trace is copied in this element's project trace folder
605 *
606 * @param newName
607 * The new trace name
608 * @return the new Resource object
609 * @since 2.0
610 */
611 public TmfTraceElement copy(String newName) {
612 TmfTraceFolder folder = (TmfTraceFolder) getParent();
613 IResource res = super.copy(newName, false);
614 for (TmfTraceElement trace : folder.getTraces()) {
615 if (trace.getResource().equals(res)) {
616 return trace;
617 }
618 }
619 return null;
620 }
621
622 /**
623 * Close opened editors associated with this trace.
624 *
625 * @since 2.0
626 */
627 @Override
628 public void closeEditors() {
629 super.closeEditors();
630
631 // Close experiments that contain the trace if open
632 if (getParent() instanceof TmfTraceFolder) {
633 TmfExperimentFolder experimentsFolder = getProject().getExperimentsFolder();
634 for (TmfExperimentElement experiment : experimentsFolder.getExperiments()) {
635 for (TmfTraceElement trace : experiment.getTraces()) {
636 if (trace.getElementPath().equals(getElementPath())) {
637 experiment.closeEditors();
638 break;
639 }
640 }
641 }
642 } else if (getParent() instanceof TmfExperimentElement) {
643 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
644 experiment.closeEditors();
645 }
646 }
647
648 /**
649 * Delete the trace resource, remove it from experiments and delete its
650 * supplementary files
651 *
652 * @param progressMonitor
653 * a progress monitor, or null if progress reporting is not
654 * desired
655 *
656 * @throws CoreException
657 * thrown when IResource.delete fails
658 * @since 2.2
659 */
660 public void delete(IProgressMonitor progressMonitor) throws CoreException {
661 // Close editors in UI Thread
662 Display.getDefault().syncExec(new Runnable() {
663 @Override
664 public void run() {
665 closeEditors();
666 }
667 });
668
669 IPath path = fResource.getLocation();
670 if (path != null) {
671 if (getParent() instanceof TmfTraceFolder) {
672 TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
673
674 // Propagate the removal to traces
675 for (TmfExperimentElement experiment : experimentFolder.getExperiments()) {
676 List<TmfTraceElement> toRemove = new LinkedList<>();
677 for (TmfTraceElement trace : experiment.getTraces()) {
678 if (trace.getElementPath().equals(getElementPath())) {
679 toRemove.add(trace);
680 }
681 }
682 for (TmfTraceElement child : toRemove) {
683 experiment.removeTrace(child);
684 }
685 }
686
687 // Delete supplementary files
688 deleteSupplementaryFolder();
689
690 } else if (getParent() instanceof TmfExperimentElement) {
691 TmfExperimentElement experimentElement = (TmfExperimentElement) getParent();
692 experimentElement.removeTrace(this);
693 }
694 }
695
696 // Finally, delete the trace
697 fResource.delete(true, progressMonitor);
698 }
699
700 }
This page took 0.048803 seconds and 5 git commands to generate.