1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Added possibility to pin view
12 * Marc-Andre Laperle - Support for view alignment
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ui
.views
;
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
;
33 * Basic abstract TMF view class implementation.
35 * It registers any sub class to the signal manager for receiving and sending
38 * @author Francois Chouinard
40 public abstract class TmfView
extends ViewPart
implements ITmfComponent
{
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();
49 * Action class for pinning of TmfView.
51 protected PinTmfViewAction fPinAction
;
52 private static TimeAlignViewsAction fAlignViewsAction
;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 * Constructor. Creates a TMF view and registers to the signal manager.
64 public TmfView(String viewName
) {
67 TmfSignalManager
.register(this);
71 * Disposes this view and de-registers itself from the signal manager
74 public void dispose() {
75 TmfSignalManager
.deregister(this);
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
84 public String
getName() {
89 public void broadcast(TmfSignal signal
) {
90 TmfSignalManager
.dispatchSignal(signal
);
94 public void broadcastAsync(TmfSignal signal
) {
95 TmfSignalManager
.dispatchSignalAsync(signal
);
98 // ------------------------------------------------------------------------
99 // View pinning support
100 // ------------------------------------------------------------------------
103 * Returns whether the pin flag is set.
104 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
108 public boolean isPinned() {
109 return ((fPinAction
!= null) && (fPinAction
.isChecked()));
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.
116 protected void contributePinActionToToolBar() {
117 if (fPinAction
== null) {
118 fPinAction
= new PinTmfViewAction();
120 IToolBarManager toolBarManager
= getViewSite().getActionBars()
121 .getToolBarManager();
122 toolBarManager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
123 toolBarManager
.add(fPinAction
);
128 public void createPartControl(final Composite parent
) {
129 fParentComposite
= parent
;
130 if (this instanceof ITmfTimeAligned
) {
131 contributeAlignViewsActionToToolbar();
133 fControlListener
= new ControlAdapter() {
135 public void controlResized(ControlEvent e
) {
136 TIME_ALIGNMENT_SYNCHRONIZER
.handleViewResized(TmfView
.this);
139 parent
.addControlListener(fControlListener
);
141 getSite().getPage().addPartListener(new IPartListener() {
143 public void partOpened(IWorkbenchPart part
) {
148 public void partDeactivated(IWorkbenchPart part
) {
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);
163 public void partBroughtToTop(IWorkbenchPart part
) {
168 public void partActivated(IWorkbenchPart part
) {
175 private void contributeAlignViewsActionToToolbar() {
176 if (fAlignViewsAction
== null) {
177 fAlignViewsAction
= new TimeAlignViewsAction();
180 IToolBarManager toolBarManager
= getViewSite().getActionBars()
181 .getToolBarManager();
182 toolBarManager
.add(new Separator(IWorkbenchActionConstants
.MB_ADDITIONS
));
183 toolBarManager
.add(fAlignViewsAction
);
187 * Returns the parent control of the view
189 * @return the parent control
193 public Composite
getParentComposite() {
194 return fParentComposite
;