Add some debug output to TestRefreshTextTrace
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / TmfView.java
CommitLineData
b0d3496e 1/*******************************************************************************
d2e4afa7 2 * Copyright (c) 2009, 2015 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;
d2e4afa7 27import org.eclipse.ui.IPartListener;
db59ddc2 28import org.eclipse.ui.IWorkbenchActionConstants;
d2e4afa7 29import org.eclipse.ui.IWorkbenchPart;
b0d3496e
ASL
30import org.eclipse.ui.part.ViewPart;
31
32/**
2f2265e2 33 * Basic abstract TMF view class implementation.
db59ddc2 34 *
2f2265e2 35 * It registers any sub class to the signal manager for receiving and sending
db59ddc2
BH
36 * TMF signals.
37 *
2f2265e2 38 * @author Francois Chouinard
b0d3496e
ASL
39 */
40public abstract class TmfView extends ViewPart implements ITmfComponent {
41
3ac5721a 42 private final String fName;
d2e4afa7
MAL
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();
248af329 47
3ac5721a
AM
48 /**
49 * Action class for pinning of TmfView.
3ac5721a
AM
50 */
51 protected PinTmfViewAction fPinAction;
d2e4afa7 52 private static TimeAlignViewsAction fAlignViewsAction;
3ac5721a
AM
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 }
8d2e2848 92
d91063d0
BH
93 @Override
94 public void broadcastAsync(TmfSignal signal) {
95 TmfSignalManager.dispatchSignalAsync(signal);
96 }
97
ea279a69
FC
98 // ------------------------------------------------------------------------
99 // View pinning support
100 // ------------------------------------------------------------------------
101
db59ddc2
BH
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
db59ddc2
BH
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.
db59ddc2
BH
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 }
d2e4afa7
MAL
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 }
013a5f1c 196}
This page took 0.11072 seconds and 5 git commands to generate.