Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-07-19 04:09:52 -0400
committerUwe Stieber2012-07-19 04:09:52 -0400
commit682cb4e102e333804c94fe2e943e672f4af4cc86 (patch)
tree26790ed8030b2d28cc55837b2cd54d9e9d760ac7
parentc5891d5c69b722e0612cbe074929483228061d23 (diff)
downloadorg.eclipse.tcf-682cb4e102e333804c94fe2e943e672f4af4cc86.tar.gz
org.eclipse.tcf-682cb4e102e333804c94fe2e943e672f4af4cc86.tar.xz
org.eclipse.tcf-682cb4e102e333804c94fe2e943e672f4af4cc86.zip
Target Explorer: Added Rename action for static peers
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RenameFilesHandler.java276
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/icons/elcl16/rename.gifbin0 -> 612 bytes
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.xml54
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java253
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/RenameDialog.java9
9 files changed, 469 insertions, 145 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RenameFilesHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RenameFilesHandler.java
index 6cc6cd181..69b7c52e5 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RenameFilesHandler.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.filesystem.ui/src/org/eclipse/tcf/te/tcf/filesystem/ui/internal/handlers/RenameFilesHandler.java
@@ -1,138 +1,138 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.JobExecutor;
-import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpRename;
-import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
-import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
-import org.eclipse.tcf.te.tcf.filesystem.ui.internal.celleditor.FSCellValidator;
-import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
-import org.eclipse.tcf.te.ui.dialogs.RenameDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * The handler that renames the selected file or folder.
- */
-public class RenameFilesHandler extends AbstractHandler {
- // The currently focused viewer.
- private static TreeViewer currentViewer;
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IStructuredSelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
- if (!sel.isEmpty()) {
- FSTreeNode node = (FSTreeNode) sel.getFirstElement();
- boolean inPlaceEditor = UIPlugin.isInPlaceEditor();
- if (inPlaceEditor) {
- // If it is configured to use in-place editor, then invoke the editor.
- if (currentViewer != null) {
- Control control = currentViewer.getControl();
- if (!control.isDisposed()) {
- currentViewer.editElement(node, 0);
- }
- }
- }
- else {
- Shell shell = HandlerUtil.getActiveShellChecked(event);
- RenameDialog dialog = createRenameDialog(shell, node);
- int ok = dialog.open();
- if (ok == Window.OK) {
- // Do the renaming.
- String newName = dialog.getNewName();
- // Rename the node with the new name using an FSRename.
- IOpExecutor executor = new JobExecutor(new RenameCallback());
- executor.execute(new OpRename(node, newName));
- }
- }
- }
- return null;
- }
-
- /**
- * Create a renaming dialog for the specified file/folder node.
- *
- * @param shell The parent shell.
- * @param node The file/folder node.
- * @return The renaming dialog.
- */
- private RenameDialog createRenameDialog(Shell shell, FSTreeNode node) {
- String[] names = getUsedNames(node);
- String title;
- if (node.isFile()) {
- title = Messages.RenameFilesHandler_TitleRenameFile;
- }
- else if (node.isDirectory()) {
- title = Messages.RenameFilesHandler_TitleRenameFolder;
- }
- else {
- title = Messages.RenameFilesHandler_TitleRename;
- }
- String formatRegex;
- if (node.isWindowsNode()) {
- formatRegex = FSCellValidator.WIN_FILENAME_REGEX;
- }
- else {
- formatRegex = FSCellValidator.UNIX_FILENAME_REGEX;
- }
- String error;
- if (node.isWindowsNode()) {
- error = Messages.FSRenamingAssistant_WinIllegalCharacters;
- }
- else {
- error = Messages.FSRenamingAssistant_UnixIllegalCharacters;
- }
- String prompt = Messages.RenameFilesHandler_RenamePromptMessage;
- String usedError = Messages.FSRenamingAssistant_NameAlreadyExists;
- String label = Messages.RenameFilesHandler_PromptNewName;
- return new RenameDialog(shell, title, prompt, usedError, error, label, node.name, formatRegex, names, null);
- }
-
- /**
- * Get the used names in the specified folder.
- *
- * @param folder The folder.
- * @return Used names.
- */
- private String[] getUsedNames(FSTreeNode folder) {
- List<String> usedNames = new ArrayList<String>();
- List<FSTreeNode> nodes = folder.getParent().getChildren();
- for (FSTreeNode node : nodes) {
- usedNames.add(node.name);
- }
- return usedNames.toArray(new String[usedNames.size()]);
- }
-
- /**
- * Set the currently focused tree viewer. Called by Target Explorer and FSTreeControl to set the
- * current viewer.
- *
- * @param viewer The currently focused tree viewer.
- */
- public static void setCurrentViewer(TreeViewer viewer) {
- currentViewer = viewer;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.filesystem.ui.internal.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.IOpExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.JobExecutor;
+import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpRename;
+import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
+import org.eclipse.tcf.te.tcf.filesystem.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.filesystem.ui.internal.celleditor.FSCellValidator;
+import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.dialogs.RenameDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * The handler that renames the selected file or folder.
+ */
+public class RenameFilesHandler extends AbstractHandler {
+ // The currently focused viewer.
+ private static TreeViewer currentViewer;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IStructuredSelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
+ if (!sel.isEmpty()) {
+ FSTreeNode node = (FSTreeNode) sel.getFirstElement();
+ boolean inPlaceEditor = UIPlugin.isInPlaceEditor();
+ if (inPlaceEditor) {
+ // If it is configured to use in-place editor, then invoke the editor.
+ if (currentViewer != null) {
+ Control control = currentViewer.getControl();
+ if (!control.isDisposed()) {
+ currentViewer.editElement(node, 0);
+ }
+ }
+ }
+ else {
+ Shell shell = HandlerUtil.getActiveShellChecked(event);
+ RenameDialog dialog = createRenameDialog(shell, node);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ // Do the renaming.
+ String newName = dialog.getNewName();
+ // Rename the node with the new name using an FSRename.
+ IOpExecutor executor = new JobExecutor(new RenameCallback());
+ executor.execute(new OpRename(node, newName));
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Create a renaming dialog for the specified file/folder node.
+ *
+ * @param shell The parent shell.
+ * @param node The file/folder node.
+ * @return The renaming dialog.
+ */
+ private RenameDialog createRenameDialog(Shell shell, FSTreeNode node) {
+ String[] names = getUsedNames(node);
+ String title;
+ if (node.isFile()) {
+ title = Messages.RenameFilesHandler_TitleRenameFile;
+ }
+ else if (node.isDirectory()) {
+ title = Messages.RenameFilesHandler_TitleRenameFolder;
+ }
+ else {
+ title = Messages.RenameFilesHandler_TitleRename;
+ }
+ String formatRegex;
+ if (node.isWindowsNode()) {
+ formatRegex = FSCellValidator.WIN_FILENAME_REGEX;
+ }
+ else {
+ formatRegex = FSCellValidator.UNIX_FILENAME_REGEX;
+ }
+ String error;
+ if (node.isWindowsNode()) {
+ error = Messages.FSRenamingAssistant_WinIllegalCharacters;
+ }
+ else {
+ error = Messages.FSRenamingAssistant_UnixIllegalCharacters;
+ }
+ String prompt = Messages.RenameFilesHandler_RenamePromptMessage;
+ String usedError = Messages.FSRenamingAssistant_NameAlreadyExists;
+ String label = Messages.RenameFilesHandler_PromptNewName;
+ return new RenameDialog(shell, title, null, prompt, usedError, error, label, node.name, formatRegex, names, null);
+ }
+
+ /**
+ * Get the used names in the specified folder.
+ *
+ * @param folder The folder.
+ * @return Used names.
+ */
+ private String[] getUsedNames(FSTreeNode folder) {
+ List<String> usedNames = new ArrayList<String>();
+ List<FSTreeNode> nodes = folder.getParent().getChildren();
+ for (FSTreeNode node : nodes) {
+ usedNames.add(node.name);
+ }
+ return usedNames.toArray(new String[usedNames.size()]);
+ }
+
+ /**
+ * Set the currently focused tree viewer. Called by Target Explorer and FSTreeControl to set the
+ * current viewer.
+ *
+ * @param viewer The currently focused tree viewer.
+ */
+ public static void setCurrentViewer(TreeViewer viewer) {
+ currentViewer = viewer;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/icons/elcl16/rename.gif b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/icons/elcl16/rename.gif
new file mode 100644
index 000000000..4b6b76831
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/icons/elcl16/rename.gif
Binary files differ
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
index 370aa88f5..17628318a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/plugin.properties
@@ -61,3 +61,6 @@ command.resetredirect.tooltip=Reset communication redirection of this node
command.offline.name=Always Available Offline Command
command.offline.label=Always Available Offline
command.offline.tooltip=Creates an offline copy of the target attributes.
+
+command.rename.label=Rename
+command.rename.description=Rename the selected target
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 aedd35a6d..73aa8eaf8 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
@@ -290,6 +290,27 @@
</menuContribution>
<menuContribution locationURI="popup:org.eclipse.tcf.te.ui.views.View#Popup?after=group.refresh">
+ <command
+ commandId="org.eclipse.ui.edit.rename"
+ helpContextId="org.eclipse.tcf.te.tcf.ui.command_Rename"
+ icon="icons/elcl16/rename.gif"
+ id="org.eclipse.tcf.te.tcf.ui.commands.rename"
+ label="%command.rename.label"
+ mnemonic="R"
+ style="push"
+ tooltip="%command.rename.tooltip">
+ <visibleWhen checkEnabled="false">
+ <with variable="selection">
+ <count value="1"/>
+ <iterate operator="and" ifEmpty="false">
+ <and>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ <test property="org.eclipse.tcf.te.tcf.locator.isStaticPeer" value="true"/>
+ </and>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
<command
commandId="org.eclipse.tcf.te.ui.command.refresh"
label="%command.refresh.label"
@@ -379,10 +400,7 @@
<activeWhen>
<and>
<with variable="activePartId">
- <or>
- <equals value="org.eclipse.tcf.te.ui.views.View"/>
- <equals value="org.eclipse.tcf.te.ui.views.Editor"/>
- </or>
+ <equals value="org.eclipse.tcf.te.ui.views.View"/>
</with>
<with variable="selection">
<iterate operator="and" ifEmpty="false">
@@ -399,6 +417,34 @@
</handler>
<handler
+ commandId="org.eclipse.ui.edit.rename"
+ class="org.eclipse.tcf.te.tcf.ui.handler.RenameHandler">
+ <activeWhen>
+ <and>
+ <with variable="activePartId">
+ <equals value="org.eclipse.tcf.te.ui.views.View"/>
+ </with>
+ <with variable="selection">
+ <iterate operator="and" ifEmpty="false">
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ </iterate>
+ </with>
+ </and>
+ </activeWhen>
+ <enabledWhen>
+ <with variable="selection">
+ <count value="1"/>
+ <iterate operator="and" ifEmpty="false">
+ <and>
+ <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel"/>
+ <test property="org.eclipse.tcf.te.tcf.locator.isStaticPeer" value="true"/>
+ </and>
+ </iterate>
+ </with>
+ </enabledWhen>
+ </handler>
+
+ <handler
class="org.eclipse.tcf.te.tcf.ui.handler.OfflineCommandHandler"
commandId="org.eclipse.tcf.te.tcf.ui.command.offline">
<activeWhen>
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
new file mode 100644
index 000000000..8ea5bae34
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java
@@ -0,0 +1,253 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.tcf.ui.handler;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Assert;
+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.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.runtime.callback.Callback;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
+import org.eclipse.tcf.te.runtime.properties.PropertiesContainer;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerManager;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandler;
+import org.eclipse.tcf.te.runtime.statushandler.interfaces.IStatusHandlerConstants;
+import org.eclipse.tcf.te.tcf.core.peers.Peer;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
+import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties;
+import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService;
+import org.eclipse.tcf.te.tcf.locator.model.Model;
+import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector;
+import org.eclipse.tcf.te.tcf.ui.activator.UIPlugin;
+import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds;
+import org.eclipse.tcf.te.tcf.ui.nls.Messages;
+import org.eclipse.tcf.te.ui.dialogs.RenameDialog;
+import org.eclipse.tcf.te.ui.views.ViewsUtil;
+import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Rename handler implementation.
+ */
+public class RenameHandler extends AbstractHandler {
+ // Remember the shell from the execution event
+ private Shell shell = null;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // Get the shell
+ shell = HandlerUtil.getActiveShell(event);
+ // Get the current selection
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ // Delete the selection
+ if (selection != null) {
+ rename(selection, new Callback() {
+ @Override
+ protected void internalDone(Object caller, IStatus status) {
+ // Refresh the view
+ ViewsUtil.refresh(IUIConstants.ID_EXPLORER);
+ }
+ });
+ }
+ // Reset the shell
+ shell = null;
+
+ return null;
+ }
+
+ /**
+ * Renames all elements from the given selection and invokes the
+ * given callback once done.
+ *
+ * @param selection The selection. Must not be <code>null</code>.
+ * @param callback The callback. Must not be <code>null</code>.
+ */
+ public void rename(final ISelection selection, final ICallback callback) {
+ Assert.isNotNull(selection);
+ Assert.isNotNull(callback);
+
+ // The callback needs to be invoked in any case. However, if called
+ // from an asynchronous callback, set this flag to false.
+ boolean invokeCallback = true;
+
+ // The selection must be a structured selection and must not be empty
+ if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
+ Iterator<?> iterator = ((IStructuredSelection)selection).iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ Assert.isTrue(element instanceof IPeerModel);
+ final IPeerModel node = (IPeerModel)element;
+
+ RenameDialog dialog = createRenameDialog(shell, node);
+ int ok = dialog.open();
+ if (ok == Window.OK) {
+ // Do the renaming.
+ final String newName = dialog.getNewName();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ if (newName != null && !"".equals(newName) && !newName.equals(node.getPeer().getName())) { //$NON-NLS-1$
+ try {
+ // Get the persistence service
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService == null) {
+ throw new IOException("Persistence service instance unavailable."); //$NON-NLS-1$
+ }
+
+ // To update the peer attributes, the peer needs to be recreated
+ IPeer oldPeer = node.getPeer();
+ // Create a write able copy of the peer attributes
+ Map<String, String> attributes = new HashMap<String, String>(oldPeer.getAttributes());
+ // Update the name
+ attributes.put(IPeer.ATTR_NAME, newName);
+ // Remove the persistence storage URI (if set)
+ attributes.remove(IPersistableNodeProperties.PROPERTY_URI);
+ // Create the new peer
+ IPeer newPeer = oldPeer instanceof PeerRedirector ? new PeerRedirector(((PeerRedirector)oldPeer).getParent(), attributes) : new Peer(attributes);
+ // Update the peer node instance (silently)
+ boolean changed = node.setChangeEventsEnabled(false);
+ node.setProperty(IPeerModelProperties.PROP_INSTANCE, newPeer);
+ if (changed) {
+ node.setChangeEventsEnabled(true);
+ }
+
+ // Remove the old persisted peer
+ uRIPersistenceService.delete(oldPeer, null);
+ // Save the peer node to the new persistence storage
+ uRIPersistenceService.write(newPeer, null);
+
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ // Trigger a change event for the node
+ node.fireChangeEvent("properties", null, node.getProperties()); //$NON-NLS-1$
+ }
+ });
+
+ } catch (IOException e) {
+ // Create the status
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(),
+ Messages.RenameHandler_error_renameFailed, e);
+
+ // Fill in the status handler custom data
+ IPropertiesContainer data = new PropertiesContainer();
+ data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, Messages.RenameHandler_error_title);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, IContextHelpIds.MESSAGE_RENAME_FAILED);
+ data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);
+
+ // Get the status handler
+ IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(selection);
+ if (handler.length > 0) {
+ handler[0].handleStatus(status, data, null);
+ }
+ }
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ // Get the locator model
+ final ILocatorModel model = Model.getModel();
+ if (model != null) {
+ // Trigger a refresh of the model
+ final ILocatorModelRefreshService service = model.getService(ILocatorModelRefreshService.class);
+ if (service != null) {
+ // Invoke the callback after the refresh
+ invokeCallback = false;
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ // Refresh the model now (must be executed within the TCF dispatch thread)
+ service.refresh();
+ // Invoke the callback
+ callback.done(RenameHandler.this, Status.OK_STATUS);
+ }
+ });
+ }
+ }
+ }
+ }
+ }
+
+ if (invokeCallback) {
+ callback.done(this, Status.OK_STATUS);
+ }
+ }
+
+ /**
+ * Create a renaming dialog for the specified peer model node.
+ *
+ * @param shell The parent shell or <code>null</code>
+ * @param node The peer model. Must not be <code>null</code>.
+ *
+ * @return The renaming dialog.
+ */
+ private RenameDialog createRenameDialog(final Shell shell, final IPeerModel node) {
+ Assert.isNotNull(node);
+
+ final AtomicReference<String> name = new AtomicReference<String>();
+ final List<String> usedNames = new ArrayList<String>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ name.set(node.getPeer().getName());
+
+ ILocatorModel model = Model.getModel();
+ IPeerModel[] peers = model.getPeers();
+ for (IPeerModel peer : peers) {
+ if (peer.equals(node)) continue;
+ if (!usedNames.contains(peer.getPeer().getName())) {
+ usedNames.add(peer.getPeer().getName());
+ }
+ }
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ String title = NLS.bind(Messages.RenameHandler_dialog_title, name.get());
+ String prompt = Messages.RenameHandler_dialog_message;
+ String usedError = Messages.RenameHandler_dialog_error_nameExist;
+ String label = Messages.RenameHandler_dialog_promptNewName;
+
+ return new RenameDialog(shell, null, title, prompt, usedError, null, label, name.get(), null, usedNames.toArray(new String[usedNames.size()]), null);
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java
index 18db12863..18b130da7 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/help/IContextHelpIds.java
@@ -55,6 +55,11 @@ public interface IContextHelpIds {
public final static String MESSAGE_DELETE_FAILED = PREFIX + ".status.messageDeleteFailed"; //$NON-NLS-1$
/**
+ * Rename command handler: Rename operation failed.
+ */
+ public final static String MESSAGE_RENAME_FAILED = PREFIX + ".status.messageRenameFailed"; //$NON-NLS-1$
+
+ /**
* Redirect command handler: Redirect operation failed.
*/
public final static String MESSAGE_REDIRECT_FAILED = PREFIX + ".status.messageRedirectFailed"; //$NON-NLS-1$
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
index d5e8fc363..1b5a71ef2 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.java
@@ -154,6 +154,13 @@ public class Messages extends NLS {
public static String CategoryManager_dnd_failed;
+ public static String RenameHandler_error_title;
+ public static String RenameHandler_error_renameFailed;
+ public static String RenameHandler_dialog_title;
+ public static String RenameHandler_dialog_message;
+ public static String RenameHandler_dialog_error_nameExist;
+ public static String RenameHandler_dialog_promptNewName;
+
public static String LoggingPreferencePage_label;
public static String LoggingPreferencePage_enabled_label;
public static String LoggingPreferencePage_monitorEnabled_label;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
index 813b81bc4..fab741b7c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/nls/Messages.properties
@@ -109,6 +109,13 @@ OfflineCommandHandler_error_makeOffline_failed=Failed to create offline copy of
CategoryManager_dnd_failed=DND operation failed: {0}
+RenameHandler_error_title=Error
+RenameHandler_error_renameFailed=Failed to rename static target.
+RenameHandler_dialog_title=Rename ''{0}''
+RenameHandler_dialog_message=Please enter a new name for the selected target.
+RenameHandler_dialog_error_nameExist=A target with the name you specified already exists! Specify a different name.
+RenameHandler_dialog_promptNewName=New Name:
+
# ***** Preference Pages *****
LoggingPreferencePage_label=Logging settings for agent communication:
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/RenameDialog.java b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/RenameDialog.java
index 5690fee4a..32bd5bf6c 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/RenameDialog.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui/src/org/eclipse/tcf/te/ui/dialogs/RenameDialog.java
@@ -31,6 +31,7 @@ import org.eclipse.tcf.te.ui.jface.dialogs.CustomTitleAreaDialog;
*/
public class RenameDialog extends CustomTitleAreaDialog {
+ private String dialogTitle;
private String title;
/* default */ String defaultMessage;
/* default */ String usedErrorMessage;
@@ -57,11 +58,12 @@ public class RenameDialog extends CustomTitleAreaDialog {
* @param usedNames The list of used or reserved names.
* @param contextHelpId The context help id.
*/
- public RenameDialog(Shell parent, String title, String defaultMessage, String usedErrorMessage, String formatErrorMessage,
+ public RenameDialog(Shell parent, String dialogTitle, String title, String defaultMessage, String usedErrorMessage, String formatErrorMessage,
String label, String oldName, String formatRegex, String[] usedNames, String contextHelpId) {
super(parent, contextHelpId);
- this.title = title != null ? title : "Rename"; //$NON-NLS-1$
+ this.dialogTitle = dialogTitle != null ? dialogTitle : "Rename"; //$NON-NLS-1$
+ this.title = title != null ? title : ""; //$NON-NLS-1$
this.defaultMessage = defaultMessage != null ? defaultMessage : ""; //$NON-NLS-1$
this.usedErrorMessage = usedErrorMessage != null ? usedErrorMessage : ""; //$NON-NLS-1$
this.formatErrorMessage = formatErrorMessage != null ? formatErrorMessage : ""; //$NON-NLS-1$
@@ -77,7 +79,8 @@ public class RenameDialog extends CustomTitleAreaDialog {
*/
@Override
protected Control createDialogArea(Composite parent) {
- setDialogTitle(title);
+ setDialogTitle(dialogTitle);
+ setTitle(title);
setDefaultMessage(defaultMessage, IMessageProvider.INFORMATION);
//set margins of dialog and apply dialog font

Back to the top