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
.signal
.TmfSignalManager
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
44 import org
.eclipse
.swt
.SWT
;
45 import org
.eclipse
.swt
.events
.SelectionEvent
;
46 import org
.eclipse
.swt
.events
.SelectionListener
;
47 import org
.eclipse
.swt
.layout
.RowLayout
;
48 import org
.eclipse
.swt
.widgets
.Button
;
49 import org
.eclipse
.swt
.widgets
.Display
;
50 import org
.eclipse
.swt
.widgets
.Shell
;
51 import org
.eclipse
.ui
.dialogs
.FileSystemElement
;
54 * Utility class for accessing TMF trace type extensions from the platform's
55 * extensions registry.
58 * @author Patrick Tasse
59 * @author Matthew Khouzam
61 public final class TmfTraceType
{
63 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$
65 private static final char SEPARATOR
= ':';
70 public static final String TMF_TRACE_TYPE_ID
= "org.eclipse.linuxtools.tmf.ui.tracetype"; //$NON-NLS-1$
73 * Extension point element 'Category'
75 public static final String CATEGORY_ELEM
= "category"; //$NON-NLS-1$
77 * Extension point element 'Type'
79 public static final String TYPE_ELEM
= "type"; //$NON-NLS-1$
81 * Extension point element 'Default editor'
83 public static final String DEFAULT_EDITOR_ELEM
= "defaultEditor"; //$NON-NLS-1$
85 * Extension point element 'Events table type'
87 public static final String EVENTS_TABLE_TYPE_ELEM
= "eventsTableType"; //$NON-NLS-1$
89 * Extension point element 'Statistics viewer type'
93 public static final String STATISTICS_VIEWER_ELEM
= "statisticsViewerType"; //$NON-NLS-1$
96 * Extension point attribute 'ID'
98 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
100 * Extension point attribute 'name'
102 public static final String NAME_ATTR
= "name"; //$NON-NLS-1$
104 * Extension point attribute 'category'
106 public static final String CATEGORY_ATTR
= "category"; //$NON-NLS-1$
108 * Extension point attribute 'trace_type'
110 public static final String TRACE_TYPE_ATTR
= "trace_type"; //$NON-NLS-1$
112 * Extension point attribute 'event_type'
114 public static final String EVENT_TYPE_ATTR
= "event_type"; //$NON-NLS-1$
116 * Extension point attribute 'icon'
118 public static final String ICON_ATTR
= "icon"; //$NON-NLS-1$
120 * Extension point attribute 'class'
122 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
125 * Custom text label used internally and therefore should not be
130 public static final String CUSTOM_TXT_CATEGORY
= "Custom Text"; //$NON-NLS-1$
132 * Custom XML label used internally and therefore should not be externalized
136 public static final String CUSTOM_XML_CATEGORY
= "Custom XML"; //$NON-NLS-1$
138 // The mapping of available trace type IDs to their corresponding
139 // configuration element
140 private final Map
<String
, IConfigurationElement
> fTraceTypeAttributes
= new HashMap
<String
, IConfigurationElement
>();
141 private final Map
<String
, IConfigurationElement
> fTraceCategories
= new HashMap
<String
, IConfigurationElement
>();
142 private final Map
<String
, TraceTypeHelper
> fTraceTypes
= new LinkedHashMap
<String
, TraceTypeHelper
>();
144 private static TmfTraceType fInstance
= null;
147 * Retrieves the category name from the platform extension registry based on
152 * @return the category name or empty string if not found
154 public static String
getCategoryName(String categoryId
) {
155 IConfigurationElement
[] elements
= Platform
.getExtensionRegistry()
156 .getConfigurationElementsFor(TMF_TRACE_TYPE_ID
);
157 for (IConfigurationElement element
: elements
) {
158 if (element
.getName().equals(CATEGORY_ELEM
) && categoryId
.equals(element
.getAttribute(ID_ATTR
))) {
159 return element
.getAttribute(NAME_ATTR
);
162 return ""; //$NON-NLS-1$
166 * Retrieves and instantiates an element's object based on his plug-in
167 * definition for a specific trace type.
169 * The element's object is instantiated using its 0-argument constructor.
172 * The resource where to find the information about the trace
175 * The name of the element to find under the trace type
177 * @return a new Object based on his definition in plugin.xml, or null if no
178 * definition was found
181 public static Object
getTraceTypeElement(IResource resource
, String element
) {
183 if (resource
!= null) {
184 String traceType
= resource
.getPersistentProperty(TmfCommonConstants
.TRACETYPE
);
186 * Search in the configuration if there is any viewer specified
187 * for this kind of trace type.
189 for (IConfigurationElement ce
: TmfTraceType
.getTypeElements()) {
190 if (ce
.getAttribute(TmfTraceType
.ID_ATTR
).equals(traceType
)) {
191 IConfigurationElement
[] viewerCE
= ce
.getChildren(element
);
192 if (viewerCE
.length
!= 1) {
195 return viewerCE
[0].createExecutableExtension(TmfTraceType
.CLASS_ATTR
);
199 } catch (CoreException e
) {
200 Activator
.getDefault().logError("Error creating the element from the resource", e
); //$NON-NLS-1$
206 * Retrieves all configuration elements from the platform extension registry
207 * for the trace type extension.
209 * @return an array of trace type configuration elements
211 public static IConfigurationElement
[] getTypeElements() {
212 IConfigurationElement
[] elements
= Platform
.getExtensionRegistry()
213 .getConfigurationElementsFor(TMF_TRACE_TYPE_ID
);
214 List
<IConfigurationElement
> typeElements
= new LinkedList
<IConfigurationElement
>();
215 for (IConfigurationElement element
: elements
) {
216 if (element
.getName().equals(TYPE_ELEM
)) {
217 typeElements
.add(element
);
220 return typeElements
.toArray(new IConfigurationElement
[typeElements
.size()]);
223 private TmfTraceType() {
228 * The import utils instance
230 * @return the import utils instance
233 public static TmfTraceType
getInstance() {
234 if (fInstance
== null) {
235 fInstance
= new TmfTraceType();
240 // ------------------------------------------------------------------
242 // ------------------------------------------------------------------
245 * Returns a list of "category:tracetype , ..."
247 * @return returns a list of "category:tracetype , ..."
250 public String
[] getAvailableTraceTypes() {
252 // Generate the list of Category:TraceType to populate the ComboBox
253 List
<String
> traceTypes
= new ArrayList
<String
>();
255 // re-populate custom trace types
256 getCustomTraceTypes();
257 for (String key
: this.fTraceTypes
.keySet()) {
258 TraceTypeHelper tt
= this.fTraceTypes
.get(key
);
259 traceTypes
.add(tt
.getCategoryName() + SEPARATOR
+ tt
.getName());
263 return traceTypes
.toArray(new String
[traceTypes
.size()]);
267 * Gets the custom trace types (custom text and friends)
270 * the type to get (Text, xml or other...)
271 * @return the list of custom trace types
274 public static List
<String
> getCustomTraceTypes(String type
) {
275 List
<String
> traceTypes
= new ArrayList
<String
>();
276 if (type
.equals(CUSTOM_TXT_CATEGORY
)) {
277 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
278 String traceTypeName
= def
.definitionName
;
279 traceTypes
.add(traceTypeName
);
282 if (type
.equals(CUSTOM_XML_CATEGORY
)) {
283 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
284 String traceTypeName
= def
.definitionName
;
285 traceTypes
.add(traceTypeName
);
292 * Gets all the custom trace types
294 * @return the list of custom trace types
297 public List
<String
> getCustomTraceTypes() {
298 List
<String
> traceTypes
= new ArrayList
<String
>();
299 // remove the customTraceTypes
300 final String
[] keySet
= fTraceTypes
.keySet().toArray(new String
[0]);
301 for (String key
: keySet
) {
302 TraceTypeHelper helper
= fTraceTypes
.get(key
);
303 if (helper
.getCategoryName().equals(CUSTOM_TXT_CATEGORY
) || helper
.getCategoryName().equals(CUSTOM_XML_CATEGORY
)) {
304 helper
.getTrace().dispose();
305 fTraceTypes
.remove(key
);
309 // add the custom trace types
310 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
311 String traceTypeId
= CustomTxtTrace
.class.getCanonicalName() + SEPARATOR
+ def
.definitionName
;
312 ITmfTrace trace
= new CustomTxtTrace(def
);
313 TraceTypeHelper tt
= new TraceTypeHelper(traceTypeId
, CUSTOM_TXT_CATEGORY
, def
.definitionName
, trace
);
314 fTraceTypes
.put(traceTypeId
, tt
);
315 traceTypes
.add(traceTypeId
);
316 // Deregister trace as signal handler because it is only used for validation
317 TmfSignalManager
.deregister(trace
);
319 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
320 String traceTypeId
= CustomXmlTrace
.class.getCanonicalName() + SEPARATOR
+ def
.definitionName
;
321 ITmfTrace trace
= new CustomXmlTrace(def
);
322 TraceTypeHelper tt
= new TraceTypeHelper(traceTypeId
, CUSTOM_XML_CATEGORY
, def
.definitionName
, trace
);
323 fTraceTypes
.put(traceTypeId
, tt
);
324 traceTypes
.add(traceTypeId
);
325 // Deregister trace as signal handler because it is only used for validation
326 TmfSignalManager
.deregister(trace
);
332 * Gets a trace type for a given canonical id
335 * the ID of the trace
336 * @return the return type
339 public TraceTypeHelper
getTraceType(String id
) {
341 return fTraceTypes
.get(id
);
344 private void populateCategoriesAndTraceTypes() {
345 if (fTraceTypes
.isEmpty()) {
346 // Populate the Categories and Trace Types
347 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType
.TMF_TRACE_TYPE_ID
);
348 for (IConfigurationElement ce
: config
) {
349 String elementName
= ce
.getName();
350 if (elementName
.equals(TmfTraceType
.TYPE_ELEM
)) {
351 String traceTypeId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
352 fTraceTypeAttributes
.put(traceTypeId
, ce
);
353 } else if (elementName
.equals(TmfTraceType
.CATEGORY_ELEM
)) {
354 String categoryId
= ce
.getAttribute(TmfTraceType
.ID_ATTR
);
355 fTraceCategories
.put(categoryId
, ce
);
358 // create the trace types
359 for (String typeId
: fTraceTypeAttributes
.keySet()) {
360 IConfigurationElement ce
= fTraceTypeAttributes
.get(typeId
);
361 final String category
= getCategory(ce
);
362 final String attribute
= ce
.getAttribute(TmfTraceType
.NAME_ATTR
);
363 ITmfTrace trace
= null;
365 trace
= (ITmfTrace
) ce
.createExecutableExtension(TmfTraceType
.TRACE_TYPE_ATTR
);
366 // Deregister trace as signal handler because it is only used for validation
367 TmfSignalManager
.deregister(trace
);
368 } catch (CoreException e
) {
370 TraceTypeHelper tt
= new TraceTypeHelper(typeId
, category
, attribute
, trace
);
371 fTraceTypes
.put(typeId
, tt
);
376 private String
getCategory(IConfigurationElement ce
) {
377 final String categoryId
= ce
.getAttribute(TmfTraceType
.CATEGORY_ATTR
);
378 if (categoryId
!= null) {
379 IConfigurationElement category
= fTraceCategories
.get(categoryId
);
380 if (category
!= null && !category
.getName().equals("")) { //$NON-NLS-1$
381 return category
.getAttribute(TmfTraceType
.NAME_ATTR
);
384 return "[no category]"; //$NON-NLS-1$
388 * Returns the list of trace categories
390 * @return the list of trace categories
393 public List
<String
> getTraceCategories() {
394 List
<String
> categoryNames
= new ArrayList
<String
>();
395 for (String key
: fTraceTypes
.keySet()) {
396 final String categoryName
= fTraceTypes
.get(key
).getCategoryName();
397 if (!categoryNames
.contains(categoryName
)) {
398 categoryNames
.add(categoryName
);
401 return categoryNames
;
405 * Get the trace type helper classes from category name
407 * @param categoryName
408 * the categoryName to lookup
409 * @return a list of trace type helper classes {@link TraceTypeHelper}
413 public List
<TraceTypeHelper
> getTraceTypes(String categoryName
) {
415 List
<TraceTypeHelper
> traceNames
= new ArrayList
<TraceTypeHelper
>();
416 for (String key
: fTraceTypes
.keySet()) {
417 final String storedCategoryName
= fTraceTypes
.get(key
).getCategoryName();
418 if (storedCategoryName
.equals(categoryName
)) {
419 traceNames
.add(fTraceTypes
.get(key
));
425 private void init() {
426 populateCategoriesAndTraceTypes();
427 getCustomTraceTypes();
431 private static List
<File
> isolateTraces(List
<FileSystemElement
> selectedResources
) {
433 List
<File
> traces
= new ArrayList
<File
>();
436 Iterator
<FileSystemElement
> resources
= selectedResources
.iterator();
438 // Get the sorted list of unique entries
439 Map
<String
, File
> fileSystemObjects
= new HashMap
<String
, File
>();
440 while (resources
.hasNext()) {
441 File resource
= (File
) resources
.next().getFileSystemObject();
442 String key
= resource
.getAbsolutePath();
443 fileSystemObjects
.put(key
, resource
);
445 List
<String
> files
= new ArrayList
<String
>(fileSystemObjects
.keySet());
446 Collections
.sort(files
);
448 // After sorting, traces correspond to the unique prefixes
449 String prefix
= null;
450 for (int i
= 0; i
< files
.size(); i
++) {
451 File file
= fileSystemObjects
.get(files
.get(i
));
452 String name
= file
.getAbsolutePath();
453 if (prefix
== null || !name
.startsWith(prefix
)) {
454 prefix
= name
; // new prefix
463 * Validate a trace type
465 * @param traceTypeName
466 * the trace category (canonical name)
468 * the file name (and path)
469 * @return true if the trace is of a valid type
472 public boolean validate(String traceTypeName
, String fileName
) {
473 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
474 final TraceTypeHelper traceTypeHelper
= fTraceTypes
.get(traceTypeName
);
475 if (!traceTypeHelper
.validate(fileName
)) {
485 * @param traceToValidate
486 * the trace category (canonical name)
487 * @return true if the trace is of a valid type
490 public boolean validate(TraceValidationHelper traceToValidate
) {
491 return validate(traceToValidate
.getTraceType(), traceToValidate
.getTraceToScan());
495 * validate list of traces with a tracetype
497 * @param traceTypeName
498 * the trace category (canonical name)
499 * @param selectedResources
500 * List of traces to validate
501 * @return true if all the traces are valid
504 public boolean validateTrace(String traceTypeName
, List
<FileSystemElement
> selectedResources
) {
505 List
<File
> traces
= isolateTraces(selectedResources
);
506 return validateTraceFiles(traceTypeName
, traces
);
510 * Validate a list of files with a tracetype
512 * @param traceTypeName
513 * the trace category (canonical name)
515 * the list of files to check if they are trace
516 * @return true if all the traces are valid
519 public boolean validateTraceFiles(String traceTypeName
, List
<File
> traces
) {
520 if (traceTypeName
!= null && !"".equals(traceTypeName
) && //$NON-NLS-1$
521 !traceTypeName
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
) && !traceTypeName
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
)) {
522 for (File trace
: traces
) {
523 if (!validate(traceTypeName
, trace
.getAbsolutePath())) {
532 * Get a configuration element for a given name
536 * @return the configuration element, can be null
539 public IConfigurationElement
getTraceAttributes(String traceType
) {
540 return fTraceTypeAttributes
.get(traceType
);
544 * Find the id of a trace type by its parameters
547 * like "ctf" or "custom text"
550 * @return an id like "org.eclipse.linuxtools.blabla...
553 public String
getTraceTypeId(String category
, String traceType
) {
554 for (String key
: fTraceTypes
.keySet()) {
555 if (fTraceTypes
.get(key
).getCategoryName().equals(category
.trim()) && fTraceTypes
.get(key
).getName().equals(traceType
.trim())) {
563 * Is the trace a custom (user-defined) trace type. These are the traces
564 * like : text and xml defined by the custom trace wizard.
567 * the trace type in human form (category:name)
568 * @return true if the trace is a custom type
571 public static boolean isCustomTrace(String traceType
) {
572 final boolean startsWithTxt
= traceType
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
);
573 final boolean startsWithXML
= traceType
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
);
574 return (startsWithTxt
|| startsWithXML
);
578 * Is the trace type id a custom (user-defined) trace type. These are the
579 * traces like : text and xml defined by the custom trace wizard.
583 * @return true if the trace is a custom type
585 private static boolean isCustomTraceId(String traceTypeId
) {
586 TraceTypeHelper traceType
= getInstance().getTraceType(traceTypeId
);
587 if (traceType
!= null) {
588 return isCustomTrace(traceType
.getCategoryName() + SEPARATOR
+ traceType
.getName());
595 * Gets the custom trace type ID from the custom trace name
598 * The trace type in human form (category:name)
599 * @return the trace type ID or null if the trace is not a custom one
602 public static String
getCustomTraceTypeId(String traceType
) {
603 String traceTypeId
= null;
605 // do custom trace stuff here
606 String traceTypeToken
[] = traceType
.split(":", 2); //$NON-NLS-1$
607 if (traceTypeToken
.length
== 2) {
608 final boolean startsWithTxt
= traceType
.startsWith(TmfTraceType
.CUSTOM_TXT_CATEGORY
);
609 final boolean startsWithXML
= traceType
.startsWith(TmfTraceType
.CUSTOM_XML_CATEGORY
);
611 traceTypeId
= CustomTxtTrace
.class.getCanonicalName() + SEPARATOR
+ traceTypeToken
[1];
612 } else if (startsWithXML
) {
613 traceTypeId
= CustomXmlTrace
.class.getCanonicalName() + SEPARATOR
+ traceTypeToken
[1];
619 TraceTypeHelper
selectTraceType(String path
, Shell shell
) throws TmfTraceImportException
{
620 return selectTraceType(path
, shell
, null);
624 * This member figures out the trace type of a given file. It will prompt
625 * the user if it needs more information to properly pick the trace type.
628 * The path of file to import
630 * a shell to display the message to. If it is null, it is
631 * assumed to be cancelled.
632 * @param traceTypeHint the ID of a trace (like "o.e.l.specifictrace" )
633 * @return null if the request is cancelled or a TraceTypeHelper if it passes.
634 * @throws TmfTraceImportException
635 * if the traces don't match or there are errors in the trace
638 TraceTypeHelper
selectTraceType(String path
, Shell shell
, String traceTypeHint
) throws TmfTraceImportException
{
639 List
<TraceTypeHelper
> validCandidates
= new ArrayList
<TraceTypeHelper
>();
640 getCustomTraceTypes();
641 final Set
<String
> traceTypes
= fTraceTypes
.keySet();
642 for (String traceType
: traceTypes
) {
643 if (validate(traceType
, path
)) {
644 validCandidates
.add(fTraceTypes
.get(traceType
));
648 TraceTypeHelper traceTypeToSet
= null;
649 if (validCandidates
.isEmpty()) {
650 final String errorMsg
= Messages
.TmfOpenTraceHelper_NoTraceTypeMatch
+ path
;
651 throw new TmfTraceImportException(errorMsg
);
652 } else if (validCandidates
.size() != 1) {
653 List
<TraceTypeHelper
> reducedCandidates
= reduce(validCandidates
);
654 for (TraceTypeHelper tth
: reducedCandidates
) {
655 if (tth
.getCanonicalName().equals(traceTypeHint
)) {
656 traceTypeToSet
= tth
;
659 if (traceTypeToSet
== null) {
660 if (reducedCandidates
.size() == 0) {
661 throw new TmfTraceImportException(Messages
.TmfOpenTraceHelper_ReduceError
);
662 } else if (reducedCandidates
.size() == 1) {
663 traceTypeToSet
= reducedCandidates
.get(0);
668 traceTypeToSet
= getTraceTypeToSet(reducedCandidates
, shell
);
672 traceTypeToSet
= validCandidates
.get(0);
674 return traceTypeToSet
;
677 private static List
<TraceTypeHelper
> reduce(List
<TraceTypeHelper
> candidates
) {
678 List
<TraceTypeHelper
> retVal
= new ArrayList
<TraceTypeHelper
>();
680 // get all the tracetypes that are unique in that stage
681 for (TraceTypeHelper trace
: candidates
) {
682 if (isUnique(trace
, candidates
)) {
690 * Only return the leaves of the trace types. Ignore custom trace types.
692 private static boolean isUnique(TraceTypeHelper trace
, List
<TraceTypeHelper
> set
) {
693 if (TmfTraceType
.isCustomTraceId(trace
.getCanonicalName())) {
696 // check if the trace type is the leaf. we make an instance of the trace
697 // type and if it is only an instance of itself, it is a leaf
698 final ITmfTrace tmfTrace
= trace
.getTrace();
700 for (TraceTypeHelper child
: set
) {
701 final ITmfTrace traceCandidate
= child
.getTrace();
702 if (tmfTrace
.getClass().isInstance(traceCandidate
)) {
709 private TraceTypeHelper
getTraceTypeToSet(List
<TraceTypeHelper
> candidates
, Shell shell
) {
710 final Map
<String
, String
> names
= new HashMap
<String
, String
>();
711 Shell shellToShow
= new Shell(shell
);
712 shellToShow
.setText(Messages
.TmfTraceType_SelectTraceType
);
713 final String candidatesToSet
[] = new String
[1];
714 for (TraceTypeHelper candidate
: candidates
) {
715 Button b
= new Button(shellToShow
, SWT
.RADIO
);
716 final String displayName
= candidate
.getCategoryName() + ':' + candidate
.getName();
717 b
.setText(displayName
);
718 names
.put(displayName
, candidate
.getCanonicalName());
720 b
.addSelectionListener(new SelectionListener() {
723 public void widgetSelected(SelectionEvent e
) {
724 final Button source
= (Button
) e
.getSource();
725 candidatesToSet
[0] = (names
.get(source
.getText()));
726 source
.getParent().dispose();
730 public void widgetDefaultSelected(SelectionEvent e
) {
735 shellToShow
.setLayout(new RowLayout(SWT
.VERTICAL
));
739 Display display
= shellToShow
.getDisplay();
740 while (!shellToShow
.isDisposed()) {
741 if (!display
.readAndDispatch()) {
745 return fTraceTypes
.get(candidatesToSet
[0]);
749 * Set the trace type of a {@Link TraceTypeHelper}. Should only be
750 * used internally by this project.
753 * the {@link IPath} path of the resource to set
755 * the {@link TraceTypeHelper} to set the trace type to.
756 * @return Status.OK_Status if successful, error is otherwise.
757 * @throws CoreException
758 * An exception caused by accessing eclipse project items.
761 public static IStatus
setTraceType(IPath path
, TraceTypeHelper traceType
) throws CoreException
{
762 IResource resource
= ResourcesPlugin
.getWorkspace().getRoot().findMember(path
);
763 String TRACE_NAME
= path
.lastSegment();
764 String traceBundle
= null, traceTypeId
= traceType
.getCanonicalName(), traceIcon
= null;
765 if (TmfTraceType
.isCustomTraceId(traceTypeId
)) {
766 traceBundle
= Activator
.getDefault().getBundle().getSymbolicName();
767 traceIcon
= DEFAULT_TRACE_ICON_PATH
;
769 IConfigurationElement ce
= TmfTraceType
.getInstance().getTraceAttributes(traceTypeId
);
770 traceBundle
= ce
.getContributor().getName();
771 traceIcon
= ce
.getAttribute(TmfTraceType
.ICON_ATTR
);
774 resource
.setPersistentProperty(TmfCommonConstants
.TRACEBUNDLE
, traceBundle
);
775 resource
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, traceTypeId
);
776 resource
.setPersistentProperty(TmfCommonConstants
.TRACEICON
, traceIcon
);
778 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(resource
.getProject());
779 if (tmfProject
!= null) {
780 final TmfTraceFolder tracesFolder
= tmfProject
.getTracesFolder();
781 tracesFolder
.refresh();
783 List
<TmfTraceElement
> traces
= tracesFolder
.getTraces();
784 boolean found
= false;
785 for (TmfTraceElement traceElement
: traces
) {
786 if (traceElement
.getName().equals(resource
.getName())) {
787 traceElement
.refreshTraceType();
793 TmfTraceElement te
= new TmfTraceElement(TRACE_NAME
, resource
, tracesFolder
);
794 te
.refreshTraceType();
795 traces
= tracesFolder
.getTraces();
796 for (TmfTraceElement traceElement
: traces
) {
797 traceElement
.refreshTraceType();
801 return Status
.OK_STATUS
;