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
.custom
;
15 import java
.io
.FileNotFoundException
;
16 import java
.util
.LinkedHashMap
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.IParserProvider
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
25 public class CustomParserProvider
implements IParserProvider
{
28 public String
getCategory() {
29 return "Custom"; //$NON-NLS-1$
33 public ITmfTrace
<?
> getTraceForParser(String parser
, IResource resource
) {
35 String name
= resource
.getName();
36 String path
= resource
.getLocation().toOSString();
37 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
38 if (parser
.equals(CustomTxtTrace
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
39 return new CustomTxtTrace(name
, def
, path
, 100);
42 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
43 if (parser
.equals(CustomXmlTrace
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
44 return new CustomXmlTrace(name
, def
, path
, 100);
47 } catch (FileNotFoundException e
) {
54 public ITmfTrace
<?
> getTraceForContentType(String contentTypeId
, IResource resource
) {
59 public String
getEditorIdForParser(String parser
) {
64 public Map
<String
, String
> getEventTypeMapForParser(String parser
) {
65 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
66 if (parser
.equals(CustomTxtTrace
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
67 Map
<String
, String
> eventTypeMap
= new LinkedHashMap
<String
, String
>();
68 eventTypeMap
.put(def
.definitionName
, CustomTxtEventType
.class.getCanonicalName() + "." + def
.definitionName
); //$NON-NLS-1$
72 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
73 if (parser
.equals(CustomXmlTrace
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
74 Map
<String
, String
> eventTypeMap
= new LinkedHashMap
<String
, String
>();
75 eventTypeMap
.put(def
.definitionName
, CustomXmlEventType
.class.getCanonicalName() + "." + def
.definitionName
); //$NON-NLS-1$
83 public String
[] getFieldLabelsForEventType(String eventType
) {
84 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
85 if (eventType
.equals(CustomTxtEventType
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
86 String
[] labels
= new String
[def
.outputs
.size()];
87 for (int i
= 0; i
< labels
.length
; i
++) {
88 labels
[i
] = def
.outputs
.get(i
).name
;
93 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
94 if (eventType
.equals(CustomXmlEventType
.class.getCanonicalName() + "." + def
.definitionName
)) { //$NON-NLS-1$
95 String
[] labels
= new String
[def
.outputs
.size()];
96 for (int i
= 0; i
< labels
.length
; i
++) {
97 labels
[i
] = def
.outputs
.get(i
).name
;
106 public Map
<String
, String
> getParserMap() {
107 Map
<String
, String
> parserMap
= new LinkedHashMap
<String
, String
>();
108 for (CustomTxtTraceDefinition def
: CustomTxtTraceDefinition
.loadAll()) {
109 parserMap
.put(def
.definitionName
, CustomTxtTrace
.class.getCanonicalName() + "." + def
.definitionName
); //$NON-NLS-1$
111 for (CustomXmlTraceDefinition def
: CustomXmlTraceDefinition
.loadAll()) {
112 parserMap
.put(def
.definitionName
, CustomXmlTrace
.class.getCanonicalName() + "." + def
.definitionName
); //$NON-NLS-1$
118 public TmfEventsTable
getEventsTable(ITmfTrace
<?
> trace
, Composite parent
, int cacheSize
) {
119 if (trace
instanceof CustomTxtTrace
) {
120 return new CustomEventsTable(((CustomTxtTrace
) trace
).getDefinition(), parent
, cacheSize
);
121 } else if (trace
instanceof CustomXmlTrace
) {
122 return new CustomEventsTable(((CustomXmlTrace
) trace
).getDefinition(), parent
, cacheSize
);