tmf: Switch views to the trace manager
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / TmfView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added possibility to pin view
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.views;
15
16 import org.eclipse.jface.action.IToolBarManager;
17 import org.eclipse.jface.action.Separator;
18 import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
19 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
20 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
21 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
22 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
23 import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
24 import org.eclipse.ui.IEditorPart;
25 import org.eclipse.ui.IWorkbenchActionConstants;
26 import org.eclipse.ui.part.ViewPart;
27
28 /**
29 * Basic abstract TMF view class implementation.
30 *
31 * It registers any sub class to the signal manager for receiving and sending
32 * TMF signals.
33 *
34 * @version 1.2
35 * @author Francois Chouinard
36 */
37 public abstract class TmfView extends ViewPart implements ITmfComponent {
38
39 private final String fName;
40
41 /**
42 * Action class for pinning of TmfView.
43 * @since 2.0
44 */
45 protected PinTmfViewAction fPinAction;
46
47 /**
48 * Reference to the trace manager
49 * @since 2.0
50 */
51 protected final TmfTraceManager fTraceManager;
52
53 // ------------------------------------------------------------------------
54 // Constructor
55 // ------------------------------------------------------------------------
56
57 /**
58 * Constructor. Creates a TMF view and registers to the signal manager.
59 *
60 * @param viewName
61 * A view name
62 */
63 public TmfView(String viewName) {
64 super();
65 fName = viewName;
66 fTraceManager = TmfTraceManager.getInstance();
67 TmfSignalManager.register(this);
68 }
69
70 /**
71 * Disposes this view and de-registers itself from the signal manager
72 */
73 @Override
74 public void dispose() {
75 TmfSignalManager.deregister(this);
76 super.dispose();
77 }
78
79 // ------------------------------------------------------------------------
80 // ITmfComponent
81 // ------------------------------------------------------------------------
82
83 @Override
84 public String getName() {
85 return fName;
86 }
87
88 @Override
89 public void broadcast(TmfSignal signal) {
90 TmfSignalManager.dispatchSignal(signal);
91 }
92
93 // ------------------------------------------------------------------------
94 // View pinning support
95 // ------------------------------------------------------------------------
96
97 /**
98 * Returns whether the pin flag is set.
99 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
100 *
101 * @return pin flag
102 * @since 2.0
103 */
104 public boolean isPinned() {
105 return ((fPinAction != null) && (fPinAction.isChecked()));
106 }
107
108 /**
109 * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag.
110 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
111 *
112 * @since 2.0
113 */
114 protected void contributePinActionToToolBar() {
115 if (fPinAction == null) {
116 fPinAction = new PinTmfViewAction();
117
118 IToolBarManager toolBarManager = getViewSite().getActionBars()
119 .getToolBarManager();
120 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
121 toolBarManager.add(fPinAction);
122 }
123 }
124
125 /**
126 * Get the currently selected trace, or 'null' if the active editor is not a
127 * TMF trace.
128 *
129 * @return The active trace, or 'null' if not a trace
130 * @since 2.0
131 */
132 public ITmfTrace getActiveTrace() {
133 IEditorPart editor = getSite().getPage().getActiveEditor();
134 if (editor instanceof ITmfTraceEditor) {
135 ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
136 return trace;
137 }
138 return null;
139 }
140
141 }
This page took 0.040248 seconds and 6 git commands to generate.