Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Torregrosa Paez2016-06-01 09:26:22 +0000
committerPablo Torregrosa Paez2016-06-01 09:26:22 +0000
commitde7b4d6b1f0ed0eea32f60d1162c080fdceada24 (patch)
tree3c2a4350919361a2bf067e08bf89331caa922361 /target_explorer/plugins/org.eclipse.tcf.te.tcf.ui
parentedf6ab5944916d079e013c0c3dc18f43265a265b (diff)
downloadorg.eclipse.tcf-de7b4d6b1f0ed0eea32f60d1162c080fdceada24.tar.gz
org.eclipse.tcf-de7b4d6b1f0ed0eea32f60d1162c080fdceada24.tar.xz
org.eclipse.tcf-de7b4d6b1f0ed0eea32f60d1162c080fdceada24.zip
Target Explorer: A connection can only be renamed when disconnected.
Change-Id: Ia1d997e87f6f907f5990028d1c9474ba59476406 Signed-off-by: Pablo Torregrosa Paez <pablo.torregrosa@windriver.com>
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.ui')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/PropertyTester.java10
3 files changed, 52 insertions, 10 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
index e7e21b421..0ca5b7ecb 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml
@@ -68,7 +68,7 @@
class="org.eclipse.tcf.te.tcf.ui.internal.PropertyTester"
id="org.eclipse.tcf.te.tcf.ui.propertyTester"
namespace="org.eclipse.tcf.te.tcf.ui"
- properties="canDelete"
+ properties="canDelete,canRename"
type="org.eclipse.jface.viewers.ISelection">
</propertyTester>
<propertyTester
@@ -82,7 +82,7 @@
class="org.eclipse.tcf.te.tcf.ui.internal.PropertyTester"
id="org.eclipse.tcf.te.tcf.ui.propertyTester.simulator"
namespace="org.eclipse.tcf.te.tcf.ui"
- properties="isValidSimulatorConfig,canDelete,hasHistory"
+ properties="isValidSimulatorConfig,canDelete,hasHistory,canRename"
type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode">
</propertyTester>
</extension>
@@ -935,10 +935,7 @@
</activeWhen>
<enabledWhen>
<with variable="selection">
- <count value="1"/>
- <iterate operator="and" ifEmpty="false">
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/>
- </iterate>
+ <test property="org.eclipse.tcf.te.tcf.ui.canRename" value="true"/>
</with>
</enabledWhen>
</handler>
@@ -1077,7 +1074,7 @@
</activeWhen>
<enabledWhen>
<with variable="defaultContextSelection">
- <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/>
+ <test property="org.eclipse.tcf.te.tcf.ui.canRename" value="true"/>
</with>
</enabledWhen>
</handler>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java
index d5748a18e..5ab971a81 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java
@@ -25,11 +25,15 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
+import org.eclipse.tcf.te.core.interfaces.IConnectable;
import org.eclipse.tcf.te.runtime.callback.Callback;
import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
@@ -271,4 +275,41 @@ public class RenameHandler extends AbstractHandler {
return new RenameDialog(shell, null, title, prompt, usedError, formatError, label, name.get(), "[0-9a-zA-Z. _()-]+", usedNames.toArray(new String[usedNames.size()]), null); //$NON-NLS-1$
}
+ /**
+ * Tests if this rename handler can rename the elements of the given
+ * <code>selection</code>.
+ *
+ * @param selection The selection. Must not be <code>null</code>.
+ * @return <code>True</code> if the selection can be renamed by this handler, <code>false</code> otherwise.
+ */
+ public boolean canRename(ISelection selection) {
+ Assert.isNotNull(selection);
+
+ boolean canRename = false;
+
+ if (!(selection instanceof ITreeSelection) && selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Iterator<?> it = ((IStructuredSelection)selection).iterator();
+ List<TreePath> treePathes = new ArrayList<TreePath>();
+ 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, must not be empty, and only a single element must be selected
+ if (selection instanceof ITreeSelection && !selection.isEmpty() && ((ITreeSelection)selection).size() == 1) {
+ TreePath treePath = ((ITreeSelection)selection).getPaths()[0];
+ // Get the element
+ Object element = treePath.getLastSegment();
+ // This handler will take care of peer model nodes only
+ if (element instanceof IPeerNode) {
+ IPeerNode node = (IPeerNode) element;
+ // It can be renamed only when not connected
+ canRename = IConnectable.STATE_DISCONNECTED == node.getConnectState();
+ }
+ }
+
+ return canRename;
+ }
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/PropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/PropertyTester.java
index 6a258b209..72a4a7c2b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/PropertyTester.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/internal/PropertyTester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011, 2016 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -25,6 +25,7 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.IDefaultContextService
import org.eclipse.tcf.te.tcf.locator.model.ModelManager;
import org.eclipse.tcf.te.tcf.locator.utils.SimulatorUtils;
import org.eclipse.tcf.te.tcf.ui.handler.DeleteHandler;
+import org.eclipse.tcf.te.tcf.ui.handler.RenameHandler;
import org.eclipse.tcf.te.tcf.ui.interfaces.IDefaultContextToolbarDelegate;
import org.eclipse.tcf.te.ui.views.navigator.nodes.NewWizardNode;
@@ -34,8 +35,9 @@ import org.eclipse.tcf.te.ui.views.navigator.nodes.NewWizardNode;
* Property tester implementation.
*/
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
- // Reference to the peer model delete handler (to determine "canDelete")
+ // References to the peer model delete/rename handlers (to determine "canDelete" and "canRename")
private final DeleteHandler deleteHandler = new DeleteHandler();
+ private final RenameHandler renameHandler = new RenameHandler();
/* (non-Javadoc)
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
@@ -47,7 +49,7 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester
return testSelection((IStructuredSelection)receiver, property, args, expectedValue);
}
- if ("canDelete".equals(property)) { //$NON-NLS-1$
+ if ("canDelete".equals(property) || "canRename".equals(property)) { //$NON-NLS-1$ //$NON-NLS-2$
return testSelection(new StructuredSelection(receiver), property, args, expectedValue);
}
@@ -107,6 +109,8 @@ public class PropertyTester extends org.eclipse.core.expressions.PropertyTester
if ("canDelete".equals(property)) { //$NON-NLS-1$
return deleteHandler.canDelete(selection);
+ } else if ("canRename".equals(property)) { //$NON-NLS-1$
+ return renameHandler.canRename(selection);
}
return false;

Back to the top