Introduce "New view" action for views based on TmfView
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / TmfView.java
index f073027a660d920c80f6719f583ae03340f26124..9c4b451f6d77664408e8f67f1a194d094daaf18f 100644 (file)
@@ -14,6 +14,9 @@
 
 package org.eclipse.tracecompass.tmf.ui.views;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.swt.events.ControlAdapter;
@@ -51,8 +54,22 @@ public abstract class TmfView extends ViewPart implements ITmfComponent {
      * Action class for pinning of TmfView.
      */
     protected PinTmfViewAction fPinAction;
+
+    /**
+     * Action class for spawning a new view based on this view type.
+     *
+     * @since 2.2
+     */
+    private NewTmfViewAction fNewAction;
+
     private static TimeAlignViewsAction fAlignViewsAction;
 
+    /**
+     * The separator used for distinguishing between primary and secondary id of a view id.
+     * @since 2.2
+     */
+    public static final String PRIMARY_SECONDARY_ID_SEPARATOR = ":"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
@@ -132,9 +149,35 @@ public abstract class TmfView extends ViewPart implements ITmfComponent {
         }
     }
 
+    /**
+     * Add the "New view" action to the expandable menu. This action spawn a new
+     * view of the same type as the caller.
+     *
+     * @since 2.2
+     */
+    private void contributeNewActionToMenu(IMenuManager menuManager) {
+        if (fNewAction == null) {
+            fNewAction = new NewTmfViewAction(TmfView.this) {
+                @Override
+                public void run() {
+                    TmfViewFactory.newView(checkNotNull(TmfView.this.getViewId()), true);
+                }
+            };
+            menuManager.add(fNewAction);
+        }
+    }
+
     @Override
     public void createPartControl(final Composite parent) {
         fParentComposite = parent;
+        IMenuManager menuManager = getViewSite().getActionBars()
+                .getMenuManager();
+
+        /* Add to menu */
+        contributeNewActionToMenu(menuManager);
+        menuManager.add(new Separator());
+
+
         if (this instanceof ITmfTimeAligned) {
             contributeAlignViewsActionToToolbar();
 
@@ -215,6 +258,6 @@ public abstract class TmfView extends ViewPart implements ITmfComponent {
         if (secondaryId == null) {
             return viewSite.getId();
         }
-        return viewSite.getId() + ':' + secondaryId;
+        return viewSite.getId() + PRIMARY_SECONDARY_ID_SEPARATOR + secondaryId;
     }
 }
This page took 0.024432 seconds and 5 git commands to generate.