Fix HistogramView recounts on range update
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / parsers / custom / CustomParserProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.parsers.custom;
14
15 import java.io.FileNotFoundException;
16 import java.util.LinkedHashMap;
17 import java.util.Map;
18
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;
24
25 public class CustomParserProvider implements IParserProvider {
26
27 @Override
28 public String getCategory() {
29 return "Custom"; //$NON-NLS-1$
30 }
31
32 @Override
33 public ITmfTrace<?> getTraceForParser(String parser, IResource resource) {
34 try {
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);
40 }
41 }
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);
45 }
46 }
47 } catch (FileNotFoundException e) {
48 e.printStackTrace();
49 }
50 return null;
51 }
52
53 @Override
54 public ITmfTrace<?> getTraceForContentType(String contentTypeId, IResource resource) {
55 return null;
56 }
57
58 @Override
59 public String getEditorIdForParser(String parser) {
60 return null;
61 }
62
63 @Override
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$
69 return eventTypeMap;
70 }
71 }
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$
76 return eventTypeMap;
77 }
78 }
79 return null;
80 }
81
82 @Override
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;
89 }
90 return labels;
91 }
92 }
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;
98 }
99 return labels;
100 }
101 }
102 return null;
103 }
104
105 @Override
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$
110 }
111 for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
112 parserMap.put(def.definitionName, CustomXmlTrace.class.getCanonicalName() + "." + def.definitionName); //$NON-NLS-1$
113 }
114 return parserMap;
115 }
116
117 @Override
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);
123 }
124 return null;
125 }
126
127 }
This page took 0.047748 seconds and 5 git commands to generate.