| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2012 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 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.linuxtools.tmf.ui.views; |
| 15 | |
| 16 | import org.eclipse.jface.action.IToolBarManager; |
| 17 | import org.eclipse.jface.action.Separator; |
| 18 | import org.eclipse.linuxtools.tmf.core.component.ITmfComponent; |
| 19 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; |
| 20 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; |
| 21 | import org.eclipse.ui.IWorkbenchActionConstants; |
| 22 | import org.eclipse.ui.part.ViewPart; |
| 23 | |
| 24 | /** |
| 25 | * Basic abstract TMF view class implementation. |
| 26 | * |
| 27 | * It registers any sub class to the signal manager for receiving and sending |
| 28 | * TMF signals. |
| 29 | * |
| 30 | * @version 1.2 |
| 31 | * @author Francois Chouinard |
| 32 | */ |
| 33 | public abstract class TmfView extends ViewPart implements ITmfComponent { |
| 34 | |
| 35 | private final String fName; |
| 36 | /** |
| 37 | * Action class for pinning of TmfView. |
| 38 | * @since 2.0 |
| 39 | */ |
| 40 | protected PinTmfViewAction fPinAction; |
| 41 | |
| 42 | // ------------------------------------------------------------------------ |
| 43 | // Constructor |
| 44 | // ------------------------------------------------------------------------ |
| 45 | |
| 46 | /** |
| 47 | * Constructor. Creates a TMF view and registers to the signal manager. |
| 48 | * |
| 49 | * @param viewName A view name |
| 50 | */ |
| 51 | public TmfView(String viewName) { |
| 52 | super(); |
| 53 | fName = viewName; |
| 54 | TmfSignalManager.register(this); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Disposes this view and de-registers itself from the signal manager |
| 59 | * |
| 60 | * @see org.eclipse.ui.part.WorkbenchPart#dispose() |
| 61 | */ |
| 62 | @Override |
| 63 | public void dispose() { |
| 64 | TmfSignalManager.deregister(this); |
| 65 | super.dispose(); |
| 66 | } |
| 67 | |
| 68 | // ------------------------------------------------------------------------ |
| 69 | // ITmfComponent |
| 70 | // ------------------------------------------------------------------------ |
| 71 | |
| 72 | /* |
| 73 | * (non-Javadoc) |
| 74 | * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#getName() |
| 75 | */ |
| 76 | @Override |
| 77 | public String getName() { |
| 78 | return fName; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * (non-Javadoc) |
| 83 | * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#broadcast(org.eclipse.linuxtools.tmf.core.signal.TmfSignal) |
| 84 | */ |
| 85 | @Override |
| 86 | public void broadcast(TmfSignal signal) { |
| 87 | TmfSignalManager.dispatchSignal(signal); |
| 88 | } |
| 89 | |
| 90 | // ------------------------------------------------------------------------ |
| 91 | // View pinning support |
| 92 | // ------------------------------------------------------------------------ |
| 93 | |
| 94 | /** |
| 95 | * Returns whether the pin flag is set. |
| 96 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. |
| 97 | * |
| 98 | * @return pin flag |
| 99 | * @since 2.0 |
| 100 | */ |
| 101 | public boolean isPinned() { |
| 102 | return ((fPinAction != null) && (fPinAction.isChecked())); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag. |
| 107 | * For example, this flag can be used to ignore time synchronization signals from other TmfViews. |
| 108 | * |
| 109 | * @since 2.0 |
| 110 | */ |
| 111 | protected void contributePinActionToToolBar() { |
| 112 | if (fPinAction == null) { |
| 113 | fPinAction = new PinTmfViewAction(); |
| 114 | |
| 115 | IToolBarManager toolBarManager = getViewSite().getActionBars() |
| 116 | .getToolBarManager(); |
| 117 | toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
| 118 | toolBarManager.add(fPinAction); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | } |