1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Add Open/Close buttons to connections page.

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2013-09-24 15:20:46 -04:00
parent 711905b239
commit d527909629
3 changed files with 81 additions and 14 deletions

View file

@ -22,16 +22,26 @@ public class Messages extends NLS {
public static String ConnectionsPreferencePage_Add; public static String ConnectionsPreferencePage_Add;
public static String ConnectionsPreferencePage_closed;
public static String ConnectionsPreferencePage_Close;
public static String ConnectionsPreferencePage_Connection_Name; public static String ConnectionsPreferencePage_Connection_Name;
public static String ConnectionsPreferencePage_Edit; public static String ConnectionsPreferencePage_Edit;
public static String ConnectionsPreferencePage_Host; public static String ConnectionsPreferencePage_Host;
public static String ConnectionsPreferencePage_open;
public static String ConnectionsPreferencePage_Open;
public static String ConnectionsPreferencePage_Remote_Services; public static String ConnectionsPreferencePage_Remote_Services;
public static String ConnectionsPreferencePage_Remove; public static String ConnectionsPreferencePage_Remove;
public static String ConnectionsPreferencePage_Status;
public static String ConnectionsPreferencePage_User; public static String ConnectionsPreferencePage_User;
public static String LocalUIConnectionManager_0; public static String LocalUIConnectionManager_0;

View file

@ -8,11 +8,16 @@ AbstractRemoteUIConnectionManager_Could_not_open_connection=Could not open conne
############################################################################### ###############################################################################
AbstractRemoteUIConnectionManager_Connection_Error=Connection Error AbstractRemoteUIConnectionManager_Connection_Error=Connection Error
ConnectionsPreferencePage_Add=Add ConnectionsPreferencePage_Add=Add
ConnectionsPreferencePage_Close=Close
ConnectionsPreferencePage_closed=closed
ConnectionsPreferencePage_Connection_Name=Connection Name ConnectionsPreferencePage_Connection_Name=Connection Name
ConnectionsPreferencePage_Edit=Edit ConnectionsPreferencePage_Edit=Edit
ConnectionsPreferencePage_Host=Host ConnectionsPreferencePage_Host=Host
ConnectionsPreferencePage_open=open
ConnectionsPreferencePage_Open=Open
ConnectionsPreferencePage_Remote_Services=Remote Services: ConnectionsPreferencePage_Remote_Services=Remote Services:
ConnectionsPreferencePage_Remove=Remove ConnectionsPreferencePage_Remove=Remove
ConnectionsPreferencePage_Status=Status
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

@ -98,10 +98,12 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
IRemoteConnection connection = (IRemoteConnection) element; IRemoteConnection connection = (IRemoteConnection) element;
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
return connection.getName(); return connection.isOpen() ? Messages.ConnectionsPreferencePage_open : Messages.ConnectionsPreferencePage_closed;
case 1: case 1:
return connection.getAddress(); return connection.getName();
case 2: case 2:
return connection.getAddress();
case 3:
return connection.getUsername(); return connection.getUsername();
} }
return null; return null;
@ -139,6 +141,10 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
editConnection(); editConnection();
} else if (source == fRemoveButton) { } else if (source == fRemoveButton) {
removeConnections(); removeConnections();
} else if (source == fOpenButton) {
toggleConnection();
} else if (source == fCloseButton) {
toggleConnection();
} else if (source == fConnectionTable) { } else if (source == fConnectionTable) {
selectConnection(); selectConnection();
} else if (source == fServicesCombo) { } else if (source == fServicesCombo) {
@ -149,16 +155,18 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
} }
private final String[] fTableColumnHeaders = { Messages.ConnectionsPreferencePage_Connection_Name, private final String[] fTableColumnHeaders = { Messages.ConnectionsPreferencePage_Status, Messages.ConnectionsPreferencePage_Connection_Name,
Messages.ConnectionsPreferencePage_Host, Messages.ConnectionsPreferencePage_User }; Messages.ConnectionsPreferencePage_Host, Messages.ConnectionsPreferencePage_User };
private final ColumnLayoutData[] fTableColumnLayouts = { new ColumnWeightData(30), new ColumnWeightData(50), private final ColumnLayoutData[] fTableColumnLayouts = { new ColumnWeightData(15), new ColumnWeightData(35),
new ColumnWeightData(20) }; new ColumnWeightData(30), new ColumnWeightData(20) };
private Combo fServicesCombo; private Combo fServicesCombo;
private Button fAddButton; private Button fAddButton;
private Button fEditButton; private Button fEditButton;
private Button fRemoveButton; private Button fRemoveButton;
private Button fOpenButton;
private Button fCloseButton;
private Table fConnectionTable; private Table fConnectionTable;
private TableViewer fConnectionViewer; private TableViewer fConnectionViewer;
private EventHandler fEventHandler; private EventHandler fEventHandler;
@ -289,6 +297,16 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
fRemoveButton.setText(Messages.ConnectionsPreferencePage_Remove); fRemoveButton.setText(Messages.ConnectionsPreferencePage_Remove);
fRemoveButton.addSelectionListener(fEventHandler); fRemoveButton.addSelectionListener(fEventHandler);
fRemoveButton.setEnabled(false); fRemoveButton.setEnabled(false);
fOpenButton = new Button(buttonPane, SWT.PUSH);
setButtonLayoutData(fOpenButton);
fOpenButton.setText(Messages.ConnectionsPreferencePage_Open);
fOpenButton.addSelectionListener(fEventHandler);
fOpenButton.setEnabled(false);
fCloseButton = new Button(buttonPane, SWT.PUSH);
setButtonLayoutData(fCloseButton);
fCloseButton.setText(Messages.ConnectionsPreferencePage_Close);
fCloseButton.addSelectionListener(fEventHandler);
fCloseButton.setEnabled(false);
String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID); String id = Preferences.getString(IRemotePreferenceConstants.PREF_REMOTE_SERVICES_ID);
if ("".equals(id)) { //$NON-NLS-1$ if ("".equals(id)) { //$NON-NLS-1$
@ -337,10 +355,6 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
return name; return name;
} }
private Set<String> invalidConnectionNames() {
return fWorkingCopies.keySet();
}
private void initWorkingConnections() { private void initWorkingConnections() {
fWorkingCopies.clear(); fWorkingCopies.clear();
for (IRemoteConnection conn : fConnectionManager.getConnections()) { for (IRemoteConnection conn : fConnectionManager.getConnections()) {
@ -348,6 +362,10 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
} }
} }
private Set<String> invalidConnectionNames() {
return fWorkingCopies.keySet();
}
@Override @Override
protected void performDefaults() { protected void performDefaults() {
initWorkingConnections(); initWorkingConnections();
@ -389,14 +407,12 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
*/ */
private void selectConnection() { private void selectConnection() {
TableItem[] selection = fConnectionTable.getSelection(); TableItem[] selection = fConnectionTable.getSelection();
fEditButton.setEnabled(false);
fRemoveButton.setEnabled(false);
if (selection.length > 0) { if (selection.length > 0) {
fSelectedConnection = (IRemoteConnection) selection[0].getData(); fSelectedConnection = (IRemoteConnection) selection[0].getData();
IRemoteServices services = fSelectedConnection.getRemoteServices(); } else {
fEditButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0); fSelectedConnection = null;
fRemoveButton.setEnabled((services.getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0);
} }
updateEnablement();
} }
private void selectServices(String id) { private void selectServices(String id) {
@ -411,6 +427,27 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
fIsDirty = false; fIsDirty = false;
} }
/**
* Toggle the connection
*/
private void toggleConnection() {
TableItem[] items = fConnectionTable.getSelection();
if (items.length > 0) {
IRemoteConnection conn = (IRemoteConnection) items[0].getData();
if (conn.isOpen()) {
conn.close();
} else {
IRemoteUIConnectionManager mgr = RemoteUIServices.getRemoteUIServices(conn.getRemoteServices())
.getUIConnectionManager();
if (mgr != null) {
mgr.openConnectionWithProgress(getShell(), null, conn);
}
}
fConnectionViewer.refresh();
updateEnablement();
}
}
/** /**
* Update the connection manager with changes to the connections. * Update the connection manager with changes to the connections.
*/ */
@ -437,4 +474,19 @@ public class ConnectionsPreferencePage extends PreferencePage implements IWorkbe
} }
initWorkingConnections(); initWorkingConnections();
} }
private void updateEnablement() {
fEditButton.setEnabled(false);
fRemoveButton.setEnabled(false);
fOpenButton.setEnabled(false);
fCloseButton.setEnabled(false);
if (fSelectedConnection != null) {
fEditButton
.setEnabled((fSelectedConnection.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_EDIT_CONNECTIONS) != 0);
fRemoveButton
.setEnabled((fSelectedConnection.getRemoteServices().getCapabilities() & IRemoteServices.CAPABILITY_REMOVE_CONNECTIONS) != 0);
fOpenButton.setEnabled(!fSelectedConnection.isOpen());
fCloseButton.setEnabled(fSelectedConnection.isOpen());
}
}
} }