In Remote Connections view, wire up indication of default connection and menu item for switching it.
authorEd Swartz <ed.swartz@nokia.com>
Wed, 30 Dec 2009 13:38:02 -0600
changeset 732 c6b80e0b9fe2
parent 731 68bc07acac96
child 733 dfcdb2620e52
In Remote Connections view, wire up indication of default connection and menu item for switching it.
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java	Wed Dec 30 12:07:21 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java	Wed Dec 30 13:38:02 2009 -0600
@@ -57,7 +57,7 @@
 	private static final ImageDescriptor CONNECTION_IN_USE_DISCONNECTED_IMGDESC =
 		RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUseDisconnected.png"); //$NON-NLS-1$
 	
-	private static final ImageDescriptor CONNECTION_IMGDESC = 
+	public static final ImageDescriptor CONNECTION_IMGDESC = 
 		RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$
 	
 	private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage();
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Wed Dec 30 12:07:21 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Wed Dec 30 13:38:02 2009 -0600
@@ -48,10 +48,11 @@
 ConnectionStatusSelectorContribution.RemovedConnectionFormat=Removed {0}
 ConnectionsView.DeleteActionLabel=Delete Connection
 ConnectionsView.DescriptionColumnHeader=Description
-ConnectionsView.EditActionLabel=Edit Connection Settings
-ConnectionsView.HelpActionLabel=Connection Documentation
+ConnectionsView.EditActionLabel=Edit Connection Settings...
+ConnectionsView.HelpActionLabel=Help on Connection...
+ConnectionsView.SetDefaultActionLabel=Use As Default Connection
 ConnectionsView.NameColumnHeader=Connection/Services
-ConnectionsView.NewActionLabel=New Connection
+ConnectionsView.NewActionLabel=New Connection...
 ConnectionsView.RefreshActionLabel=Refresh Status
 ConnectionsView.RenameMenuLabel=Rename connection
 ConnectionsView.StatusColumnHeader=Status
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java	Wed Dec 30 12:07:21 2009 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java	Wed Dec 30 13:38:02 2009 -0600
@@ -58,6 +58,7 @@
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -77,11 +78,13 @@
 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
 import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
 import com.nokia.carbide.remoteconnections.internal.registry.Registry;
 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils;
 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
+import com.nokia.cpp.internal.api.utils.core.ObjectUtils;
 import com.nokia.cpp.internal.api.utils.core.TextUtils;
 
 
@@ -94,6 +97,7 @@
 
 	private TreeViewer viewer;
 	private IConnectionsManagerListener connectionStoreChangedListener;
+	private IConnectionListener connectionListener;
 	private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap;
 	private List<Action> actions;
 	private List<Action> connectionSelectedActions;
@@ -112,8 +116,12 @@
 	private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$
 	private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$
 	private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$
+	private static final String SET_DEFAULT_ACTION = "ConnectionsView.makeDefault"; //$NON-NLS-1$
 	private KeyAdapter keyListener;
 	private boolean isDisposed;
+
+	// handle, do not dispose
+	private Font boldViewerFont;
 	
 	private TreeNode[] loadConnections() {
 		if (serviceToListenerMap == null)
@@ -201,6 +209,19 @@
 		public String getText(Object obj) {
 			return getNodeDisplayName(obj);
 		}
+		
+		/* (non-Javadoc)
+		 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object)
+		 */
+		@Override
+		public Font getFont(Object element) {
+			if (element instanceof TreeNode) {
+				if (((TreeNode)element).getValue().equals(Registry.instance().getDefaultConnection())) {
+					return boldViewerFont;
+				}
+			}
+			return super.getFont(element);
+		}
 
 		public Image getImage(Object obj) {
 			TreeNode node = (TreeNode) obj;
@@ -369,6 +390,8 @@
 			}
 		};
 		TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT);
+		
+		boldViewerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
 
 		TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT);
 		typeColumn.setLabelProvider(new TypeLabelProvider());
@@ -467,6 +490,26 @@
 			}
 		};
 		Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener);
+		
+		connectionListener = new IConnectionListener() {
+			
+			public void defaultConnectionSet(IConnection connection) {
+				Display.getDefault().asyncExec(new Runnable() {
+					public void run() {
+						viewer.refresh(true);
+					}
+				});				
+			}
+			
+			public void connectionRemoved(IConnection connection) {
+				// presumably the viewer itself handles this...
+			}
+			
+			public void connectionAdded(IConnection connection) {
+				// presumably the viewer itself handles this...
+			}
+		};
+		Registry.instance().addConnectionListener(connectionListener);
 
 		RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$
 	}
@@ -526,6 +569,9 @@
 			manager.add(getAction(DELETE_ACTION));
 			manager.add(getAction(HELP_ACTION));
 		}
+		if (value instanceof IConnection) {
+			manager.add(getAction(SET_DEFAULT_ACTION));
+		}
 	}
 	
 	private void fillLocalToolBar(IToolBarManager manager) {
@@ -673,6 +719,36 @@
 		action.setId(HELP_ACTION);
 		actions.add(action);
 		connectionSelectedActions.add(action);
+		
+		desc = ConnectionUIUtils.CONNECTION_IMGDESC;
+		action = new Action(Messages.getString("ConnectionsView.SetDefaultActionLabel"), desc) { //$NON-NLS-1$
+			
+			private IConnection getConnectionFromSelection() {
+				ISelection selection = viewer.getSelection();
+				if (!selection.isEmpty()) {
+					TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
+					Object value = treeNode.getValue();
+					if (value instanceof IConnection) {
+						return ((IConnection) value);
+					}
+				}
+				return null;
+			}
+			
+			@Override
+			public boolean isEnabled() {
+				return !ObjectUtils.equals(Registry.instance().getDefaultConnection(), getConnectionFromSelection());
+			}
+
+			@Override
+			public void run() {
+				Registry.instance().setDefaultConnection(getConnectionFromSelection());
+			}
+		};
+		action.setId(SET_DEFAULT_ACTION);
+		actions.add(action);
+		connectionSelectedActions.add(action);		
+		
 		enableConnectionSelectedActions(false);
 		enableServiceSelectedActions(false);
 	}
@@ -743,6 +819,7 @@
 	public void dispose() {
 		removeServiceListeners();
 		Registry.instance().removeConnectionStoreChangedListener(connectionStoreChangedListener);
+		Registry.instance().removeConnectionListener(connectionListener);
 		disableAllConnectedServices();
 		isDisposed = true;
 		super.dispose();