From 0df67c311c62d573396e5d4ecac48b5e436de6a0 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Mon, 2 Jun 2014 22:47:17 -0400 Subject: [PATCH] Bug 436390 - Fix new connection status. Change-Id: Ib90b507abb7c8c1b8bcb4a2d91e06de988103172 Signed-off-by: Greg Watson --- .../internal/ui/messages/messages.properties | 4 +- .../ConnectionsPreferencePage.java | 61 +++++++++++-------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages/messages.properties b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages/messages.properties index cb00e2acc40..ec5132aa7ed 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages/messages.properties +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/messages/messages.properties @@ -19,8 +19,8 @@ ConnectionsPreferencePage_Open=Open ConnectionsPreferencePage_Remote_Services=Remote Services: ConnectionsPreferencePage_Remove=Remove ConnectionsPreferencePage_Status=Status -ConnectionsPreferencePage_There_are_unsaved_changes=There are unsaved changes. Do you wish to save the changes before proceeding? -ConnectionsPreferencePage_This_connection_contains_unsaved_changes=This connection contains unsaved changes. Do you wish to save before opening the connection? +ConnectionsPreferencePage_There_are_unsaved_changes=There are unsaved changes that must be saved before proceeding. Do you wish to save the changes? +ConnectionsPreferencePage_This_connection_contains_unsaved_changes=This connection contains unsaved changes which must be saved before the connection can be opened. Do you wish to save the changes? ConnectionsPreferencePage_User=User LocalUIConnectionManager_0=Connection Error LocalUIConnectionManager_1=Could not open connection diff --git a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java index f5280c4b335..e750fe97e2b 100644 --- a/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java +++ b/bundles/org.eclipse.remote.ui/src/org/eclipse/remote/internal/ui/preferences/ConnectionsPreferencePage.java @@ -106,7 +106,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe @Override public String getColumnText(Object element, int columnIndex) { - IRemoteConnection connection = (IRemoteConnection) element; + IRemoteConnection connection = getOriginalIfClean((IRemoteConnection) element); switch (columnIndex) { case 0: return connection.isOpen() ? Messages.ConnectionsPreferencePage_open : Messages.ConnectionsPreferencePage_closed; @@ -214,17 +214,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe if (fIsDirty) { MessageDialog dialog = new MessageDialog(getShell(), Messages.ConnectionsPreferencePage_Confirm_Actions, null, Messages.ConnectionsPreferencePage_There_are_unsaved_changes, MessageDialog.QUESTION, new String[] { - IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); - switch (dialog.open()) { - case 0: - performOk(); - break; - case 1: - performDefaults(); - break; - case 2: + IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); + if (dialog.open() == 1) { return; } + performOk(); } IRemoteUIConnectionWizard wizard = fUIConnectionManager.getConnectionWizard(getShell()); if (wizard != null) { @@ -293,7 +287,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe fConnectionTable.addMouseListener(new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) { - if (fSelectedConnection != null && !fSelectedConnection.isOpen()) { + if (fSelectedConnection != null && !getOriginalIfClean(fSelectedConnection).isOpen()) { editConnection(); } } @@ -374,7 +368,12 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe */ private void editConnection() { if (fSelectedConnection != null) { - IRemoteConnectionWorkingCopy copy = fSelectedConnection.getWorkingCopy(); + IRemoteConnectionWorkingCopy copy; + if (fSelectedConnection instanceof IRemoteConnectionWorkingCopy) { + copy = (IRemoteConnectionWorkingCopy) fSelectedConnection; + } else { + copy = fSelectedConnection.getWorkingCopy(); + } IRemoteUIConnectionWizard wizard = fUIConnectionManager.getConnectionWizard(getShell()); if (wizard != null) { wizard.setConnection(copy); @@ -451,6 +450,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe fConnectionTable.deselectAll(); fSelectedConnection = null; } + updateEnablement(); } /** @@ -484,7 +484,7 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe private void toggleConnection() { TableItem[] items = fConnectionTable.getSelection(); if (items.length > 0) { - IRemoteConnection conn = (IRemoteConnection) items[0].getData(); + IRemoteConnection conn = getOriginalIfClean((IRemoteConnection) items[0].getData()); if (conn.isOpen()) { conn.close(); } else { @@ -494,17 +494,11 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe if (wc.isDirty()) { MessageDialog dialog = new MessageDialog(getShell(), Messages.ConnectionsPreferencePage_Confirm_Actions, null, Messages.ConnectionsPreferencePage_This_connection_contains_unsaved_changes, - MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, - IDialogConstants.CANCEL_LABEL }, 0); - switch (dialog.open()) { - case 0: - wc.save(); - break; - case 1: - break; - case 2: + MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); + if (dialog.open() == 1) { return; } + wc.save(); } } IRemoteUIConnectionManager mgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()) @@ -551,15 +545,32 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe fOpenButton.setEnabled(false); fCloseButton.setEnabled(false); if (fSelectedConnection != null) { - if (!fSelectedConnection.isOpen()) { + IRemoteConnection conn = getOriginalIfClean(fSelectedConnection); + if (!conn.isOpen()) { fEditButton - .setEnabled((fSelectedConnection.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0); + .setEnabled((conn.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0); fRemoveButton - .setEnabled((fSelectedConnection.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0); + .setEnabled((conn.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0); fOpenButton.setEnabled(true); } else { fCloseButton.setEnabled(true); } } } + + /** + * Get the original connection if the working copy is not dirty + * + * @param conn + * @return + */ + private IRemoteConnection getOriginalIfClean(IRemoteConnection conn) { + if (conn instanceof IRemoteConnectionWorkingCopy) { + IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) conn; + if (!wc.isDirty()) { + return wc.getOriginal(); + } + } + return conn; + } }