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 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.views; |
b0d3496e | 15 | |
db59ddc2 BH |
16 | import org.eclipse.jface.action.IToolBarManager; |
17 | import org.eclipse.jface.action.Separator; | |
2bdf0193 AM |
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; | |
db59ddc2 | 21 | import org.eclipse.ui.IWorkbenchActionConstants; |
b0d3496e ASL |
22 | import org.eclipse.ui.part.ViewPart; |
23 | ||
24 | /** | |
2f2265e2 | 25 | * Basic abstract TMF view class implementation. |
db59ddc2 | 26 | * |
2f2265e2 | 27 | * It registers any sub class to the signal manager for receiving and sending |
db59ddc2 BH |
28 | * TMF signals. |
29 | * | |
2f2265e2 | 30 | * @author Francois Chouinard |
b0d3496e ASL |
31 | */ |
32 | public abstract class TmfView extends ViewPart implements ITmfComponent { | |
33 | ||
3ac5721a | 34 | private final String fName; |
248af329 | 35 | |
3ac5721a AM |
36 | /** |
37 | * Action class for pinning of TmfView. | |
3ac5721a AM |
38 | */ |
39 | protected PinTmfViewAction fPinAction; | |
40 | ||
41 | // ------------------------------------------------------------------------ | |
42 | // Constructor | |
43 | // ------------------------------------------------------------------------ | |
44 | ||
45 | /** | |
46 | * Constructor. Creates a TMF view and registers to the signal manager. | |
47 | * | |
48 | * @param viewName | |
49 | * A view name | |
50 | */ | |
51 | public TmfView(String viewName) { | |
52 | super(); | |
53 | fName = viewName; | |
54 | TmfSignalManager.register(this); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Disposes this view and de-registers itself from the signal manager | |
59 | */ | |
60 | @Override | |
61 | public void dispose() { | |
62 | TmfSignalManager.deregister(this); | |
63 | super.dispose(); | |
64 | } | |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // ITmfComponent | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | @Override | |
71 | public String getName() { | |
72 | return fName; | |
73 | } | |
74 | ||
75 | @Override | |
76 | public void broadcast(TmfSignal signal) { | |
77 | TmfSignalManager.dispatchSignal(signal); | |
78 | } | |
8d2e2848 | 79 | |
d91063d0 BH |
80 | @Override |
81 | public void broadcastAsync(TmfSignal signal) { | |
82 | TmfSignalManager.dispatchSignalAsync(signal); | |
83 | } | |
84 | ||
ea279a69 FC |
85 | // ------------------------------------------------------------------------ |
86 | // View pinning support | |
87 | // ------------------------------------------------------------------------ | |
88 | ||
db59ddc2 BH |
89 | /** |
90 | * Returns whether the pin flag is set. | |
91 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. | |
92 | * | |
93 | * @return pin flag | |
db59ddc2 BH |
94 | */ |
95 | public boolean isPinned() { | |
96 | return ((fPinAction != null) && (fPinAction.isChecked())); | |
97 | } | |
98 | ||
99 | /** | |
100 | * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag. | |
101 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. | |
db59ddc2 BH |
102 | */ |
103 | protected void contributePinActionToToolBar() { | |
104 | if (fPinAction == null) { | |
105 | fPinAction = new PinTmfViewAction(); | |
106 | ||
107 | IToolBarManager toolBarManager = getViewSite().getActionBars() | |
108 | .getToolBarManager(); | |
109 | toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | |
110 | toolBarManager.add(fPinAction); | |
111 | } | |
112 | } | |
013a5f1c | 113 | } |