1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 05:15:43 +02:00

Check for changes before opening connection.

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2013-10-07 11:41:49 -04:00
parent c22656936a
commit ec96e61198
7 changed files with 152 additions and 3 deletions

View file

@ -22,36 +22,91 @@ public class LocalConnectionWorkingCopy extends LocalConnection implements IRemo
fOriginal = connection; fOriginal = connection;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#getOriginal()
*/
@Override
public IRemoteConnection getOriginal() {
return fOriginal;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#isDirty()
*/
@Override
public boolean isDirty() {
return false;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#save()
*/
@Override @Override
public IRemoteConnection save() { public IRemoteConnection save() {
return fOriginal; return fOriginal;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String)
*/
@Override @Override
public void setAddress(String address) { public void setAddress(String address) {
// Do nothing // Do nothing
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String)
*/
@Override @Override
public void setAttribute(String key, String value) { public void setAttribute(String key, String value) {
// Do nothing // Do nothing
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String)
*/
@Override @Override
public void setName(String name) { public void setName(String name) {
// Do nothing // Do nothing
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String)
*/
@Override @Override
public void setPassword(String password) { public void setPassword(String password) {
// Do nothing // Do nothing
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int)
*/
@Override @Override
public void setPort(int port) { public void setPort(int port) {
// Do nothing // Do nothing
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String)
*/
@Override @Override
public void setUsername(String username) { public void setUsername(String username) {
// Do nothing // Do nothing

View file

@ -11,6 +11,20 @@
package org.eclipse.remote.core; package org.eclipse.remote.core;
public interface IRemoteConnectionWorkingCopy extends IRemoteConnection { public interface IRemoteConnectionWorkingCopy extends IRemoteConnection {
/**
* Returns the original connection this working copy was created from.
*
* @return original connection
*/
public IRemoteConnection getOriginal();
/**
* Returns whether this connection has been modified since it was last saved or created.
*
* @return true if the connection has been modified
*/
public boolean isDirty();
/** /**
* Saves this working copy to its original connection and returns a handle to the resulting connection. Has no effect if this * Saves this working copy to its original connection and returns a handle to the resulting connection. Has no effect if this
* connection does not need saving. * connection does not need saving.

View file

@ -97,6 +97,10 @@ public class JSchConnection implements IRemoteConnection {
if (logging) { if (logging) {
System.out.println("promptPassword:" + message); //$NON-NLS-1$ System.out.println("promptPassword:" + message); //$NON-NLS-1$
} }
if (firstTry && !getPassword().equals("")) { //$NON-NLS-1$
firstTry = false;
return true;
}
if (fAuthenticator != null) { if (fAuthenticator != null) {
PasswordAuthentication auth = fAuthenticator.prompt(null, message); PasswordAuthentication auth = fAuthenticator.prompt(null, message);
if (auth == null) { if (auth == null) {
@ -117,11 +121,11 @@ public class JSchConnection implements IRemoteConnection {
return true; return true;
} }
if (fAuthenticator != null) { if (fAuthenticator != null) {
String[] results = fAuthenticator.prompt("", "", message, new String[] { message }, new boolean[] { true }); //$NON-NLS-1$//$NON-NLS-2$ PasswordAuthentication auth = fAuthenticator.prompt(null, message);
if (results == null) { if (auth == null) {
return false; return false;
} }
fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, results[0]); fAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, new String(auth.getPassword()));
} }
return true; return true;
} }

View file

@ -23,11 +23,13 @@ import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
public class JSchConnectionWorkingCopy extends JSchConnection implements IRemoteConnectionWorkingCopy { public class JSchConnectionWorkingCopy extends JSchConnection implements IRemoteConnectionWorkingCopy {
private final JSchConnectionAttributes fWorkingAttributes; private final JSchConnectionAttributes fWorkingAttributes;
private final JSchConnection fOriginal; private final JSchConnection fOriginal;
private boolean fIsDirty;
public JSchConnectionWorkingCopy(JSchConnection connection) { public JSchConnectionWorkingCopy(JSchConnection connection) {
super(connection.getName(), connection.getRemoteServices()); super(connection.getName(), connection.getRemoteServices());
fWorkingAttributes = connection.getInfo().copy(); fWorkingAttributes = connection.getInfo().copy();
fOriginal = connection; fOriginal = connection;
fIsDirty = false;
} }
/* /*
@ -65,6 +67,15 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
return fWorkingAttributes.getName(); return fWorkingAttributes.getName();
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#getOriginal()
*/
public IRemoteConnection getOriginal() {
return fOriginal;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -125,6 +136,15 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
return this; return this;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#isDirty()
*/
public boolean isDirty() {
return fIsDirty;
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -153,6 +173,7 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
} }
info.save(); info.save();
getManager().add(fOriginal); getManager().add(fOriginal);
fIsDirty = false;
return fOriginal; return fOriginal;
} }
@ -162,6 +183,7 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAddress(java.lang.String)
*/ */
public void setAddress(String address) { public void setAddress(String address) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.ADDRESS_ATTR, address); fWorkingAttributes.setAttribute(JSchConnectionAttributes.ADDRESS_ATTR, address);
} }
@ -171,14 +193,17 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setAttribute(java.lang.String, java.lang.String)
*/ */
public void setAttribute(String key, String value) { public void setAttribute(String key, String value) {
fIsDirty = true;
fWorkingAttributes.setAttribute(key, value); fWorkingAttributes.setAttribute(key, value);
} }
public void setIsPasswordAuth(boolean flag) { public void setIsPasswordAuth(boolean flag) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(flag)); fWorkingAttributes.setAttribute(JSchConnectionAttributes.IS_PASSWORD_ATTR, Boolean.toString(flag));
} }
public void setKeyFile(String keyFile) { public void setKeyFile(String keyFile) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.KEYFILE_ATTR, keyFile); fWorkingAttributes.setAttribute(JSchConnectionAttributes.KEYFILE_ATTR, keyFile);
} }
@ -193,10 +218,12 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setName(java.lang.String)
*/ */
public void setName(String name) { public void setName(String name) {
fIsDirty = true;
fWorkingAttributes.setName(name); fWorkingAttributes.setName(name);
} }
public void setPassphrase(String passphrase) { public void setPassphrase(String passphrase) {
fIsDirty = true;
fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, passphrase); fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSPHRASE_ATTR, passphrase);
} }
@ -206,6 +233,7 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPassword(java.lang.String)
*/ */
public void setPassword(String password) { public void setPassword(String password) {
fIsDirty = true;
fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, password); fWorkingAttributes.setSecureAttribute(JSchConnectionAttributes.PASSWORD_ATTR, password);
} }
@ -215,14 +243,17 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setPort(int)
*/ */
public void setPort(int port) { public void setPort(int port) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.PORT_ATTR, Integer.toString(port)); fWorkingAttributes.setAttribute(JSchConnectionAttributes.PORT_ATTR, Integer.toString(port));
} }
public void setTimeout(int timeout) { public void setTimeout(int timeout) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.TIMEOUT_ATTR, Integer.toString(timeout)); fWorkingAttributes.setAttribute(JSchConnectionAttributes.TIMEOUT_ATTR, Integer.toString(timeout));
} }
public void setUseLoginShell(boolean flag) { public void setUseLoginShell(boolean flag) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.USE_LOGIN_SHELL_ATTR, Boolean.toString(flag)); fWorkingAttributes.setAttribute(JSchConnectionAttributes.USE_LOGIN_SHELL_ATTR, Boolean.toString(flag));
} }
@ -232,6 +263,7 @@ public class JSchConnectionWorkingCopy extends JSchConnection implements IRemote
* @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String) * @see org.eclipse.remote.core.IRemoteConnectionWorkingCopy#setUsername(java.lang.String)
*/ */
public void setUsername(String userName) { public void setUsername(String userName) {
fIsDirty = true;
fWorkingAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, userName); fWorkingAttributes.setAttribute(JSchConnectionAttributes.USERNAME_ATTR, userName);
} }
} }

View file

@ -26,6 +26,8 @@ public class Messages extends NLS {
public static String ConnectionsPreferencePage_Close; public static String ConnectionsPreferencePage_Close;
public static String ConnectionsPreferencePage_Confirm_Actions;
public static String ConnectionsPreferencePage_Connection_Name; public static String ConnectionsPreferencePage_Connection_Name;
public static String ConnectionsPreferencePage_Edit; public static String ConnectionsPreferencePage_Edit;
@ -42,6 +44,8 @@ public class Messages extends NLS {
public static String ConnectionsPreferencePage_Status; public static String ConnectionsPreferencePage_Status;
public static String ConnectionsPreferencePage_This_connection_contains_unsaved_changes;
public static String ConnectionsPreferencePage_User; public static String ConnectionsPreferencePage_User;
public static String LocalUIConnectionManager_0; public static String LocalUIConnectionManager_0;

View file

@ -10,6 +10,7 @@ AbstractRemoteUIConnectionManager_Connection_Error=Connection Error
ConnectionsPreferencePage_Add=Add ConnectionsPreferencePage_Add=Add
ConnectionsPreferencePage_Close=Close ConnectionsPreferencePage_Close=Close
ConnectionsPreferencePage_closed=closed ConnectionsPreferencePage_closed=closed
ConnectionsPreferencePage_Confirm_Actions=Confirm Actions
ConnectionsPreferencePage_Connection_Name=Connection Name ConnectionsPreferencePage_Connection_Name=Connection Name
ConnectionsPreferencePage_Edit=Edit ConnectionsPreferencePage_Edit=Edit
ConnectionsPreferencePage_Host=Host ConnectionsPreferencePage_Host=Host
@ -18,6 +19,7 @@ ConnectionsPreferencePage_Open=Open
ConnectionsPreferencePage_Remote_Services=Remote Services: ConnectionsPreferencePage_Remote_Services=Remote Services:
ConnectionsPreferencePage_Remove=Remove ConnectionsPreferencePage_Remove=Remove
ConnectionsPreferencePage_Status=Status ConnectionsPreferencePage_Status=Status
ConnectionsPreferencePage_This_connection_contains_unsaved_changes=This connection contains unsaved changes. Do you wish to save before opening the connection?
ConnectionsPreferencePage_User=User ConnectionsPreferencePage_User=User
LocalUIConnectionManager_0=Connection Error LocalUIConnectionManager_0=Connection Error
LocalUIConnectionManager_1=Could not open connection LocalUIConnectionManager_1=Could not open connection

View file

@ -19,6 +19,8 @@ import org.eclipse.internal.remote.core.RemoteServicesDescriptor;
import org.eclipse.internal.remote.core.RemoteServicesImpl; import org.eclipse.internal.remote.core.RemoteServicesImpl;
import org.eclipse.internal.remote.core.preferences.Preferences; import org.eclipse.internal.remote.core.preferences.Preferences;
import org.eclipse.internal.remote.ui.messages.Messages; import org.eclipse.internal.remote.ui.messages.Messages;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ColumnLayoutData; import org.eclipse.jface.viewers.ColumnLayoutData;
@ -41,6 +43,8 @@ import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.remote.ui.RemoteUIServices; import org.eclipse.remote.ui.RemoteUIServices;
import org.eclipse.remote.ui.widgets.RemoteConnectionWidget; import org.eclipse.remote.ui.widgets.RemoteConnectionWidget;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@ -262,6 +266,21 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
fConnectionTable.setLayoutData(data); fConnectionTable.setLayoutData(data);
fConnectionTable.setFont(parent.getFont()); fConnectionTable.setFont(parent.getFont());
fConnectionTable.addSelectionListener(fEventHandler); fConnectionTable.addSelectionListener(fEventHandler);
fConnectionTable.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
if (fSelectedConnection != null && !fSelectedConnection.isOpen()) {
editConnection();
}
}
public void mouseDown(MouseEvent e) {
// Nothing
}
public void mouseUp(MouseEvent e) {
// Nothing
}
});
TableLayout tableLayout = new TableLayout(); TableLayout tableLayout = new TableLayout();
fConnectionTable.setLayout(tableLayout); fConnectionTable.setLayout(tableLayout);
@ -438,6 +457,25 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
if (conn.isOpen()) { if (conn.isOpen()) {
conn.close(); conn.close();
} else { } else {
if (conn instanceof IRemoteConnectionWorkingCopy) {
IRemoteConnectionWorkingCopy wc = (IRemoteConnectionWorkingCopy) conn;
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:
conn = wc.getOriginal();
break;
case 2:
return;
}
}
}
IRemoteUIConnectionManager mgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices()) IRemoteUIConnectionManager mgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices())
.getUIConnectionManager(); .getUIConnectionManager();
if (mgr != null) { if (mgr != null) {