From d7c061e683c81ccda995bc9049464790780bee14 Mon Sep 17 00:00:00 2001 From: Pablo Torregrosa Paez Date: Wed, 11 May 2016 11:54:27 +0200 Subject: Target Explorer:Renaming a connection with a long name restores old one Change-Id: Ie2f5fb14a105e93aea10d1f6c822fae52e72f020 Signed-off-by: Pablo Torregrosa Paez --- .../tcf/te/tcf/ui/handler/RenameHandler.java | 44 +++++++++++++++++----- 1 file 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 attributes = new HashMap(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 attributes = new HashMap(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); -- cgit v1.2.3