diff options
author | Pablo Torregrosa Paez | 2016-05-11 09:54:27 +0000 |
---|---|---|
committer | Pablo Torregrosa Paez | 2016-05-11 09:54:27 +0000 |
commit | d7c061e683c81ccda995bc9049464790780bee14 (patch) | |
tree | fdc15d469ec74f0ebf7f81c64995006ff13dd2a6 | |
parent | 077911a68758a8103ab5d49d2cc0e8d875158e2a (diff) | |
download | org.eclipse.tcf-d7c061e683c81ccda995bc9049464790780bee14.tar.gz org.eclipse.tcf-d7c061e683c81ccda995bc9049464790780bee14.tar.xz org.eclipse.tcf-d7c061e683c81ccda995bc9049464790780bee14.zip |
Target Explorer:Renaming a connection with a long name restores old one
Change-Id: Ie2f5fb14a105e93aea10d1f6c822fae52e72f020
Signed-off-by: Pablo Torregrosa Paez <pablo.torregrosa@windriver.com>
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/RenameHandler.java | 44 |
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); |