Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2016-05-11 10:05:37 +0000
committerGerrit Code Review @ Eclipse.org2016-05-11 10:05:37 +0000
commitd8bb41c1b80eb4373661f6bbc58917133e8b5ba1 (patch)
treeddb3c2d9052a69b587efd8f88a7e4222062cb097
parentc54f26b7e07319b7ad309aab8c02b72be6d1afff (diff)
parentd7c061e683c81ccda995bc9049464790780bee14 (diff)
downloadorg.eclipse.tcf-d8bb41c1b80eb4373661f6bbc58917133e8b5ba1.tar.gz
org.eclipse.tcf-d8bb41c1b80eb4373661f6bbc58917133e8b5ba1.tar.xz
org.eclipse.tcf-d8bb41c1b80eb4373661f6bbc58917133e8b5ba1.zip
Merge "Target Explorer:Renaming a connection with a long name restores old one"
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java44
1 files changed, 34 insertions, 10 deletions
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 379e57a7a..328895bec 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
@@ -119,6 +119,17 @@ public class RenameHandler extends AbstractHandler {
@Override
public void run() {
if (newName != null && !"".equals(newName) && !newName.equals(node.getPeer().getName())) { //$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 = new Peer(attributes);
+
try {
// Get the persistence service
IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
@@ -126,16 +137,6 @@ public class RenameHandler extends AbstractHandler {
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 = new Peer(attributes);
// Update the peer node instance (silently)
boolean changed = node.setChangeEventsEnabled(false);
node.setProperty(IPeerNodeProperties.PROPERTY_INSTANCE, newPeer);
@@ -157,6 +158,29 @@ public class RenameHandler extends AbstractHandler {
});
} catch (IOException e) {
+ // Remove new peer and restore the old one
+ IURIPersistenceService uRIPersistenceService = ServiceManager.getInstance().getService(IURIPersistenceService.class);
+ if (uRIPersistenceService != null) {
+ try {
+ uRIPersistenceService.delete(newPeer, null);
+ } catch (Exception ex) { /* Ignored on purpose */ }
+ try {
+ boolean changed = node.setChangeEventsEnabled(false);
+ node.setProperty(IPeerNodeProperties.PROPERTY_INSTANCE, oldPeer);
+ if (changed) {
+ node.setChangeEventsEnabled(true);
+ }
+ Protocol.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ // Trigger a change event for the node
+ node.fireChangeEvent("properties", null, node.getProperties()); //$NON-NLS-1$
+ }
+ });
+ uRIPersistenceService.write(oldPeer, null);
+ } catch (Exception ex) { /* Ignored on purpose */ }
+ }
+
String template = NLS.bind(Messages.RenameHandler_error_renameFailed, Messages.PossibleCause);
StatusHandlerUtil.handleStatus(StatusHelper.getStatus(e), selection, template,
Messages.RenameHandler_error_title, IContextHelpIds.MESSAGE_RENAME_FAILED, this, null);

Back to the top