ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / TmfView.java
index 04a0f9bcaad3934020f45ebd09bfd0d84dc98465..ace756e65ebb85027f4cdde49c0b4097e38e03ef 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2010, 2012 Ericsson
+ * Copyright (c) 2009, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -18,6 +18,10 @@ import org.eclipse.jface.action.Separator;
 import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
+import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.part.ViewPart;
 
@@ -32,60 +36,67 @@ import org.eclipse.ui.part.ViewPart;
  */
 public abstract class TmfView extends ViewPart implements ITmfComponent {
 
-       private final String fName;
-       /**
-        * Action class for pinning of TmfView.
-        * @since 2.0
-        */
-       protected PinTmfViewAction fPinAction;
-
-       // ------------------------------------------------------------------------
-       // Constructor
-       // ------------------------------------------------------------------------
-
-       /**
-        * Constructor. Creates a TMF view and registers to the signal manager.
-        *
-        * @param viewName A view name
-        */
-       public TmfView(String viewName) {
-               super();
-               fName = viewName;
-               TmfSignalManager.register(this);
-       }
-
-       /**
-        * Disposes this view and de-registers itself from the signal manager
-        *
-        * @see org.eclipse.ui.part.WorkbenchPart#dispose()
-        */
-       @Override
-       public void dispose() {
-               TmfSignalManager.deregister(this);
-               super.dispose();
-       }
-
-       // ------------------------------------------------------------------------
-       // ITmfComponent
-       // ------------------------------------------------------------------------
-
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#getName()
-        */
-       @Override
-       public String getName() {
-               return fName;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#broadcast(org.eclipse.linuxtools.tmf.core.signal.TmfSignal)
-        */
-       @Override
-       public void broadcast(TmfSignal signal) {
-               TmfSignalManager.dispatchSignal(signal);
-       }
+    private final String fName;
+
+    /**
+     * Action class for pinning of TmfView.
+     * @since 2.0
+     */
+    protected PinTmfViewAction fPinAction;
+
+    /**
+     * Reference to the trace manager
+     * @since 2.0
+     */
+    protected final TmfTraceManager fTraceManager;
+
+    // ------------------------------------------------------------------------
+    // Constructor
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor. Creates a TMF view and registers to the signal manager.
+     *
+     * @param viewName
+     *            A view name
+     */
+    public TmfView(String viewName) {
+        super();
+        fName = viewName;
+        fTraceManager = TmfTraceManager.getInstance();
+        TmfSignalManager.register(this);
+    }
+
+    /**
+     * Disposes this view and de-registers itself from the signal manager
+     */
+    @Override
+    public void dispose() {
+        TmfSignalManager.deregister(this);
+        super.dispose();
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfComponent
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String getName() {
+        return fName;
+    }
+
+    @Override
+    public void broadcast(TmfSignal signal) {
+        TmfSignalManager.dispatchSignal(signal);
+    }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public void broadcastAsync(TmfSignal signal) {
+        TmfSignalManager.dispatchSignalAsync(signal);
+    }
 
     // ------------------------------------------------------------------------
     // View pinning support
@@ -119,4 +130,20 @@ public abstract class TmfView extends ViewPart implements ITmfComponent {
         }
     }
 
+    /**
+     * Get the currently selected trace, or 'null' if the active editor is not a
+     * TMF trace.
+     *
+     * @return The active trace, or 'null' if not a trace
+     * @since 2.0
+     */
+    public ITmfTrace getActiveTrace() {
+        IEditorPart editor = getSite().getPage().getActiveEditor();
+        if (editor instanceof ITmfTraceEditor) {
+            ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
+            return trace;
+        }
+        return null;
+    }
+
 }
This page took 0.025411 seconds and 5 git commands to generate.