From: Patrick Tasse Date: Fri, 3 Oct 2014 20:23:43 +0000 (-0400) Subject: tmf: Fix copy trace handler enabled in unrelated dialogs X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=35a15531a032c0bca2cc956bc97a319e5496fb66;p=deliverable%2Ftracecompass.git tmf: Fix copy trace handler enabled in unrelated dialogs Ctrl-C no longer opens the Copy Trace dialog from another dialog when the current selection in the Project Explorer is a trace element. The same fix is applied to the copy experiment handler. Change-Id: I4eb9df578d2227b74312d7fe660b2a3caf2b2627 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/34415 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index b1cd6838c1..f336ed28a2 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -458,25 +458,7 @@ mnemonic="%command.copy.mnemonic" style="push"> - - - - - - - - - - - - + checkEnabled="true"> + + + + @@ -1267,6 +1255,12 @@ + + + + @@ -1276,6 +1270,12 @@ commandId="org.eclipse.ui.edit.copy"> + + + + diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyExperimentHandler.java index 4b23853bee..507011c876 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyExperimentHandler.java @@ -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 + * Patrick Tasse - Remove enable check *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; @@ -16,64 +17,18 @@ 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.TreeSelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyExperimentDialog; import org.eclipse.swt.widgets.Shell; -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; /** * CopyExperimentHandler *

- * TODO: Implement me. Please. */ public class CopyExperimentHandler extends AbstractHandler { - private TmfExperimentElement fExperiment = null; - - // ------------------------------------------------------------------------ - // isEnabled - // ------------------------------------------------------------------------ - - @Override - public boolean isEnabled() { - - // Check if we are closing down - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return false; - } - - // Get the selection - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPart part = page.getActivePart(); - if (part == null) { - return false; - } - ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); - if (selectionProvider == null) { - return false; - } - ISelection selection = selectionProvider.getSelection(); - - // Make sure there is only selection and that it is an experiment - fExperiment = 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 TmfExperimentElement) { - fExperiment = (TmfExperimentElement) element; - } - } - - return (fExperiment != null); - } - // ------------------------------------------------------------------------ // Execution // ------------------------------------------------------------------------ @@ -81,15 +36,16 @@ public class CopyExperimentHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - // Check if we are closing down - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { + // Get selection already validated by handler in plugin.xml + ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); + if (!(selection instanceof IStructuredSelection)) { return null; } + TmfExperimentElement experiment = (TmfExperimentElement) ((IStructuredSelection) selection).getFirstElement(); // Fire the Copy Experiment dialog - Shell shell = window.getShell(); - CopyExperimentDialog dialog = new CopyExperimentDialog(shell, fExperiment); + Shell shell = HandlerUtil.getActiveShellChecked(event); + CopyExperimentDialog dialog = new CopyExperimentDialog(shell, experiment); dialog.open(); return null; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyTraceHandler.java index 61496dfd5e..91d83be589 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/CopyTraceHandler.java @@ -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 @@ -8,6 +8,7 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Patrick Tasse - Remove enable check *******************************************************************************/ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; @@ -16,16 +17,11 @@ 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.TreeSelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyTraceDialog; import org.eclipse.swt.widgets.Shell; -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; /** * CopyTraceHandler @@ -33,48 +29,6 @@ import org.eclipse.ui.PlatformUI; */ public class CopyTraceHandler extends AbstractHandler { - private TmfTraceElement fTrace = null; - - // ------------------------------------------------------------------------ - // Validation - // ------------------------------------------------------------------------ - - @Override - public boolean isEnabled() { - - // Check if we are closing down - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return false; - } - - // Get the selection - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPart part = page.getActivePart(); - if (part == null) { - return false; - } - ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); - if (selectionProvider == null) { - return false; - } - ISelection selection = selectionProvider.getSelection(); - - // Make sure a trace is selected - fTrace = 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 TmfTraceElement) { - fTrace = (TmfTraceElement) element; - } - } - - // We only enable opening from the Traces folder for now - return (fTrace != null && fTrace.getParent() instanceof TmfTraceFolder); - } - // ------------------------------------------------------------------------ // Execution // ------------------------------------------------------------------------ @@ -82,15 +36,16 @@ public class CopyTraceHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - // Check if we are closing down - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { + // Get selection already validated by handler in plugin.xml + ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); + if (!(selection instanceof IStructuredSelection)) { return null; } + TmfTraceElement trace = (TmfTraceElement) ((IStructuredSelection) selection).getFirstElement(); - // Fire the Copy Experiment dialog - Shell shell = window.getShell(); - CopyTraceDialog dialog = new CopyTraceDialog(shell, fTrace); + // Fire the Copy Trace dialog + Shell shell = HandlerUtil.getActiveShellChecked(event); + CopyTraceDialog dialog = new CopyTraceDialog(shell, trace); dialog.open(); return null;