From 2e7cb57c2e295a0fb8cf301bb2200c1f567c7683 Mon Sep 17 00:00:00 2001 From: Tobias Schwarz Date: Wed, 20 Nov 2013 13:52:57 +0100 Subject: Target Explorer: rework handler activity and enablement --- .../tcf/te/tcf/ui/handler/DeleteHandler.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src') diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java index a2935d75c..2c451a72f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java @@ -11,6 +11,7 @@ package org.eclipse.tcf.te.tcf.ui.handler; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -24,9 +25,11 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.tcf.protocol.Protocol; @@ -99,6 +102,16 @@ public class DeleteHandler extends AbstractHandler { boolean canDelete = false; + if (!(selection instanceof ITreeSelection) && selection instanceof IStructuredSelection && !selection.isEmpty()) { + Iterator it = ((IStructuredSelection)selection).iterator(); + List treePathes = new ArrayList(); + while (it.hasNext()) { + Object sel = it.next(); + treePathes.add(new TreePath(new Object[]{sel})); + } + selection = new TreeSelection(treePathes.toArray(new TreePath[treePathes.size()])); + } + // The selection must be a tree selection and must not be empty if (selection instanceof ITreeSelection && !selection.isEmpty()) { // Assume the selection to be deletable @@ -294,7 +307,7 @@ public class DeleteHandler extends AbstractHandler { * @param selection The selection. Must not be null. * @param callback The callback. Must not be null. */ - public void delete(final ISelection selection, final ICallback callback) { + public void delete(ISelection selection, final ICallback callback) { Assert.isNotNull(selection); Assert.isNotNull(callback); @@ -302,6 +315,16 @@ public class DeleteHandler extends AbstractHandler { // from an asynchronous callback, set this flag to false. boolean invokeCallback = true; + if (!(selection instanceof ITreeSelection) && selection instanceof IStructuredSelection && !selection.isEmpty()) { + Iterator it = ((IStructuredSelection)selection).iterator(); + List treePathes = new ArrayList(); + while (it.hasNext()) { + Object sel = it.next(); + treePathes.add(new TreePath(new Object[]{sel})); + } + selection = new TreeSelection(treePathes.toArray(new TreePath[treePathes.size()])); + } + // The selection must be a tree selection and must not be empty if (selection instanceof ITreeSelection && !selection.isEmpty()) { // Determine the operations to perform for each of the selected elements -- cgit v1.2.3