tmf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / TmfView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 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 * Marc-Andre Laperle - Support for view alignment
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.ui.views;
16
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.jface.action.Separator;
19 import org.eclipse.swt.events.ControlAdapter;
20 import org.eclipse.swt.events.ControlEvent;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.tracecompass.internal.tmf.ui.views.TimeAlignViewsAction;
23 import org.eclipse.tracecompass.internal.tmf.ui.views.TmfAlignmentSynchronizer;
24 import org.eclipse.tracecompass.tmf.core.component.ITmfComponent;
25 import org.eclipse.tracecompass.tmf.core.signal.TmfSignal;
26 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
27 import org.eclipse.ui.IPartListener;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.eclipse.ui.IWorkbenchPart;
30 import org.eclipse.ui.part.ViewPart;
31
32 /**
33 * Basic abstract TMF view class implementation.
34 *
35 * It registers any sub class to the signal manager for receiving and sending
36 * TMF signals.
37 *
38 * @author Francois Chouinard
39 */
40 public abstract class TmfView extends ViewPart implements ITmfComponent {
41
42 private final String fName;
43 /** This allows us to keep track of the view sizes */
44 private Composite fParentComposite;
45 private ControlAdapter fControlListener;
46 private static final TmfAlignmentSynchronizer TIME_ALIGNMENT_SYNCHRONIZER = new TmfAlignmentSynchronizer();
47
48 /**
49 * Action class for pinning of TmfView.
50 */
51 protected PinTmfViewAction fPinAction;
52 private static TimeAlignViewsAction fAlignViewsAction;
53
54 // ------------------------------------------------------------------------
55 // Constructor
56 // ------------------------------------------------------------------------
57
58 /**
59 * Constructor. Creates a TMF view and registers to the signal manager.
60 *
61 * @param viewName
62 * A view name
63 */
64 public TmfView(String viewName) {
65 super();
66 fName = viewName;
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 @Override
94 public void broadcastAsync(TmfSignal signal) {
95 TmfSignalManager.dispatchSignalAsync(signal);
96 }
97
98 // ------------------------------------------------------------------------
99 // View pinning support
100 // ------------------------------------------------------------------------
101
102 /**
103 * Returns whether the pin flag is set.
104 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
105 *
106 * @return pin flag
107 */
108 public boolean isPinned() {
109 return ((fPinAction != null) && (fPinAction.isChecked()));
110 }
111
112 /**
113 * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag.
114 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
115 */
116 protected void contributePinActionToToolBar() {
117 if (fPinAction == null) {
118 fPinAction = new PinTmfViewAction();
119
120 IToolBarManager toolBarManager = getViewSite().getActionBars()
121 .getToolBarManager();
122 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
123 toolBarManager.add(fPinAction);
124 }
125 }
126
127 @Override
128 public void createPartControl(final Composite parent) {
129 fParentComposite = parent;
130 if (this instanceof ITmfTimeAligned) {
131 contributeAlignViewsActionToToolbar();
132
133 fControlListener = new ControlAdapter() {
134 @Override
135 public void controlResized(ControlEvent e) {
136 TIME_ALIGNMENT_SYNCHRONIZER.handleViewResized(TmfView.this);
137 }
138 };
139 parent.addControlListener(fControlListener);
140
141 getSite().getPage().addPartListener(new IPartListener() {
142 @Override
143 public void partOpened(IWorkbenchPart part) {
144 // do nothing
145 }
146
147 @Override
148 public void partDeactivated(IWorkbenchPart part) {
149 // do nothing
150 }
151
152 @Override
153 public void partClosed(IWorkbenchPart part) {
154 if (part == TmfView.this && fControlListener != null && !fParentComposite.isDisposed()) {
155 fParentComposite.removeControlListener(fControlListener);
156 fControlListener = null;
157 getSite().getPage().removePartListener(this);
158 TIME_ALIGNMENT_SYNCHRONIZER.handleViewClosed(TmfView.this);
159 }
160 }
161
162 @Override
163 public void partBroughtToTop(IWorkbenchPart part) {
164 // do nothing
165 }
166
167 @Override
168 public void partActivated(IWorkbenchPart part) {
169 // do nothing
170 }
171 });
172 }
173 }
174
175 private void contributeAlignViewsActionToToolbar() {
176 if (fAlignViewsAction == null) {
177 fAlignViewsAction = new TimeAlignViewsAction();
178 }
179
180 IToolBarManager toolBarManager = getViewSite().getActionBars()
181 .getToolBarManager();
182 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
183 toolBarManager.add(fAlignViewsAction);
184 }
185
186 /**
187 * Returns the parent control of the view
188 *
189 * @return the parent control
190 *
191 * @since 1.0
192 */
193 public Composite getParentComposite() {
194 return fParentComposite;
195 }
196 }
This page took 0.034912 seconds and 6 git commands to generate.