Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / editors / TmfEventsEditor.java
index 841170953e709d66fc2578f825e09e4ba9071a2e..8c0082980ed9ed5ff6045336428ba4abf1e8f597 100644 (file)
 \r
 package org.eclipse.linuxtools.tmf.ui.editors;\r
 \r
+import java.io.FileNotFoundException;\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+\r
 import org.eclipse.core.resources.IMarker;\r
 import org.eclipse.core.resources.IMarkerDelta;\r
 import org.eclipse.core.resources.IResource;\r
@@ -20,16 +24,23 @@ import org.eclipse.core.resources.IResourceChangeListener;
 import org.eclipse.core.resources.IResourceDelta;\r
 import org.eclipse.core.resources.ResourcesPlugin;\r
 import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.signal.TmfTraceSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager;\r
+import org.eclipse.core.runtime.InvalidRegistryObjectException;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;\r
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;\r
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r
+import org.eclipse.linuxtools.tmf.core.util.TmfTraceType;\r
+import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomEventsTable;\r
+import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTxtTrace;\r
+import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomXmlTrace;\r
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;\r
 import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;\r
 import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;\r
 import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal;\r
 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;\r
-import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.ui.IEditorInput;\r
@@ -39,8 +50,8 @@ import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IPropertyListener;\r
 import org.eclipse.ui.IReusableEditor;\r
 import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.ide.FileStoreEditorInput;\r
 import org.eclipse.ui.ide.IGotoMarker;\r
+import org.osgi.framework.Bundle;\r
 \r
 /**\r
  * <b><u>TmfEventsEditor</u></b>\r
@@ -51,6 +62,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
     \r
     private TmfEventsTable fEventsTable;\r
     private IResource fResource;\r
+    @SuppressWarnings("rawtypes")\r
     private ITmfTrace fTrace;\r
     private Composite fParent;\r
 \r
@@ -62,6 +74,7 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
     public void doSaveAs() {\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Override\r
     public void init(IEditorSite site, IEditorInput input) throws PartInitException {\r
         if (input instanceof TmfEditorInput) {\r
@@ -69,17 +82,27 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
             fTrace = ((TmfEditorInput) input).getTrace();\r
         } else if (input instanceof IFileEditorInput) {\r
             fResource = ((IFileEditorInput) input).getFile();\r
-            fTrace = ParserProviderManager.getTrace(fResource);\r
-            input = new TmfEditorInput(fResource, fTrace);\r
-        } else if (input instanceof FileStoreEditorInput) {\r
             try {\r
-                FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) input;\r
-                fResource = ProjectView.createLink(fileStoreEditorInput.getURI());\r
-                fTrace = ParserProviderManager.getTrace(fResource);\r
-                input = new TmfEditorInput(fResource, fTrace);\r
+                String traceTypeId = fResource.getPersistentProperty(TmfTraceElement.TRACETYPE);\r
+                if (traceTypeId != null) {\r
+                    for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
+                        if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) {\r
+                            fTrace = (ITmfTrace<?>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);\r
+                            TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
+                            String path = fResource.getLocation().toOSString();\r
+                            fTrace.initTrace(path, event.getClass(), true);\r
+                            break;\r
+                        }\r
+                    }\r
+                }\r
+            } catch (InvalidRegistryObjectException e) {\r
+                e.printStackTrace();\r
+            } catch (FileNotFoundException e) {\r
+                e.printStackTrace();\r
             } catch (CoreException e) {\r
-                throw new PartInitException(e.getMessage());\r
+                e.printStackTrace();\r
             }\r
+            input = new TmfEditorInput(fResource, fTrace);\r
         } else {\r
             throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$\r
         }\r
@@ -155,15 +178,66 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
     }\r
 \r
     protected TmfEventsTable createEventsTable(Composite parent, int cacheSize) {\r
-        TmfEventsTable eventsTable = ParserProviderManager.getEventsTable(fTrace, parent, cacheSize);\r
+        TmfEventsTable eventsTable = getEventsTable(parent, cacheSize);\r
         if (eventsTable == null) {\r
             eventsTable = new TmfEventsTable(parent, cacheSize);\r
         }\r
         return eventsTable;\r
     }\r
     \r
+    private TmfEventsTable getEventsTable(Composite parent, int cacheSize) {\r
+        TmfEventsTable eventsTable = null;\r
+        try {\r
+            String traceType = fResource.getPersistentProperty(TmfTraceElement.TRACETYPE);\r
+            if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {\r
+                return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize);\r
+            }\r
+            if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {\r
+                return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize);\r
+            }\r
+            for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
+                if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(traceType)) {\r
+                    IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);\r
+                    if (eventsTableTypeCE.length != 1) {\r
+                        break;\r
+                    }\r
+                    String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);\r
+                    if (eventsTableType == null || eventsTableType.length() == 0) {\r
+                        break;\r
+                    }\r
+                    Bundle bundle = Platform.getBundle(ce.getContributor().getName());\r
+                    Class<?> c = bundle.loadClass(eventsTableType);\r
+                    Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };\r
+                    Constructor<?> constructor = c.getConstructor(constructorArgs);\r
+                    Object[] args = new Object[] { parent, cacheSize };\r
+                    eventsTable = (TmfEventsTable) constructor.newInstance(args);\r
+                    break;\r
+                }\r
+            }\r
+        } catch (InvalidRegistryObjectException e) {\r
+            e.printStackTrace();\r
+        } catch (CoreException e) {\r
+            e.printStackTrace();\r
+        } catch (ClassNotFoundException e) {\r
+            e.printStackTrace();\r
+        } catch (SecurityException e) {\r
+            e.printStackTrace();\r
+        } catch (NoSuchMethodException e) {\r
+            e.printStackTrace();\r
+        } catch (IllegalArgumentException e) {\r
+            e.printStackTrace();\r
+        } catch (InstantiationException e) {\r
+            e.printStackTrace();\r
+        } catch (IllegalAccessException e) {\r
+            e.printStackTrace();\r
+        } catch (InvocationTargetException e) {\r
+            e.printStackTrace();\r
+        }\r
+        return eventsTable;\r
+    }\r
+\r
     @Override\r
-       public ITmfTrace getTrace() {\r
+       public ITmfTrace<?> getTrace() {\r
         return fTrace;\r
     }\r
 \r
@@ -217,11 +291,32 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus
     // Signal handlers\r
     // ------------------------------------------------------------------------\r
     \r
+    @SuppressWarnings("unchecked")\r
     @TmfSignalHandler\r
     public void traceParserUpdated(TmfTraceParserUpdatedSignal signal) {\r
         if (signal.getTraceResource().equals(fResource)) {\r
             broadcast(new TmfTraceClosedSignal(this, fTrace));\r
-            fTrace = ParserProviderManager.getTrace(fResource);\r
+            try {\r
+                fTrace = null;\r
+                String traceTypeId = fResource.getPersistentProperty(TmfTraceElement.TRACETYPE);\r
+                if (traceTypeId != null) {\r
+                    for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {\r
+                        if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) {\r
+                            fTrace = (ITmfTrace<?>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);\r
+                            TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
+                            String path = fResource.getLocation().toOSString();\r
+                            fTrace.initTrace(path, event.getClass(), true);\r
+                            break;\r
+                        }\r
+                    }\r
+                }\r
+            } catch (InvalidRegistryObjectException e) {\r
+                e.printStackTrace();\r
+            } catch (FileNotFoundException e) {\r
+                e.printStackTrace();\r
+            } catch (CoreException e) {\r
+                e.printStackTrace();\r
+            }\r
             fEventsTable.dispose();\r
             if (fTrace != null) {\r
                 fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());\r
This page took 0.026421 seconds and 5 git commands to generate.