tmf: Introduce a scheduler for event requests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / model / TmfTraceElement.java
CommitLineData
12c155f5 1/*******************************************************************************
beb19106 2 * Copyright (c) 2010, 2013 Ericsson, École Polytechnique de Montréal
ce2388e0 3 *
12c155f5
FC
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
ce2388e0 8 *
12c155f5
FC
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
b544077e 11 * Bernd Hufmann - Added supplementary files handling
a72a6830
PT
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
4962833a
JCK
15 * Jean-Christian Kouame - added trace properties to be shown into
16 * the properties view
12c155f5
FC
17 *******************************************************************************/
18
19package org.eclipse.linuxtools.tmf.ui.project.model;
20
c4c81d91
PT
21import java.io.ByteArrayInputStream;
22import java.io.InputStream;
5a5c2fc7 23import java.util.Arrays;
12c155f5
FC
24import java.util.HashMap;
25import java.util.Map;
26
c4c81d91 27import org.eclipse.core.resources.IFile;
5e4bf87d 28import org.eclipse.core.resources.IFolder;
12c155f5
FC
29import org.eclipse.core.resources.IResource;
30import org.eclipse.core.runtime.CoreException;
31import org.eclipse.core.runtime.IConfigurationElement;
32import org.eclipse.core.runtime.Platform;
8fd82db5 33import org.eclipse.linuxtools.internal.tmf.ui.Activator;
d34665f9
FC
34import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent;
35import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace;
36import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition;
37import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlEvent;
38import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace;
39import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition;
e12ecd30 40import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
ce2388e0 41import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
6c13869b 42import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
4962833a 43import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
c4c81d91 44import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
4962833a 45import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
4bf17f4a 46import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
080600d9 47import org.eclipse.linuxtools.tmf.ui.properties.ReadOnlyTextPropertyDescriptor;
12c155f5 48import org.eclipse.ui.IActionFilter;
a72a6830
PT
49import org.eclipse.ui.IEditorReference;
50import org.eclipse.ui.IWorkbench;
51import org.eclipse.ui.IWorkbenchPage;
52import org.eclipse.ui.IWorkbenchWindow;
53import org.eclipse.ui.PartInitException;
54import org.eclipse.ui.PlatformUI;
55import org.eclipse.ui.part.FileEditorInput;
12c155f5
FC
56import org.eclipse.ui.views.properties.IPropertyDescriptor;
57import org.eclipse.ui.views.properties.IPropertySource2;
12c155f5
FC
58
59/**
d04ec5a7
MK
60 * Implementation of trace model element representing a trace. It provides
61 * methods to instantiate <code>ITmfTrace</code> and <code>ITmfEvent</code> as
62 * well as editor ID from the trace type extension definition.
abbdd66a 63 *
b544077e
BH
64 * @version 1.0
65 * @author Francois Chouinard
12c155f5 66 */
99504bb8 67public class TmfTraceElement extends TmfWithFolderElement implements IActionFilter, IPropertySource2 {
12c155f5
FC
68
69 // ------------------------------------------------------------------------
70 // Constants
71 // ------------------------------------------------------------------------
72
12c155f5 73 // Other attributes
b544077e
BH
74 /**
75 * Bundle attribute name
76 */
12c155f5 77 public static final String BUNDLE = "bundle"; //$NON-NLS-1$
b544077e
BH
78 /**
79 * IsLinked attribute name.
80 */
12c155f5
FC
81 public static final String IS_LINKED = "isLinked"; //$NON-NLS-1$
82
83 // Property View stuff
4962833a
JCK
84 private static final String sfResourcePropertiesCategory = Messages.TmfTraceElement_ResourceProperties;
85 private static final String sfName = Messages.TmfTraceElement_Name;
86 private static final String sfPath = Messages.TmfTraceElement_Path;
87 private static final String sfLocation = Messages.TmfTraceElement_Location;
88 private static final String sfEventType = Messages.TmfTraceElement_EventType;
89 private static final String sfIsLinked = Messages.TmfTraceElement_IsLinked;
90 private static final String sfTracePropertiesCategory = Messages.TmfTraceElement_TraceProperties;
12c155f5 91
253d5be1
BH
92 private static final ReadOnlyTextPropertyDescriptor sfNameDescriptor = new ReadOnlyTextPropertyDescriptor(sfName, sfName);
93 private static final ReadOnlyTextPropertyDescriptor sfPathDescriptor = new ReadOnlyTextPropertyDescriptor(sfPath, sfPath);
94 private static final ReadOnlyTextPropertyDescriptor sfLocationDescriptor = new ReadOnlyTextPropertyDescriptor(sfLocation, sfLocation);
95 private static final ReadOnlyTextPropertyDescriptor sfTypeDescriptor = new ReadOnlyTextPropertyDescriptor(sfEventType, sfEventType);
96 private static final ReadOnlyTextPropertyDescriptor sfIsLinkedDescriptor = new ReadOnlyTextPropertyDescriptor(sfIsLinked, sfIsLinked);
12c155f5
FC
97
98 private static final IPropertyDescriptor[] sfDescriptors = { sfNameDescriptor, sfPathDescriptor, sfLocationDescriptor,
99 sfTypeDescriptor, sfIsLinkedDescriptor };
100
101 static {
4962833a
JCK
102 sfNameDescriptor.setCategory(sfResourcePropertiesCategory);
103 sfPathDescriptor.setCategory(sfResourcePropertiesCategory);
104 sfLocationDescriptor.setCategory(sfResourcePropertiesCategory);
105 sfTypeDescriptor.setCategory(sfResourcePropertiesCategory);
106 sfIsLinkedDescriptor.setCategory(sfResourcePropertiesCategory);
12c155f5 107 }
6256d8ad 108
c4c81d91
PT
109 private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
110
12c155f5
FC
111 // ------------------------------------------------------------------------
112 // Attributes
113 // ------------------------------------------------------------------------
114
115 // This trace type ID as defined in plugin.xml
116 private String fTraceTypeId = null;
117
118 // ------------------------------------------------------------------------
119 // Static initialization
120 // ------------------------------------------------------------------------
121
d04ec5a7
MK
122 // The mapping of available trace type IDs to their corresponding
123 // configuration element
12c155f5
FC
124 private static final Map<String, IConfigurationElement> sfTraceTypeAttributes = new HashMap<String, IConfigurationElement>();
125 private static final Map<String, IConfigurationElement> sfTraceCategories = new HashMap<String, IConfigurationElement>();
126
b544077e 127 /**
d04ec5a7
MK
128 * Initialize statically at startup by getting extensions from the platform
129 * extension registry.
b544077e 130 */
12c155f5 131 public static void init() {
4bf17f4a 132 IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
12c155f5 133 for (IConfigurationElement ce : config) {
4bf17f4a 134 String elementName = ce.getName();
135 if (elementName.equals(TmfTraceType.TYPE_ELEM)) {
136 String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
12c155f5 137 sfTraceTypeAttributes.put(traceTypeId, ce);
4bf17f4a 138 } else if (elementName.equals(TmfTraceType.CATEGORY_ELEM)) {
139 String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
12c155f5
FC
140 sfTraceCategories.put(categoryId, ce);
141 }
142 }
143 }
144
145 // ------------------------------------------------------------------------
146 // Constructors
147 // ------------------------------------------------------------------------
b544077e 148 /**
d04ec5a7
MK
149 * Constructor. Creates trace model element under the trace folder.
150 *
151 * @param name
152 * The name of trace
153 * @param trace
154 * The trace resource.
155 * @param parent
156 * The parent element (trace folder)
b544077e 157 */
12c155f5
FC
158 public TmfTraceElement(String name, IResource trace, TmfTraceFolder parent) {
159 this(name, trace, (TmfProjectModelElement) parent);
160 }
d04ec5a7 161
b544077e 162 /**
d04ec5a7
MK
163 * Constructor. Creates trace model element under the experiment folder.
164 *
165 * @param name
166 * The name of trace
167 * @param trace
168 * The trace resource.
169 * @param parent
170 * The parent element (experiment folder)
b544077e 171 */
12c155f5
FC
172 public TmfTraceElement(String name, IResource trace, TmfExperimentElement parent) {
173 this(name, trace, (TmfProjectModelElement) parent);
174 }
175
176 private TmfTraceElement(String name, IResource trace, TmfProjectModelElement parent) {
177 super(name, trace, parent);
178 parent.addChild(this);
179 refreshTraceType();
180 }
181
182 // ------------------------------------------------------------------------
183 // Operations
184 // ------------------------------------------------------------------------
b544077e
BH
185 /**
186 * Returns the trace type ID.
d04ec5a7 187 *
b544077e
BH
188 * @return trace type ID.
189 */
12c155f5
FC
190 public String getTraceType() {
191 return fTraceTypeId;
192 }
193
b544077e 194 /**
d04ec5a7
MK
195 * Refreshes the trace type filed by reading the trace type persistent
196 * property of the resource referenece.
b544077e 197 */
12c155f5
FC
198 public void refreshTraceType() {
199 try {
e12ecd30 200 fTraceTypeId = getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);
12c155f5 201 } catch (CoreException e) {
8fd82db5 202 Activator.getDefault().logError("Error refreshing trace type pesistent property for trace " + getName(), e); //$NON-NLS-1$
12c155f5
FC
203 }
204 }
205
b544077e 206 /**
d04ec5a7
MK
207 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
208 * the corresponding extension.
abbdd66a 209 *
b544077e
BH
210 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
211 */
6256d8ad 212 public ITmfTrace instantiateTrace() {
12c155f5 213 try {
e12ecd30
BH
214
215 // make sure that supplementary folder exists
216 refreshSupplementaryFolder();
217
12c155f5 218 if (fTraceTypeId != null) {
4bf17f4a 219 if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
220 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
221 if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
222 return new CustomTxtTrace(def);
223 }
224 }
225 }
226 if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
227 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
228 if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
229 return new CustomXmlTrace(def);
230 }
231 }
232 }
12c155f5 233 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
d04ec5a7
MK
234 if (ce == null) {
235 return null;
236 }
6256d8ad 237 ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
12c155f5
FC
238 return trace;
239 }
240 } catch (CoreException e) {
8fd82db5 241 Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e); //$NON-NLS-1$
12c155f5
FC
242 }
243 return null;
244 }
245
b544077e 246 /**
d04ec5a7
MK
247 * Instantiate a <code>ITmfEvent</code> object based on the trace type and
248 * the corresponding extension.
abbdd66a 249 *
b544077e
BH
250 * @return the <code>ITmfEvent</code> or <code>null</code> for an error
251 */
ce2388e0 252 public ITmfEvent instantiateEvent() {
12c155f5
FC
253 try {
254 if (fTraceTypeId != null) {
4bf17f4a 255 if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
256 for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
257 if (fTraceTypeId.equals(CustomTxtTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
258 return new CustomTxtEvent(def);
259 }
260 }
261 }
262 if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
263 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
264 if (fTraceTypeId.equals(CustomXmlTrace.class.getCanonicalName() + ":" + def.definitionName)) { //$NON-NLS-1$
265 return new CustomXmlEvent(def);
266 }
267 }
268 }
12c155f5 269 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
d04ec5a7
MK
270 if (ce == null) {
271 return null;
272 }
ce2388e0 273 ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
12c155f5
FC
274 return event;
275 }
276 } catch (CoreException e) {
8fd82db5 277 Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$
12c155f5
FC
278 }
279 return null;
280 }
281
b544077e
BH
282 /**
283 * Returns the optional editor ID from the trace type extension.
d04ec5a7 284 *
b544077e
BH
285 * @return the editor ID or <code>null</code> if not defined.
286 */
12c155f5
FC
287 public String getEditorId() {
288 if (fTraceTypeId != null) {
4bf17f4a 289 if (fTraceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName())) {
290 return TmfEventsEditor.ID;
291 }
292 if (fTraceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName())) {
293 return TmfEventsEditor.ID;
294 }
12c155f5 295 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
4bf17f4a 296 IConfigurationElement[] defaultEditorCE = ce.getChildren(TmfTraceType.DEFAULT_EDITOR_ELEM);
12c155f5 297 if (defaultEditorCE.length == 1) {
4bf17f4a 298 return defaultEditorCE[0].getAttribute(TmfTraceType.ID_ATTR);
12c155f5
FC
299 }
300 }
301 return null;
302 }
e12ecd30 303
c4c81d91 304 /**
d04ec5a7
MK
305 * Returns the file resource used to store bookmarks after creating it if
306 * necessary. If the trace resource is a file, it is returned directly. If
307 * the trace resource is a folder, a linked file is returned. The file will
308 * be created if it does not exist.
309 *
c4c81d91 310 * @return the bookmarks file
d04ec5a7
MK
311 * @throws CoreException
312 * if the bookmarks file cannot be created
c4c81d91
PT
313 * @since 2.0
314 */
81fe3479
PT
315 public IFile createBookmarksFile() throws CoreException {
316 IFile file = getBookmarksFile();
317 if (fResource instanceof IFolder) {
318 if (!file.exists()) {
319 final IFile bookmarksFile = getProject().getTracesFolder().getResource().getFile(BOOKMARKS_HIDDEN_FILE);
320 if (!bookmarksFile.exists()) {
321 final InputStream source = new ByteArrayInputStream(new byte[0]);
322 bookmarksFile.create(source, true, null);
323 }
324 bookmarksFile.setHidden(true);
325 file.createLink(bookmarksFile.getLocation(), IResource.REPLACE, null);
326 file.setHidden(true);
327 file.setPersistentProperty(TmfCommonConstants.TRACETYPE, TmfTrace.class.getCanonicalName());
328 }
329 }
330 return file;
331 }
332
333 /**
d04ec5a7
MK
334 * Returns the file resource used to store bookmarks. The file may not
335 * exist.
336 *
81fe3479
PT
337 * @return the bookmarks file
338 * @since 2.0
339 */
340 public IFile getBookmarksFile() {
c4c81d91
PT
341 IFile file = null;
342 if (fResource instanceof IFile) {
343 file = (IFile) fResource;
344 } else if (fResource instanceof IFolder) {
c4c81d91
PT
345 final IFolder folder = (IFolder) fResource;
346 file = folder.getFile(getName() + '_');
c4c81d91
PT
347 }
348 return file;
349 }
350
e12ecd30 351 /**
d04ec5a7
MK
352 * Returns the <code>TmfTraceElement</code> located under the
353 * <code>TmfTracesFolder</code>.
6256d8ad 354 *
d04ec5a7
MK
355 * @return <code>this</code> if this element is under the
356 * <code>TmfTracesFolder</code> else the corresponding
357 * <code>TmfTraceElement</code> if this element is under
e12ecd30
BH
358 * <code>TmfExperimentElement</code>.
359 */
5e4bf87d 360 public TmfTraceElement getElementUnderTraceFolder() {
e12ecd30 361
d04ec5a7
MK
362 // If trace is under an experiment, return original trace from the
363 // traces folder
5e4bf87d
BH
364 if (getParent() instanceof TmfExperimentElement) {
365 for (TmfTraceElement aTrace : getProject().getTracesFolder().getTraces()) {
366 if (aTrace.getName().equals(getName())) {
367 return aTrace;
368 }
369 }
370 }
371 return this;
372 }
6256d8ad 373
12c155f5
FC
374 // ------------------------------------------------------------------------
375 // IActionFilter
376 // ------------------------------------------------------------------------
377
378 @Override
379 public boolean testAttribute(Object target, String name, String value) {
380 if (name.equals(IS_LINKED)) {
381 boolean isLinked = getResource().isLinked();
382 return Boolean.toString(isLinked).equals(value);
383 }
384 return false;
385 }
386
387 // ------------------------------------------------------------------------
388 // TmfTraceElement
389 // ------------------------------------------------------------------------
11252342 390
12c155f5
FC
391 @Override
392 public TmfProjectElement getProject() {
393 if (getParent() instanceof TmfTraceFolder) {
394 TmfTraceFolder folder = (TmfTraceFolder) getParent();
395 TmfProjectElement project = (TmfProjectElement) folder.getParent();
396 return project;
397 }
398 if (getParent() instanceof TmfExperimentElement) {
399 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
400 TmfExperimentFolder folder = (TmfExperimentFolder) experiment.getParent();
401 TmfProjectElement project = (TmfProjectElement) folder.getParent();
402 return project;
403 }
404 return null;
405 }
406
407 // ------------------------------------------------------------------------
408 // IPropertySource2
409 // ------------------------------------------------------------------------
410
411 @Override
412 public Object getEditableValue() {
413 return null;
414 }
415
4962833a
JCK
416 /**
417 * Get the trace properties of this traceElement if the corresponding trace
418 * is opened in an editor
419 *
420 * @return a map with the names and values of the trace properties
421 * respectively as keys and values
422 */
423 private Map<String, String> getTraceProperties() {
424 for (ITmfTrace trace : TmfTraceManager.getInstance().getOpenedTraces()) {
425 if (trace.getResource().equals(this.getResource())) {
426 if (trace instanceof ITmfTraceProperties) {
427 ITmfTraceProperties traceProperties = (ITmfTraceProperties) trace;
428 return traceProperties.getTraceProperties();
429 }
430 }
431 }
432 return new HashMap<String, String>();
433 }
434
12c155f5
FC
435 @Override
436 public IPropertyDescriptor[] getPropertyDescriptors() {
4962833a
JCK
437 Map<String, String> traceProperties = getTraceProperties();
438 if (!traceProperties.isEmpty()) {
439 IPropertyDescriptor[] propertyDescriptorArray = new IPropertyDescriptor[traceProperties.size() + sfDescriptors.length];
440 int index = 0;
441 for (Map.Entry<String, String> varName : traceProperties.entrySet()) {
442 ReadOnlyTextPropertyDescriptor descriptor = new ReadOnlyTextPropertyDescriptor(this.getName() + "_" + varName.getKey(), varName.getKey()); //$NON-NLS-1$
443 descriptor.setCategory(sfTracePropertiesCategory);
444 propertyDescriptorArray[index] = descriptor;
445 index++;
446 }
447 for (int i = 0; i < sfDescriptors.length; i++) {
448 propertyDescriptorArray[index] = sfDescriptors[i];
449 index++;
450 }
451 return propertyDescriptorArray;
452 }
77fdc5df 453 return Arrays.copyOf(sfDescriptors, sfDescriptors.length);
12c155f5
FC
454 }
455
456 @Override
457 public Object getPropertyValue(Object id) {
458
ce2388e0 459 if (sfName.equals(id)) {
12c155f5 460 return getName();
ce2388e0 461 }
12c155f5 462
ce2388e0 463 if (sfPath.equals(id)) {
12c155f5 464 return getPath().toString();
ce2388e0 465 }
12c155f5 466
ce2388e0 467 if (sfLocation.equals(id)) {
12c155f5 468 return getLocation().toString();
ce2388e0 469 }
12c155f5 470
ce2388e0 471 if (sfIsLinked.equals(id)) {
12c155f5 472 return Boolean.valueOf(getResource().isLinked()).toString();
ce2388e0 473 }
12c155f5
FC
474
475 if (sfEventType.equals(id)) {
476 if (fTraceTypeId != null) {
477 IConfigurationElement ce = sfTraceTypeAttributes.get(fTraceTypeId);
4bf17f4a 478 return (ce != null) ? (getCategory(ce) + " : " + ce.getAttribute(TmfTraceType.NAME_ATTR)) : ""; //$NON-NLS-1$ //$NON-NLS-2$
12c155f5
FC
479 }
480 }
481
4962833a
JCK
482 Map<String, String> traceProperties = getTraceProperties();
483 if (id != null && !traceProperties.isEmpty()) {
484 String key = (String) id;
485 key = key.replaceFirst(this.getName() + "_", ""); //$NON-NLS-1$ //$NON-NLS-2$
486 String value = traceProperties.get(key);
487 return value;
488 }
489
12c155f5
FC
490 return null;
491 }
492
abbdd66a 493 private static String getCategory(IConfigurationElement ce) {
4bf17f4a 494 String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
12c155f5
FC
495 if (categoryId != null) {
496 IConfigurationElement category = sfTraceCategories.get(categoryId);
4bf17f4a 497 if (category != null) {
498 return category.getAttribute(TmfTraceType.NAME_ATTR);
12c155f5
FC
499 }
500 }
501 return "[no category]"; //$NON-NLS-1$
502 }
503
504 @Override
505 public void resetPropertyValue(Object id) {
506 }
507
508 @Override
509 public void setPropertyValue(Object id, Object value) {
510 }
511
512 @Override
513 public boolean isPropertyResettable(Object id) {
514 return false;
515 }
516
517 @Override
518 public boolean isPropertySet(Object id) {
519 return false;
520 }
521
beb19106
GB
522 /**
523 * Copy this trace in the trace folder. No other parameters are mentioned so
524 * the trace is copied in this element's project trace folder
525 *
526 * @param string
527 * The new trace name
528 * @return the new Resource object
529 * @since 2.0
530 */
531 public TmfTraceElement copy(String string) {
532 TmfTraceFolder folder = this.getProject().getTracesFolder();
533 IResource res = super.copy(string, false);
534 return new TmfTraceElement(string, res, folder);
535 }
536
a72a6830
PT
537 /**
538 * Close opened editors associated with this trace.
4962833a 539 *
a72a6830
PT
540 * @since 2.0
541 */
542 public void closeEditors() {
543 // Close the trace if open
544 IFile file = getBookmarksFile();
545 FileEditorInput input = new FileEditorInput(file);
546 IWorkbench wb = PlatformUI.getWorkbench();
547 for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
548 for (IWorkbenchPage wbPage : wbWindow.getPages()) {
549 for (IEditorReference editorReference : wbPage.getEditorReferences()) {
550 try {
551 if (editorReference.getEditorInput().equals(input)) {
552 wbPage.closeEditor(editorReference.getEditor(false), false);
553 }
554 } catch (PartInitException e) {
555 Activator.getDefault().logError("Error closing editor for trace " + getName(), e); //$NON-NLS-1$
556 }
557 }
558 }
559 }
560
561 // Close experiments that contain the trace if open
562 if (getParent() instanceof TmfTraceFolder) {
563 TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder();
564 for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) {
565 for (ITmfProjectModelElement child : experiment.getChildren()) {
566 if (child.getName().equals(getName())) {
567 ((TmfExperimentElement) experiment).closeEditors();
568 break;
569 }
570 }
571 }
572 } else if (getParent() instanceof TmfExperimentElement) {
573 TmfExperimentElement experiment = (TmfExperimentElement) getParent();
574 experiment.closeEditors();
575 }
576 }
12c155f5 577}
This page took 0.092284 seconds and 5 git commands to generate.