1 /*******************************************************************************
2 * Copyright (c) 2010 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.parsers
;
15 import java
.util
.ArrayList
;
16 import java
.util
.LinkedHashMap
;
17 import java
.util
.List
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
23 import org
.eclipse
.core
.runtime
.IExtensionRegistry
;
24 import org
.eclipse
.core
.runtime
.Platform
;
25 import org
.eclipse
.core
.runtime
.QualifiedName
;
26 import org
.eclipse
.core
.runtime
.content
.IContentType
;
27 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.TmfUiPlugin
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
33 public class ParserProviderManager
{
35 public static final QualifiedName PARSER_PROPERTY
= new QualifiedName(TmfUiPlugin
.PLUGIN_ID
, "PARSER"); //$NON-NLS-1$
37 private static List
<IParserProvider
> fParserProviders
= new ArrayList
<IParserProvider
>();
39 public static void init() {
40 IExtensionRegistry reg
= Platform
.getExtensionRegistry();
41 IConfigurationElement
[] extensions
= reg
.getConfigurationElementsFor("org.eclipse.linuxtools.tmf.ui.parserProviders"); //$NON-NLS-1$
42 for (int i
= 0; i
< extensions
.length
; i
++) {
43 IConfigurationElement element
= extensions
[i
];
45 IParserProvider parserProvider
= (IParserProvider
) element
.createExecutableExtension("class"); //$NON-NLS-1$
46 addParserProvider(parserProvider
);
47 } catch (CoreException e
) {
53 public static void addParserProvider(IParserProvider parserProvider
) {
54 fParserProviders
.add(parserProvider
);
57 public static void removeParserProvider(IParserProvider parserProvider
) {
58 fParserProviders
.remove(parserProvider
);
61 public static ITmfTrace
getTrace(IResource resource
) {
62 if (resource
== null) {
66 String parser
= resource
.getPersistentProperty(PARSER_PROPERTY
);
68 for (IParserProvider parserProvider
: fParserProviders
) {
69 if (parserProvider
!= null) {
70 ITmfTrace trace
= parserProvider
.getTraceForParser(parser
, resource
);
77 IContentType contentType
= Platform
.getContentTypeManager().findContentTypeFor(resource
.getName());
78 if (contentType
!= null) {
79 for (IParserProvider parserProvider
: fParserProviders
) {
80 if (parserProvider
!= null) {
81 ITmfTrace trace
= parserProvider
.getTraceForContentType(contentType
.getId(), resource
);
83 resource
.setPersistentProperty(PARSER_PROPERTY
, trace
.getClass().getCanonicalName());
89 } catch (CoreException e
) {
95 public static String
getEditorId(IResource resource
) {
96 if (resource
== null) {
100 String parser
= resource
.getPersistentProperty(PARSER_PROPERTY
);
101 if (parser
!= null) {
102 for (IParserProvider parserProvider
: fParserProviders
) {
103 if (parserProvider
!= null) {
104 String editorId
= parserProvider
.getEditorIdForParser(parser
);
105 if (editorId
!= null) {
111 return TmfEventsEditor
.ID
;
112 } catch (CoreException e
) {
118 public static Map
<String
, Map
<String
, String
>> getParserMap() {
119 Map
<String
, Map
<String
, String
>> parserMap
= new LinkedHashMap
<String
, Map
<String
, String
>>();
120 for (IParserProvider parserProvider
: fParserProviders
) {
121 parserMap
.put(parserProvider
.getCategory(), parserProvider
.getParserMap());
126 public static TmfEventsTable
getEventsTable(ITmfTrace trace
, Composite parent
, int cacheSize
) {
127 for (IParserProvider parserProvider
: fParserProviders
) {
128 if (parserProvider
!= null) {
129 TmfEventsTable eventsTable
= parserProvider
.getEventsTable(trace
, parent
, cacheSize
);
130 if (eventsTable
!= null) {