tmf: Add Open With menu for trace elements in project explorer
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 26 Mar 2014 14:43:43 +0000 (10:43 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 3 Apr 2014 16:50:14 +0000 (12:50 -0400)
The menu item is only available when the trace resource is a file.

Change-Id: I6951764fe5e357467020938c3f3802621e591aef
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/23926
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki
org.eclipse.linuxtools.tmf.ui/plugin.xml
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/TmfActionProvider.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties

index cba2215506d2284da96c3315f57d7ad1e1d84c16..9030621644c3017fc7e10e2d58d95a5a36ecbce1 100644 (file)
@@ -483,7 +483,9 @@ A trace or experiment can be open by double-clicking the left mouse button on th
 
 [[Image:images/OpenTraceAction.png]]
 
-When opening a trace or experiment all currently open view will be filled which are defined for the corresponding trace type. Additionally, an internal index will be created for fast navigation within a trace. For LTTng 2.0 kernel traces a persistent state history will also be build. This state history will be used in different views to display kernel state information.
+When opening a trace or experiment all currently opened views will be filled which are defined for the corresponding trace type. Additionally, an internal index will be created for fast navigation within a trace. For LTTng 2.0 kernel traces a persistent state history will also be build. This state history will be used in different views to display kernel state information.
+
+If a trace resource is a file (and not a directory), then the '''Open With''' menu item is available in the context-sensitive menu and can be used to open the trace source file with any applicable internal or external editor. In that case the trace will not be processed by the tracing application.
 
 === Drag and Drop ===
 
index 119166af6e5635a5174f83c56ad8f2ace23afe04..dee7f748024217500c1bdeb51c690e33bfa56c05 100644 (file)
    <extension
          point="org.eclipse.ui.menus">
       <menuContribution
-            locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+            allPopups="false"
+            locationURI="popup:org.eclipse.ui.popup.any?after=group.open">
          <command
                commandId="org.eclipse.linuxtools.tmf.ui.openFile"
                label="%command.OpenFile.label"
                </with>
             </visibleWhen>
          </command>
+         <command
+               commandId="org.eclipse.ui.navigate.openResource"
+               disabledIcon="/icons/dlcl16/open.gif"
+               icon="/icons/elcl16/open.gif"
+               label="%command.open"
+               mnemonic="%command.open.mnemonic"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="selection">
+                  <count
+                        value="1">
+                  </count>
+                  <iterate
+                        ifEmpty="false"
+                        operator="and">
+                     <or>
+                        <instanceof
+                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+                        </instanceof>
+                        <instanceof
+                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+                        </instanceof>
+                        <instanceof
+                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfAnalysisOutputElement">
+                        </instanceof>
+                     </or>
+                  </iterate>
+               </with>
+            </visibleWhen>
+         </command>
+      </menuContribution>
+      <menuContribution
+            locationURI="popup:org.eclipse.ui.popup.any?after=additions">
          <separator
                name="org.eclipse.linuxtools.tmf.ui.separator1"
                visible="true">
                name="org.eclipse.linuxtools.tmf.ui.separator0"
                visible="true">
          </separator>
-         <command
-               commandId="org.eclipse.ui.navigate.openResource"
-               disabledIcon="/icons/dlcl16/open.gif"
-               icon="/icons/elcl16/open.gif"
-               label="%command.open"
-               mnemonic="%command.open.mnemonic"
-               style="push">
-            <visibleWhen
-                  checkEnabled="false">
-               <with
-                     variable="selection">
-                  <count
-                        value="1">
-                  </count>
-                  <iterate
-                        ifEmpty="false"
-                        operator="and">
-                     <or>
-                        <instanceof
-                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
-                        </instanceof>
-                        <instanceof
-                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
-                        </instanceof>
-                        <instanceof
-                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfAnalysisOutputElement">
-                        </instanceof>
-                     </or>
-                  </iterate>
-               </with>
-            </visibleWhen>
-         </command>
          <command
                commandId="org.eclipse.ui.edit.copy"
                disabledIcon="icons/dtool16/copy_edit.gif"
index 50dd428bf52a71f21ed63d1346a4e90a6fd38b97..bb7a33c349c1cb7c518f350ac90210b75c4fac7b 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson
+ * Copyright (c) 2011, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -52,6 +52,8 @@ public class Messages extends NLS {
 
     public static String AnalysisModule_Help;
 
+    public static String TmfActionProvider_OpenWith;
+
     static {
         // initialize resource bundle
         NLS.initializeMessages(BUNDLE_NAME, Messages.class);
index 62ca4dcfeac2d28851e7eefe150a55734887f217..23bd5441a243c3e2fb84dbbbed392fdd8b88d163 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
-* Copyright (c) 2012, 2013 Ericsson
+* Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
 import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.OpenWithMenu;
 import org.eclipse.ui.navigator.CommonActionProvider;
 import org.eclipse.ui.navigator.ICommonActionConstants;
 import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
 import org.eclipse.ui.navigator.ICommonViewerSite;
 import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
 
@@ -31,6 +40,8 @@ public class TmfActionProvider extends CommonActionProvider {
     private DeleteAction deleteAction;
     private RefreshAction refreshAction;
 
+    private IWorkbenchPage page;
+
     /**
      * Default constructor
      */
@@ -42,9 +53,26 @@ public class TmfActionProvider extends CommonActionProvider {
         ICommonViewerSite viewSite = aSite.getViewSite();
         if (viewSite instanceof ICommonViewerWorkbenchSite) {
             ICommonViewerWorkbenchSite workbenchSite = (ICommonViewerWorkbenchSite) viewSite;
-            openAction = new OpenAction(workbenchSite.getPage(), workbenchSite.getSelectionProvider());
-            deleteAction = new DeleteAction(workbenchSite.getPage(), workbenchSite.getSelectionProvider());
-            refreshAction = new RefreshAction(workbenchSite.getPage(), workbenchSite.getSelectionProvider());
+            page = workbenchSite.getPage();
+            openAction = new OpenAction(page, workbenchSite.getSelectionProvider());
+            deleteAction = new DeleteAction(page, workbenchSite.getSelectionProvider());
+            refreshAction = new RefreshAction(page, workbenchSite.getSelectionProvider());
+        }
+    }
+
+    @Override
+    public void fillContextMenu(IMenuManager menu) {
+        ISelection selection = getContext().getSelection();
+        if (selection instanceof IStructuredSelection) {
+            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+            if (structuredSelection.size() == 1 && structuredSelection.getFirstElement() instanceof TmfTraceElement) {
+                TmfTraceElement traceElement = (TmfTraceElement) structuredSelection.getFirstElement();
+                if (traceElement.getResource() instanceof IFile) {
+                    MenuManager openWithMenu = new MenuManager(Messages.TmfActionProvider_OpenWith);
+                    openWithMenu.add(new OpenWithMenu(page, traceElement.getResource()));
+                    menu.insertAfter(ICommonMenuConstants.GROUP_OPEN_WITH, openWithMenu);
+                }
+            }
         }
     }
 
index a284e5fbfaad012d835e692fe122321cb014e6cf..a93375c6349fb7379fb72e9d1981ce138b682093 100644 (file)
@@ -41,3 +41,6 @@ SynchronizeTracesHandler_ErrorSynchingForTrace=Error synchronizing experiment %s
 
 # Analysis modules
 AnalysisModule_Help=Help
+
+# TMF Action Provider
+TmfActionProvider_OpenWith=Open With
\ No newline at end of file
This page took 0.036414 seconds and 5 git commands to generate.