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"
/*******************************************************************************
- * 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
*
* 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;
* @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;
/*******************************************************************************
- * 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
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Bernd Hufmann - Update selection handling
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
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>
@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;
}
-
}
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;
/**
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);
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
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