linux.core: Remove throws runtime exceptions
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / TmfView.java
CommitLineData
b0d3496e 1/*******************************************************************************
1cefda97 2 * Copyright (c) 2009, 2016 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
d2e4afa7 12 * Marc-Andre Laperle - Support for view alignment
b0d3496e
ASL
13 *******************************************************************************/
14
2bdf0193 15package org.eclipse.tracecompass.tmf.ui.views;
b0d3496e 16
db59ddc2
BH
17import org.eclipse.jface.action.IToolBarManager;
18import org.eclipse.jface.action.Separator;
d2e4afa7
MAL
19import org.eclipse.swt.events.ControlAdapter;
20import org.eclipse.swt.events.ControlEvent;
21import org.eclipse.swt.widgets.Composite;
22import org.eclipse.tracecompass.internal.tmf.ui.views.TimeAlignViewsAction;
23import org.eclipse.tracecompass.internal.tmf.ui.views.TmfAlignmentSynchronizer;
2bdf0193
AM
24import org.eclipse.tracecompass.tmf.core.component.ITmfComponent;
25import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
26import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
1cefda97 27import org.eclipse.ui.IActionBars;
d2e4afa7 28import org.eclipse.ui.IPartListener;
db59ddc2 29import org.eclipse.ui.IWorkbenchActionConstants;
d2e4afa7 30import org.eclipse.ui.IWorkbenchPart;
b0d3496e
ASL
31import org.eclipse.ui.part.ViewPart;
32
33/**
2f2265e2 34 * Basic abstract TMF view class implementation.
db59ddc2 35 *
2f2265e2 36 * It registers any sub class to the signal manager for receiving and sending
db59ddc2
BH
37 * TMF signals.
38 *
2f2265e2 39 * @author Francois Chouinard
b0d3496e
ASL
40 */
41public abstract class TmfView extends ViewPart implements ITmfComponent {
42
3ac5721a 43 private final String fName;
d2e4afa7
MAL
44 /** This allows us to keep track of the view sizes */
45 private Composite fParentComposite;
46 private ControlAdapter fControlListener;
47 private static final TmfAlignmentSynchronizer TIME_ALIGNMENT_SYNCHRONIZER = new TmfAlignmentSynchronizer();
248af329 48
3ac5721a
AM
49 /**
50 * Action class for pinning of TmfView.
3ac5721a
AM
51 */
52 protected PinTmfViewAction fPinAction;
d2e4afa7 53 private static TimeAlignViewsAction fAlignViewsAction;
3ac5721a
AM
54
55 // ------------------------------------------------------------------------
56 // Constructor
57 // ------------------------------------------------------------------------
58
59 /**
60 * Constructor. Creates a TMF view and registers to the signal manager.
61 *
62 * @param viewName
63 * A view name
64 */
65 public TmfView(String viewName) {
66 super();
67 fName = viewName;
68 TmfSignalManager.register(this);
69 }
70
71 /**
72 * Disposes this view and de-registers itself from the signal manager
73 */
74 @Override
75 public void dispose() {
76 TmfSignalManager.deregister(this);
1cefda97
PT
77
78 /* Workaround for Bug 490400: Clear the action bars */
79 IActionBars bars = getViewSite().getActionBars();
80 bars.getToolBarManager().removeAll();
81 bars.getMenuManager().removeAll();
82
3ac5721a
AM
83 super.dispose();
84 }
85
86 // ------------------------------------------------------------------------
87 // ITmfComponent
88 // ------------------------------------------------------------------------
89
90 @Override
91 public String getName() {
92 return fName;
93 }
94
95 @Override
96 public void broadcast(TmfSignal signal) {
97 TmfSignalManager.dispatchSignal(signal);
98 }
8d2e2848 99
d91063d0
BH
100 @Override
101 public void broadcastAsync(TmfSignal signal) {
102 TmfSignalManager.dispatchSignalAsync(signal);
103 }
104
ea279a69
FC
105 // ------------------------------------------------------------------------
106 // View pinning support
107 // ------------------------------------------------------------------------
108
db59ddc2
BH
109 /**
110 * Returns whether the pin flag is set.
111 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
112 *
113 * @return pin flag
db59ddc2
BH
114 */
115 public boolean isPinned() {
116 return ((fPinAction != null) && (fPinAction.isChecked()));
117 }
118
119 /**
120 * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag.
121 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
db59ddc2
BH
122 */
123 protected void contributePinActionToToolBar() {
124 if (fPinAction == null) {
125 fPinAction = new PinTmfViewAction();
126
127 IToolBarManager toolBarManager = getViewSite().getActionBars()
128 .getToolBarManager();
129 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
130 toolBarManager.add(fPinAction);
131 }
132 }
d2e4afa7
MAL
133
134 @Override
135 public void createPartControl(final Composite parent) {
136 fParentComposite = parent;
137 if (this instanceof ITmfTimeAligned) {
138 contributeAlignViewsActionToToolbar();
139
140 fControlListener = new ControlAdapter() {
141 @Override
142 public void controlResized(ControlEvent e) {
143 TIME_ALIGNMENT_SYNCHRONIZER.handleViewResized(TmfView.this);
144 }
145 };
146 parent.addControlListener(fControlListener);
147
148 getSite().getPage().addPartListener(new IPartListener() {
149 @Override
150 public void partOpened(IWorkbenchPart part) {
151 // do nothing
152 }
153
154 @Override
155 public void partDeactivated(IWorkbenchPart part) {
156 // do nothing
157 }
158
159 @Override
160 public void partClosed(IWorkbenchPart part) {
161 if (part == TmfView.this && fControlListener != null && !fParentComposite.isDisposed()) {
162 fParentComposite.removeControlListener(fControlListener);
163 fControlListener = null;
164 getSite().getPage().removePartListener(this);
165 TIME_ALIGNMENT_SYNCHRONIZER.handleViewClosed(TmfView.this);
166 }
167 }
168
169 @Override
170 public void partBroughtToTop(IWorkbenchPart part) {
171 // do nothing
172 }
173
174 @Override
175 public void partActivated(IWorkbenchPart part) {
176 // do nothing
177 }
178 });
179 }
180 }
181
182 private void contributeAlignViewsActionToToolbar() {
183 if (fAlignViewsAction == null) {
184 fAlignViewsAction = new TimeAlignViewsAction();
185 }
186
187 IToolBarManager toolBarManager = getViewSite().getActionBars()
188 .getToolBarManager();
189 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
190 toolBarManager.add(fAlignViewsAction);
191 }
192
193 /**
194 * Returns the parent control of the view
195 *
196 * @return the parent control
197 *
198 * @since 1.0
199 */
200 public Composite getParentComposite() {
201 return fParentComposite;
202 }
013a5f1c 203}
This page took 0.122765 seconds and 5 git commands to generate.