Commit | Line | Data |
---|---|---|
b0d3496e | 1 | /******************************************************************************* |
d91063d0 | 2 | * Copyright (c) 2009, 2014 Ericsson |
db59ddc2 | 3 | * |
b0d3496e ASL |
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 | |
013a5f1c | 8 | * |
b0d3496e ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
db59ddc2 | 11 | * Bernd Hufmann - Added possibility to pin view |
b0d3496e ASL |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ui.views; | |
15 | ||
db59ddc2 BH |
16 | import org.eclipse.jface.action.IToolBarManager; |
17 | import org.eclipse.jface.action.Separator; | |
6c13869b FC |
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; | |
3ac5721a | 21 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
248af329 | 22 | import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; |
3ac5721a AM |
23 | import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor; |
24 | import org.eclipse.ui.IEditorPart; | |
db59ddc2 | 25 | import org.eclipse.ui.IWorkbenchActionConstants; |
b0d3496e ASL |
26 | import org.eclipse.ui.part.ViewPart; |
27 | ||
28 | /** | |
2f2265e2 | 29 | * Basic abstract TMF view class implementation. |
db59ddc2 | 30 | * |
2f2265e2 | 31 | * It registers any sub class to the signal manager for receiving and sending |
db59ddc2 BH |
32 | * TMF signals. |
33 | * | |
34 | * @version 1.2 | |
2f2265e2 | 35 | * @author Francois Chouinard |
b0d3496e ASL |
36 | */ |
37 | public abstract class TmfView extends ViewPart implements ITmfComponent { | |
38 | ||
3ac5721a | 39 | private final String fName; |
248af329 | 40 | |
3ac5721a AM |
41 | /** |
42 | * Action class for pinning of TmfView. | |
3ac5721a AM |
43 | * @since 2.0 |
44 | */ | |
45 | protected PinTmfViewAction fPinAction; | |
46 | ||
248af329 AM |
47 | /** |
48 | * Reference to the trace manager | |
49 | * @since 2.0 | |
50 | */ | |
51 | protected final TmfTraceManager fTraceManager; | |
52 | ||
3ac5721a AM |
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; | |
248af329 | 66 | fTraceManager = TmfTraceManager.getInstance(); |
3ac5721a AM |
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 | } | |
8d2e2848 | 92 | |
d91063d0 BH |
93 | /** |
94 | * @since 3.0 | |
95 | */ | |
96 | @Override | |
97 | public void broadcastAsync(TmfSignal signal) { | |
98 | TmfSignalManager.dispatchSignalAsync(signal); | |
99 | } | |
100 | ||
ea279a69 FC |
101 | // ------------------------------------------------------------------------ |
102 | // View pinning support | |
103 | // ------------------------------------------------------------------------ | |
104 | ||
db59ddc2 BH |
105 | /** |
106 | * Returns whether the pin flag is set. | |
107 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. | |
108 | * | |
109 | * @return pin flag | |
9da25000 | 110 | * @since 2.0 |
db59ddc2 BH |
111 | */ |
112 | public boolean isPinned() { | |
113 | return ((fPinAction != null) && (fPinAction.isChecked())); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag. | |
118 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. | |
119 | * | |
9da25000 | 120 | * @since 2.0 |
db59ddc2 BH |
121 | */ |
122 | protected void contributePinActionToToolBar() { | |
123 | if (fPinAction == null) { | |
124 | fPinAction = new PinTmfViewAction(); | |
125 | ||
126 | IToolBarManager toolBarManager = getViewSite().getActionBars() | |
127 | .getToolBarManager(); | |
128 | toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | |
129 | toolBarManager.add(fPinAction); | |
130 | } | |
131 | } | |
ea279a69 | 132 | |
3ac5721a AM |
133 | /** |
134 | * Get the currently selected trace, or 'null' if the active editor is not a | |
135 | * TMF trace. | |
136 | * | |
137 | * @return The active trace, or 'null' if not a trace | |
138 | * @since 2.0 | |
139 | */ | |
140 | public ITmfTrace getActiveTrace() { | |
141 | IEditorPart editor = getSite().getPage().getActiveEditor(); | |
142 | if (editor instanceof ITmfTraceEditor) { | |
143 | ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace(); | |
144 | return trace; | |
145 | } | |
146 | return null; | |
147 | } | |
148 | ||
013a5f1c | 149 | } |