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