tmf: Add standard import trace wizard to the file menu of the RCP
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Sun, 16 Feb 2014 18:05:26 +0000 (13:05 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Tue, 25 Feb 2014 18:56:15 +0000 (13:56 -0500)
Also simplify the selection handling for BatchImportTraceHandler

Change-Id: Ice7ec29c3b5d3a34c4c5960084a2062c593885df
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/22122
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
IP-Clean: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.linuxtools.tmf.ui/plugin.xml
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/BatchImportTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/ImportTraceHandler.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/ImportTraceWizard.java
org.eclipse.linuxtools.tracing.rcp.ui/plugin.properties
org.eclipse.linuxtools.tracing.rcp.ui/plugin.xml

index c2414129852d59836594c32c92c7c0358a306751..2e1fcc6138bb3386261835004cf4d0e9e0df6607 100644 (file)
                visible="true">
          </separator>
          <command
-               commandId="org.eclipse.ui.file.import"
+               commandId="org.eclipse.linuxtools.tmf.ui.import"
                label="%command.import"
                mnemonic="%command.import.mnemonic"
                style="push">
             id="org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.MoveSDRight"
             name="%commands.uml2sd.scrollright">
       </command>
+      <command
+            description="%command.import.description"
+            id="org.eclipse.linuxtools.tmf.ui.import"
+            name="%command.import">
+      </command>
       <command
             description="%command.batch_import.description"
             id="org.eclipse.linuxtools.tmf.ui.batch_import"
          point="org.eclipse.ui.handlers">
       <handler
             class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.ImportTraceHandler"
-            commandId="org.eclipse.ui.file.import">
-         <activeWhen>
-            <and>
-               <count
-                     value="1">
-               </count>
-               <iterate
-                     ifEmpty="false"
-                     operator="and">
-                  <instanceof
-                        value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
-                  </instanceof>
-               </iterate>
-            </and>
-         </activeWhen>
+            commandId="org.eclipse.linuxtools.tmf.ui.import">
       </handler>
       <handler
             class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.RefreshHandler"
index ee71777787b054750ae2c17dfb31c859de078ec9..30c11c8936f53cf76246d113d41073aab0003d34 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 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
@@ -8,18 +8,19 @@
  *
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
+ *   Bernd Hufmann - Simplify selection logic
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
 
+import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 import org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace.BatchImportTraceWizard;
-import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.HandlerUtil;
@@ -30,30 +31,27 @@ import org.eclipse.ui.handlers.HandlerUtil;
  * @author Matthew Khouzam
  * @since 2.0
  */
-public class BatchImportTraceHandler extends ImportTraceHandler {
+public class BatchImportTraceHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-        // Fire the Import Trace Wizard
-        IWorkbench workbench = PlatformUI.getWorkbench();
-        if (workbench == null) {
-            return null;
-        }
 
-        final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
-        if (activeWorkbenchWindow == null) {
-            return null;
+        BatchImportTraceWizard w = new BatchImportTraceWizard();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+        if (window == null) {
+            return false;
         }
 
-        IStructuredSelection selection = new StructuredSelection(HandlerUtil.getCurrentSelection(event));
-        TmfTraceFolder traceFolder = getTraceFolder();
-        if (traceFolder != null) {
-            selection = new StructuredSelection(traceFolder);
+        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+
+        IStructuredSelection sec = StructuredSelection.EMPTY;
+        if (currentSelection instanceof IStructuredSelection) {
+            sec = (IStructuredSelection) currentSelection;
         }
 
-        BatchImportTraceWizard wizard = new BatchImportTraceWizard();
-        wizard.init(PlatformUI.getWorkbench(), selection);
-        WizardDialog dialog = new WizardDialog(activeWorkbenchWindow.getShell(), wizard);
+        w.init(PlatformUI.getWorkbench(), sec);
+        WizardDialog dialog = new WizardDialog(window.getShell(), w);
         dialog.open();
 
         return null;
index bfa8bc50951599d8ea3783b683ad1b074b53db7c..6d49d0f26ecf85806fff109a4978633fec532edc 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2013 Ericsson
+ * Copyright (c) 2009, 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
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
+ *   Bernd Hufmann - Update selection handling
  *******************************************************************************/
 
 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
@@ -16,18 +17,13 @@ import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
 import org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
 
 /**
  * <b><u>ImportTraceHandler</u></b>
@@ -42,57 +38,27 @@ public class ImportTraceHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
+        ImportTraceWizard w = new ImportTraceWizard();
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
-        TmfTraceFolder traceFolder = getTraceFolder();
-        if (traceFolder == null) {
-            return null;
+        if (window == null) {
+            return false;
         }
-        // Fire the Import Trace Wizard
-        IWorkbench workbench = PlatformUI.getWorkbench();
-        Shell shell = workbench.getActiveWorkbenchWindow().getShell();
-
-        ImportTraceWizard wizard = new ImportTraceWizard();
-        wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder));
-        WizardDialog dialog = new WizardDialog(shell, wizard);
-        dialog.open();
 
-        traceFolder.refresh();
+        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
+        // Menu Selection is only not null for context-sensitive menu
+        ISelection menuSelection  = HandlerUtil.getActiveMenuSelection(event);
 
-        return null;
-    }
+        IStructuredSelection sec = StructuredSelection.EMPTY;
 
-    /**
-     * @return the trace folder or null
-     */
-    protected TmfTraceFolder getTraceFolder() {
-        // Check if we are closing down
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null) {
-            return null;
+        // Only use the selection if handler is called from context-sensitive menu
+        if ((menuSelection != null) && (currentSelection instanceof IStructuredSelection)) {
+            sec = (IStructuredSelection) currentSelection;
         }
 
-        // Get the selection
-        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-        IWorkbenchPart part = page.getActivePart();
-        if (part == null) {
-            return null;
-        }
-        ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
-        if (selectionProvider == null) {
-            return null;
-        }
-        ISelection selection = selectionProvider.getSelection();
-
-        TmfTraceFolder traceFolder = null;
-        if (selection instanceof TreeSelection) {
-            TreeSelection sel = (TreeSelection) selection;
-            // There should be only one item selected as per the plugin.xml
-            Object element = sel.getFirstElement();
-            if (element instanceof TmfTraceFolder) {
-                traceFolder = (TmfTraceFolder) element;
-            }
-        }
-        return traceFolder;
+        w.init(PlatformUI.getWorkbench(), sec);
+        WizardDialog dialog = new WizardDialog(window.getShell(), w);
+        dialog.open();
+        return null;
     }
-
 }
index b56a2dd6ef96aa3381727943bf22937e0c7945f5..d354f3cce0b2d05710e1b07e34960dfcdb9f0cc4 100644 (file)
 
 package org.eclipse.linuxtools.tmf.ui.project.wizards.importtrace;
 
-import java.util.List;
-
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.tmf.ui.project.wizards.Messages;
 import org.eclipse.ui.IImportWizard;
 import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
 /**
@@ -74,11 +70,6 @@ public class ImportTraceWizard extends Wizard implements IImportWizard {
         fWorkbench = workbench;
         fSelection = selection;
 
-        List<?> selectedResources = IDE.computeSelectedResources(selection);
-        if (!selectedResources.isEmpty()) {
-            fSelection = new StructuredSelection(selectedResources);
-        }
-
         setWindowTitle(Messages.ImportTraceWizard_DialogTitle);
         setDefaultPageImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH));
         setNeedsProgressMonitor(true);
index 7b1d46cd091da3649f371bedcd91fe50d73f239f..626a6eca9fd72dd0e288e3b3dee94ad8cb0bc5c1 100644 (file)
@@ -34,6 +34,7 @@ activity.description.search = (Unwanted) Search Perspective
 activity.name.search = Unwanted Search Perspective
 command.OpenFile.label = Open Trace File...
 command.OpenDirectory.label = Open Trace Directory...
+command.import = Import...
 command.batch_import = Batch Import...
 menu.mnemonic = F
 menu.label = Open
index f3fb0f743393f71a2bceac60972750b056395914..794f48f65ab81a5690e8ed9bd239205dc3a33bd2 100644 (file)
                   label="%command.OpenDirectory.label"
                   style="push">
             </command>
+            <separator
+                  name="OpenSeparator"
+                  visible="true">
+            </separator>
+            <command
+                  commandId="org.eclipse.linuxtools.tmf.ui.import"
+                  label="%command.import"
+                  style="push">
+            </command>
             <command
                   commandId="org.eclipse.linuxtools.tmf.ui.batch_import"
                   label="%command.batch_import"
                   style="push">
             </command>
             <separator
-                  name="OpenSeparator"
+                  name="ImportSeparator"
                   visible="true">
             </separator>
             <command
This page took 0.031476 seconds and 5 git commands to generate.