1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Matthew Khouzam - Added import functionalities
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Collections
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
22 import java
.util
.LinkedList
;
23 import java
.util
.List
;
27 import org
.eclipse
.core
.resources
.IResource
;
28 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
29 import org
.eclipse
.core
.runtime
.CoreException
;
30 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
31 import org
.eclipse
.core
.runtime
.IPath
;
32 import org
.eclipse
.core
.runtime
.IStatus
;
33 import org
.eclipse
.core
.runtime
.Platform
;
34 import org
.eclipse
.core
.runtime
.Status
;
35 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
36 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTrace
;
37 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomTxtTraceDefinition
;
38 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTrace
;
39 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
.CustomXmlTraceDefinition
;
40 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.model
.TmfTraceImportException
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.TmfCommonConstants
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
43 import org
.eclipse
.swt
.SWT
;
44 import org
.eclipse
.swt
.events
.SelectionEvent
;
45 import org
.eclipse
.swt
.events
.SelectionListener
;
46 import org
.eclipse
.swt
.layout
.RowLayout
;
47 import org
.eclipse
.swt
.widgets
.Button
;
48 import org
.eclipse
.swt
.widgets
.Display
;
49 import org
.eclipse
.swt
.widgets
.Shell
;
50 import org
.eclipse
.ui
.dialogs
.FileSystemElement
;
53 * Utility class for accessing TMF trace type extensions from the platform's
54 * extensions registry.
57 * @author Patrick Tasse
58 * @author Matthew Khouzam
60 public final class TmfTraceType
{
62 private static final String DEFAULT_TRACE_ICON_PATH
= "icons" + File
.separator
+ "elcl16" + File
.separator
+ "trace.gif"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64 private static final char SEPARATOR
= ':';
69 public static final String TMF_TRACE_TYPE_ID
= "org.eclipse.linuxtools.tmf.ui.tracetype"; //$NON-NLS-1$
72 * Extension point element 'Category'
74 public static final String CATEGORY_ELEM
= "category"; //$NON-NLS-1$
76 * Extension point element 'Type'
78 public static final String TYPE_ELEM
= "type"; //$NON-NLS-1$
80 * Extension point element 'Default editor'
82 public static final String DEFAULT_EDITOR_ELEM
= "defaultEditor"; //$NON-NLS-1$
84 * Extension point element 'Events table type'
86 public static final String EVENTS_TABLE_TYPE_ELEM
= "eventsTableType"; //$NON-NLS-1$
88 * Extension point element 'Statistics viewer type'
92 public static final String STATISTICS_VIEWER_ELEM
= "statisticsViewerType"; //$NON-NLS-1$
95 * Extension point attribute 'ID'
97 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
99 * Extension point attribute 'name'
101 public static final String NAME_ATTR
= "name"; //$NON-NLS-1$
103 * Extension point attribute 'category'
105 public static final String CATEGORY_ATTR
= "category"; //$NON-NLS-1$
107 * Extension point attribute 'trace_type'
109 public static final String TRACE_TYPE_ATTR
= "trace_type"; //$NON-NLS-1$
111 * Extension point attribute 'event_type'
113 public static final String EVENT_TYPE_ATTR
= "event_type"; //$NON-NLS-1$
115 * Extension point attribute 'icon'
117 public static final String ICON_ATTR
= "icon"; //$NON-NLS-1$
119 * Extension point attribute 'class'
121 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
124 * Custom text label used internally and therefore should not be
129 public static final String CUSTOM_TXT_CATEGORY
= "Custom Text"; //$NON-NLS-1$
131 * Custom XML label used internally and therefore should not be externalized
135 public static final String CUSTOM_XML_CATEGORY
= "Custom XML"; //$NON-NLS-1$
137 // The mapping of available trace type IDs to their corresponding
138 // configuration element
139 private final Map
<String
, IConfigurationElement
> fTraceTypeAttributes
= new HashMap
<String
, IConfigurationElement
>();
140 private final Map
<String
, IConfigurationElement
> fTraceCategories
= new HashMap
<String
, IConfigurationElement
>();
141 private final Map
<String
, TraceTypeHelper
> fTraceTypes
= new LinkedHashMap
<String
, TraceTypeHelper
>();
143 private static TmfTraceType fInstance
= null;
146 * Retrieves the category name from the platform extension registry based on
151 * @return the category name or empty string if not found
153 public static String
getCategoryName(String categoryId
) {
154 IConfigurationElement
[] elements
= Platform
.getExtensionRegistry()
155 .getConfigurationElementsFor(TMF_TRACE_TYPE_ID
);
156 for (IConfigurationElement element
: elements
) {
157 if (element
.getName().equals(CATEGORY_ELEM
) && categoryId
.equals(element
.getAttribute(ID_ATTR
))) {
158 return element
.getAttribute(NAME_ATTR
);
161 return ""; //$NON-NLS-1$
165 * Retrieves and instantiates an element's object based on his plug-in
166 * definition for a specific trace type.
168 * The element's object is instantiated using its 0-argument constructor.
171 * The resource where to find the information about the trace
174 * The name of the element to find under the trace type
176 * @return a new Object based on his definition in plugin.xml, or null if no
177 * definition was found
180 public static Object
getTraceTypeElement(IResource resource
, String element
) {
182 if (resource
!= null) {
183 String traceType
= resource
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
185 * Search in the configuration if there is any viewer specified
186 * for this kind of trace type.
188 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
189 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(traceType
)) {
190 IConfigurationElement
[] viewerCE
= ce
.getChildren(element
);
191 if (viewerCE
.length
!= 1) {
194 return viewerCE
[0].createExecutableExtension(TmfTraceType
.CLASS_ATTR
);
198 } catch (CoreException e
) {
199 Activator
.getDefault().logError("Error creating the element from the resource", e
); //$NON-NLS-1$
205 * Retrieves all configuration elements from the platform extension registry
206 * for the trace type extension.
208 * @return an array of trace type configuration elements
210 public static IConfigurationElement
[] getTypeElements() {
211 IConfigurationElement
[] elements
= Platform
.getExtensionRegistry()
212 .getConfigurationElementsFor(TMF_TRACE_TYPE_ID
);
213 List
<IConfigurationElement
> typeElements
= new LinkedList
<IConfigurationElement
>();
214 for (IConfigurationElement element
: elements
) {
215 if (element
.getName().equals(TYPE_ELEM
)) {
216 typeElements
.add(element
);
219 return typeElements
.toArray(new IConfigurationElement
[typeElements
.size()]);
222 private TmfTraceType() {
227 * The import utils instance
229 * @return the import utils instance
232 public static TmfTraceType
getInstance() {
233 if (fInstance
== null) {
234 fInstance
= new TmfTraceType();
239 // ------------------------------------------------------------------
241 // ------------------------------------------------------------------
244 * Returns a list of "category:tracetype , ..."
246 * @return returns a list of "category:tracetype , ..."
249 public String
[] getAvailableTraceTypes() {
251 // Generate the list of Category:TraceType to populate the ComboBox
252 List
<String
> traceTypes
= new ArrayList
<String
>();
254 // re-populate custom trace types
255 getCustomTraceTypes();
256 for (String key
: this.fTraceTypes
.keySet()) {
257 TraceTypeHelper tt
= this.fTraceTypes
.get(key
);
258 traceTypes
.add(tt
.getCategoryName() + SEPARATOR
+ tt
.getName());
262 return traceTypes
.toArray(new String
[traceTypes
.size()]);
266 * Gets the custom trace types (custom text and friends)
269 * the type to get (Text, xml or other...)
270 * @return the list of custom trace types
273 public static List
<String
> getCustomTraceTypes(String type
) {
274 List
<String
> traceTypes
= new ArrayList
<String
>();
275 if (type
.equals(CUSTOM_TXT_CATEGORY
)) {
276 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
277 String traceTypeName
= def
.definitionName
;
278 traceTypes
.add(traceTypeName
);
281 if (type
.equals(CUSTOM_XML_CATEGORY
)) {
282 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
283 String traceTypeName
= def
.definitionName
;
284 traceTypes
.add(traceTypeName
);
291 * Gets all the custom trace types
293 * @return the list of custom trace types
296 public List
<String
> getCustomTraceTypes() {
297 List
<String
> traceTypes
= new ArrayList
<String
>();
298 // remove the customTraceTypes
299 final String
[] keySet
= fTraceTypes
.keySet().toArray(new String
[0]);
300 for (String key
: keySet
) {
301 TraceTypeHelper helper
= fTraceTypes
.get(key
);
302 if (helper
.getCategoryName().equals(CUSTOM_TXT_CATEGORY
) || helper
.getCategoryName().equals(CUSTOM_XML_CATEGORY
)) {
303 helper
.getTrace().dispose();
304 fTraceTypes
.remove(key
);
308 // add the custom trace types
309 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
310 String traceTypeId
= CustomTxtTrace
.class.getCanonicalName() + SEPARATOR
+ def
.definitionName
;
311 TraceTypeHelper tt
= new TraceTypeHelper(traceTypeId
, CUSTOM_TXT_CATEGORY
, def
.definitionName
, new CustomTxtTrace(def
));
312 fTraceTypes
.put(traceTypeId
, tt
);
313 traceTypes
.add(traceTypeId
);
315 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
316 String traceTypeId
= CustomXmlTrace
.class.getCanonicalName() + SEPARATOR
+ def
.definitionName
;
317 TraceTypeHelper tt
= new TraceTypeHelper(traceTypeId
, CUSTOM_XML_CATEGORY
, def
.definitionName
, new CustomXmlTrace(def
));
318 fTraceTypes
.put(traceTypeId
, tt
);
319 traceTypes
.add(traceTypeId
);
325 * Gets a trace type for a given canonical id
328 * the ID of the trace
329 * @return the return type
332 public TraceTypeHelper
getTraceType(String id
) {
334 return fTraceTypes
.get(id
);
337 private void populateCategoriesAndTraceTypes() {
338 if (fTraceTypes
.isEmpty()) {
339 // Populate the Categories and Trace Types
340 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
341 for (IConfigurationElement ce
: config
) {
342 String elementName
= ce
.getName();
343 if (elementName
.equals(TmfTraceType
.TYPE_ELEM
)) {
344 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
345 fTraceTypeAttributes
.put(traceTypeId
, ce
);
346 } else if (elementName
.equals(TmfTraceType
.CATEGORY_ELEM
)) {
347 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
348 fTraceCategories
.put(categoryId
, ce
);
351 // create the trace types
352 for (String typeId
: fTraceTypeAttributes
.keySet()) {
353 IConfigurationElement ce
= fTraceTypeAttributes
.get(typeId
);
354 final String category
= getCategory(ce
);
355 final String attribute
= ce
.getAttribute(TmfTraceType
.NAME_ATTR
);
356 ITmfTrace trace
= null;
358 trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
359 } catch (CoreException e
) {
361 TraceTypeHelper tt
= new TraceTypeHelper(typeId
, category
, attribute
, trace
);
362 fTraceTypes
.put(typeId
, tt
);
367 private String
getCategory(IConfigurationElement ce
) {
368 final String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
369 if (categoryId
!= null) {
370 IConfigurationElement category
= fTraceCategories
.get(categoryId
);
371 if (category
!= null && !category
.getName().equals("")) { //$NON-NLS-1$
372 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
375 return "[no category]"; //$NON-NLS-1$
379 * Returns the list of trace categories
381 * @return the list of trace categories
384 public List
<String
> getTraceCategories() {
385 List
<String
> categoryNames
= new ArrayList
<String
>();
386 for (String key
: fTraceTypes
.keySet()) {
387 final String categoryName
= fTraceTypes
.get(key
).getCategoryName();
388 if (!categoryNames
.contains(categoryName
)) {
389 categoryNames
.add(categoryName
);
392 return categoryNames
;
396 * Get the trace type helper classes from category name
398 * @param categoryName
399 * the categoryName to lookup
400 * @return a list of trace type helper classes {@link TraceTypeHelper}
404 public List
<TraceTypeHelper
> getTraceTypes(String categoryName
) {
406 List
<TraceTypeHelper
> traceNames
= new ArrayList
<TraceTypeHelper
>();
407 for (String key
: fTraceTypes
.keySet()) {
408 final String storedCategoryName
= fTraceTypes
.get(key
).getCategoryName();
409 if (storedCategoryName
.equals(categoryName
)) {
410 traceNames
.add(fTraceTypes
.get(key
));
416 private void init() {
417 populateCategoriesAndTraceTypes();
418 getCustomTraceTypes();
422 private static List
<File
> isolateTraces(List
<FileSystemElement
> selectedResources
) {
424 List
<File
> traces
= new ArrayList
<File
>();
427 Iterator
<FileSystemElement
> resources
= selectedResources
.iterator();
429 // Get the sorted list of unique entries
430 Map
<String
, File
> fileSystemObjects
= new HashMap
<String
, File
>();
431 while (resources
.hasNext()) {
432 File resource
= (File
) resources
.next().getFileSystemObject();
433 String key
= resource
.getAbsolutePath();
434 fileSystemObjects
.put(key
, resource
);
436 List
<String
> files
= new ArrayList
<String
>(fileSystemObjects
.keySet());
437 Collections
.sort(files
);
439 // After sorting, traces correspond to the unique prefixes
440 String prefix
= null;
441 for (int i
= 0; i
< files
.size(); i
++) {
442 File file
= fileSystemObjects
.get(files
.get(i
));
443 String name
= file
.getAbsolutePath();
444 if (prefix
== null || !name
.startsWith(prefix
)) {
445 prefix
= name
; // new prefix
454 * Validate a trace type
456 * @param traceTypeName
457 * the trace category (canonical name)
459 * the file name (and path)
460 * @return true if the trace is of a valid type
463 public boolean validate(String traceTypeName
, String fileName
) {
464 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
465 if (!fTraceTypes
.get(traceTypeName
).validate(fileName
)) {
475 * @param traceToValidate
476 * the trace category (canonical name)
477 * @return true if the trace is of a valid type
480 public boolean validate(TraceValidationHelper traceToValidate
) {
481 return validate(traceToValidate
.getTraceType(), traceToValidate
.getTraceToScan());
485 * validate list of traces with a tracetype
487 * @param traceTypeName
488 * the trace category (canonical name)
489 * @param selectedResources
490 * List of traces to validate
491 * @return true if all the traces are valid
494 public boolean validateTrace(String traceTypeName
, List
<FileSystemElement
> selectedResources
) {
495 List
<File
> traces
= isolateTraces(selectedResources
);
496 return validateTraceFiles(traceTypeName
, traces
);
500 * Validate a list of files with a tracetype
502 * @param traceTypeName
503 * the trace category (canonical name)
505 * the list of files to check if they are trace
506 * @return true if all the traces are valid
509 public boolean validateTraceFiles(String traceTypeName
, List
<File
> traces
) {
510 if (traceTypeName
!= null && !"".equals(traceTypeName
) && //$NON-NLS-1$
511 !traceTypeName
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
) && !traceTypeName
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
)) {
512 for (File trace
: traces
) {
513 if (!validate(traceTypeName
, trace
.getAbsolutePath())) {
522 * Get a configuration element for a given name
526 * @return the configuration element, can be null
529 public IConfigurationElement
getTraceAttributes(String traceType
) {
530 return fTraceTypeAttributes
.get(traceType
);
534 * Find the id of a trace type by its parameters
537 * like "ctf" or "custom text"
540 * @return an id like "org.eclipse.linuxtools.blabla...
543 public String
getTraceTypeId(String category
, String traceType
) {
544 for (String key
: fTraceTypes
.keySet()) {
545 if (fTraceTypes
.get(key
).getCategoryName().equals(category
.trim()) && fTraceTypes
.get(key
).getName().equals(traceType
.trim())) {
553 * Is the trace a custom (user-defined) trace type. These are the traces
554 * like : text and xml defined by the custom trace wizard.
557 * the trace type in human form (category:name)
558 * @return true if the trace is a custom type
561 public static boolean isCustomTrace(String traceType
) {
562 final boolean startsWithTxt
= traceType
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
);
563 final boolean startsWithXML
= traceType
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
);
564 return (startsWithTxt
|| startsWithXML
);
568 * Is the trace type id a custom (user-defined) trace type. These are the
569 * traces like : text and xml defined by the custom trace wizard.
573 * @return true if the trace is a custom type
575 private static boolean isCustomTraceId(String traceTypeId
) {
576 TraceTypeHelper traceType
= getInstance().getTraceType(traceTypeId
);
577 if (traceType
!= null) {
578 return isCustomTrace(traceType
.getCategoryName() + SEPARATOR
+ traceType
.getName());
585 * Gets the custom trace type ID from the custom trace name
588 * The trace type in human form (category:name)
589 * @return the trace type ID or null if the trace is not a custom one
592 public static String
getCustomTraceTypeId(String traceType
) {
593 String traceTypeId
= null;
595 // do custom trace stuff here
596 String traceTypeToken
[] = traceType
.split(":", 2); //$NON-NLS-1$
597 if (traceTypeToken
.length
== 2) {
598 final boolean startsWithTxt
= traceType
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
);
599 final boolean startsWithXML
= traceType
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
);
601 traceTypeId
= CustomTxtTrace
.class.getCanonicalName() + SEPARATOR
+ traceTypeToken
[1];
602 } else if (startsWithXML
) {
603 traceTypeId
= CustomXmlTrace
.class.getCanonicalName() + SEPARATOR
+ traceTypeToken
[1];
609 TraceTypeHelper
selectTraceType(String path
, Shell shell
) throws TmfTraceImportException
{
610 return selectTraceType(path
, shell
, null);
614 * This member figures out the trace type of a given file. It will prompt
615 * the user if it needs more information to properly pick the trace type.
618 * The path of file to import
620 * a shell to display the message to. If it is null, it is
621 * assumed to be cancelled.
622 * @param traceTypeHint the ID of a trace (like "o.e.l.specifictrace" )
623 * @return null if the request is cancelled or a TraceTypeHelper if it passes.
624 * @throws TmfTraceImportException
625 * if the traces don't match or there are errors in the trace
628 TraceTypeHelper
selectTraceType(String path
, Shell shell
, String traceTypeHint
) throws TmfTraceImportException
{
629 List
<TraceTypeHelper
> validCandidates
= new ArrayList
<TraceTypeHelper
>();
630 getCustomTraceTypes();
631 final Set
<String
> traceTypes
= fTraceTypes
.keySet();
632 for (String traceType
: traceTypes
) {
633 if (validate(traceType
, path
)) {
634 validCandidates
.add(fTraceTypes
.get(traceType
));
638 TraceTypeHelper traceTypeToSet
= null;
639 if (validCandidates
.isEmpty()) {
640 final String errorMsg
= Messages
.TmfOpenTraceHelper_NoTraceTypeMatch
+ path
;
641 throw new TmfTraceImportException(errorMsg
);
642 } else if (validCandidates
.size() != 1) {
643 List
<TraceTypeHelper
> reducedCandidates
= reduce(validCandidates
);
644 for (TraceTypeHelper tth
: reducedCandidates
) {
645 if (tth
.getCanonicalName().equals(traceTypeHint
)) {
646 traceTypeToSet
= tth
;
649 if (traceTypeToSet
== null) {
650 if (reducedCandidates
.size() == 0) {
651 throw new TmfTraceImportException(Messages
.TmfOpenTraceHelper_ReduceError
);
652 } else if (reducedCandidates
.size() == 1) {
653 traceTypeToSet
= reducedCandidates
.get(0);
658 traceTypeToSet
= getTraceTypeToSet(reducedCandidates
, shell
);
662 traceTypeToSet
= validCandidates
.get(0);
664 return traceTypeToSet
;
667 private static List
<TraceTypeHelper
> reduce(List
<TraceTypeHelper
> candidates
) {
668 List
<TraceTypeHelper
> retVal
= new ArrayList
<TraceTypeHelper
>();
670 // get all the tracetypes that are unique in that stage
671 for (TraceTypeHelper trace
: candidates
) {
672 if (isUnique(trace
, candidates
)) {
680 * Only return the leaves of the trace types. Ignore custom trace types.
682 private static boolean isUnique(TraceTypeHelper trace
, List
<TraceTypeHelper
> set
) {
683 if (TmfTraceType
.isCustomTraceId(trace
.getCanonicalName())) {
686 // check if the trace type is the leaf. we make an instance of the trace
687 // type and if it is only an instance of itself, it is a leaf
688 final ITmfTrace tmfTrace
= trace
.getTrace();
690 for (TraceTypeHelper child
: set
) {
691 final ITmfTrace traceCandidate
= child
.getTrace();
692 if (tmfTrace
.getClass().isInstance(traceCandidate
)) {
699 private TraceTypeHelper
getTraceTypeToSet(List
<TraceTypeHelper
> candidates
, Shell shell
) {
700 final Map
<String
, String
> names
= new HashMap
<String
, String
>();
701 Shell shellToShow
= new Shell(shell
);
702 shellToShow
.setText(Messages
.TmfTraceType_SelectTraceType
);
703 final String candidatesToSet
[] = new String
[1];
704 for (TraceTypeHelper candidate
: candidates
) {
705 Button b
= new Button(shellToShow
, SWT
.RADIO
);
706 final String displayName
= candidate
.getCategoryName() + ':' + candidate
.getName();
707 b
.setText(displayName
);
708 names
.put(displayName
, candidate
.getCanonicalName());
710 b
.addSelectionListener(new SelectionListener() {
713 public void widgetSelected(SelectionEvent e
) {
714 final Button source
= (Button
) e
.getSource();
715 candidatesToSet
[0] = (names
.get(source
.getText()));
716 source
.getParent().dispose();
720 public void widgetDefaultSelected(SelectionEvent e
) {
725 shellToShow
.setLayout(new RowLayout(SWT
.VERTICAL
));
729 Display display
= shellToShow
.getDisplay();
730 while (!shellToShow
.isDisposed()) {
731 if (!display
.readAndDispatch()) {
735 return fTraceTypes
.get(candidatesToSet
[0]);
739 * Set the trace type of a {@Link TraceTypeHelper}. Should only be
740 * used internally by this project.
743 * the {@link IPath} path of the resource to set
745 * the {@link TraceTypeHelper} to set the trace type to.
746 * @return Status.OK_Status if successful, error is otherwise.
747 * @throws CoreException
748 * An exception caused by accessing eclipse project items.
751 public static IStatus
setTraceType(IPath path
, TraceTypeHelper traceType
) throws CoreException
{
752 IResource resource
= ResourcesPlugin
.getWorkspace().getRoot().findMember(path
);
753 String TRACE_NAME
= path
.lastSegment();
754 String traceBundle
= null, traceTypeId
= traceType
.getCanonicalName(), traceIcon
= null;
755 if (TmfTraceType
.isCustomTraceId(traceTypeId
)) {
756 traceBundle
= Activator
.getDefault().getBundle().getSymbolicName();
757 traceIcon
= DEFAULT_TRACE_ICON_PATH
;
759 IConfigurationElement ce
= TmfTraceType
.getInstance().getTraceAttributes(traceTypeId
);
760 traceBundle
= ce
.getContributor().getName();
761 traceIcon
= ce
.getAttribute(TmfTraceType
.ICON_ATTR
);
764 resource
.setPersistentProperty(TmfCommonConstants
.TRACEBUNDLE
, traceBundle
);
765 resource
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, traceTypeId
);
766 resource
.setPersistentProperty(TmfCommonConstants
.TRACEICON
, traceIcon
);
768 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(resource
.getProject());
769 if (tmfProject
!= null) {
770 final TmfTraceFolder tracesFolder
= tmfProject
.getTracesFolder();
771 tracesFolder
.refresh();
773 List
<TmfTraceElement
> traces
= tracesFolder
.getTraces();
774 boolean found
= false;
775 for (TmfTraceElement traceElement
: traces
) {
776 if (traceElement
.getName().equals(resource
.getName())) {
777 traceElement
.refreshTraceType();
783 TmfTraceElement te
= new TmfTraceElement(TRACE_NAME
, resource
, tracesFolder
);
784 te
.refreshTraceType();
785 traces
= tracesFolder
.getTraces();
786 for (TmfTraceElement traceElement
: traces
) {
787 traceElement
.refreshTraceType();
791 return Status
.OK_STATUS
;