tmf: Introduce a central trace manager
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / TmfView.java
CommitLineData
b0d3496e 1/*******************************************************************************
11252342 2 * Copyright (c) 2009, 2013 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
14package org.eclipse.linuxtools.tmf.ui.views;
15
db59ddc2
BH
16import org.eclipse.jface.action.IToolBarManager;
17import org.eclipse.jface.action.Separator;
6c13869b
FC
18import org.eclipse.linuxtools.tmf.core.component.ITmfComponent;
19import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
20import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
3ac5721a
AM
21import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
22import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor;
23import org.eclipse.ui.IEditorPart;
db59ddc2 24import org.eclipse.ui.IWorkbenchActionConstants;
b0d3496e
ASL
25import org.eclipse.ui.part.ViewPart;
26
27/**
2f2265e2 28 * Basic abstract TMF view class implementation.
db59ddc2 29 *
2f2265e2 30 * It registers any sub class to the signal manager for receiving and sending
db59ddc2
BH
31 * TMF signals.
32 *
33 * @version 1.2
2f2265e2 34 * @author Francois Chouinard
b0d3496e
ASL
35 */
36public abstract class TmfView extends ViewPart implements ITmfComponent {
37
3ac5721a
AM
38 private final String fName;
39 /**
40 * Action class for pinning of TmfView.
41 *
42 * @since 2.0
43 */
44 protected PinTmfViewAction fPinAction;
45
46 // ------------------------------------------------------------------------
47 // Constructor
48 // ------------------------------------------------------------------------
49
50 /**
51 * Constructor. Creates a TMF view and registers to the signal manager.
52 *
53 * @param viewName
54 * A view name
55 */
56 public TmfView(String viewName) {
57 super();
58 fName = viewName;
59 TmfSignalManager.register(this);
60 }
61
62 /**
63 * Disposes this view and de-registers itself from the signal manager
64 */
65 @Override
66 public void dispose() {
67 TmfSignalManager.deregister(this);
68 super.dispose();
69 }
70
71 // ------------------------------------------------------------------------
72 // ITmfComponent
73 // ------------------------------------------------------------------------
74
75 @Override
76 public String getName() {
77 return fName;
78 }
79
80 @Override
81 public void broadcast(TmfSignal signal) {
82 TmfSignalManager.dispatchSignal(signal);
83 }
8d2e2848 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
9da25000 94 * @since 2.0
db59ddc2
BH
95 */
96 public boolean isPinned() {
97 return ((fPinAction != null) && (fPinAction.isChecked()));
98 }
99
100 /**
101 * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag.
102 * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
103 *
9da25000 104 * @since 2.0
db59ddc2
BH
105 */
106 protected void contributePinActionToToolBar() {
107 if (fPinAction == null) {
108 fPinAction = new PinTmfViewAction();
109
110 IToolBarManager toolBarManager = getViewSite().getActionBars()
111 .getToolBarManager();
112 toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
113 toolBarManager.add(fPinAction);
114 }
115 }
ea279a69 116
3ac5721a
AM
117 /**
118 * Get the currently selected trace, or 'null' if the active editor is not a
119 * TMF trace.
120 *
121 * @return The active trace, or 'null' if not a trace
122 * @since 2.0
123 */
124 public ITmfTrace getActiveTrace() {
125 IEditorPart editor = getSite().getPage().getActiveEditor();
126 if (editor instanceof ITmfTraceEditor) {
127 ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
128 return trace;
129 }
130 return null;
131 }
132
013a5f1c 133}
This page took 0.046675 seconds and 5 git commands to generate.