don't rely on all services reporting in-use together for UI to show connection in use
authordadubrow
Tue, 28 Jul 2009 15:08:51 -0500
changeset 381 9a15cc2691b5
parent 380 2c1483a2585f
child 382 6a8fd4465a9b
don't rely on all services reporting in-use together for UI to show connection in use
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/messages.properties	Tue Jul 28 15:06:01 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Tue Jul 28 15:08:51 2009 -0500
@@ -42,6 +42,7 @@
 ConnectionsView.EnableTestActionLabel=Enable Service Testing
 ConnectionsView.DisableTestActionLabel=Disable Service Testing
 ConnectionsView.TypeColumnHeader=Type
+ConnectionsView.InUseDesc=At least one service is using this connection
 ConnectionTypePage.ConnectionNameInUseError=The connection name ''{0}'' is in use
 ConnectionTypePage.Description=Select a name and the connection type for the connection
 ConnectionTypePage.NameLabel=Connection name:
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java	Tue Jul 28 15:06:01 2009 -0500
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java	Tue Jul 28 15:08:51 2009 -0500
@@ -190,6 +190,9 @@
 			}
 			else if (value instanceof IConnectedService) {
 				EStatus status = ((IConnectedService) value).getStatus().getEStatus();
+				IConnection connection = findConnection((IConnectedService) value);
+				if (connection != null && isConnectionInUse(connection))
+					status = EStatus.IN_USE;
 				switch (status) {
 				case DOWN:
 					return STATUS_UNAVAIL_IMG;
@@ -203,30 +206,21 @@
 			}
 			return null;
 		}
-
-		private boolean isConnectionInUse(IConnection connection) {
-			Collection<IConnectedService> connectedServices = 
-				RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
-			// if any service is in-use, then connection is in-use
-			for (IConnectedService connectedService : connectedServices) {
-				IStatus status = connectedService.getStatus();
-				if (status.getEStatus().equals(EStatus.IN_USE))
-					return true;
-			}
-			
-			return false;
-		}
 	}
 	
 	private class StatusLabelProvider extends ColumnLabelProvider {
-
 		public String getText(Object obj) {
 			TreeNode node = (TreeNode) obj;
 			Object value = node.getValue();
 			if (value instanceof IConnectedService) {
-				IStatus status = ((IConnectedService) value).getStatus();
-				if (!status.getEStatus().equals(EStatus.IN_USE)) // if in-use, we show it in the connection row
+				IStatus status = null;
+				IConnection connection = findConnection((IConnectedService) value);
+				if (connection != null)
+					status = getFirstInUseStatus(connection);
+				if (status == null) {
+					status = ((IConnectedService) value).getStatus();
 					return status.getShortDescription();
+				}
 			}
 			else if (value instanceof IConnection) {
 				IStatus status = getFirstInUseStatus((IConnection) value);
@@ -237,19 +231,6 @@
 			return null;
 		}
 
-		private IStatus getFirstInUseStatus(IConnection connection) {
-			Collection<IConnectedService> connectedServices = 
-				RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
-			// if any service is in-use, then connection is in-use
-			for (IConnectedService connectedService : connectedServices) {
-				IStatus status = connectedService.getStatus();
-				if (status.getEStatus().equals(EStatus.IN_USE))
-					return status;
-			}
-			
-			return null;
-		}
-
 		@Override
 		public Color getForeground(Object obj) {
 			TreeNode node = (TreeNode) obj;
@@ -280,13 +261,20 @@
 			Object value = node.getValue();
 			if (value instanceof IConnectedService) {
 				IStatus status = ((IConnectedService) value).getStatus();
-				if (!status.getEStatus().equals(EStatus.IN_USE)) { // if in-use, we show it in the connection row
+				IConnection connection = findConnection((IConnectedService) value);
+				if (!status.getEStatus().equals(EStatus.IN_USE) ||
+						!(connection != null && isConnectionInUse(connection))) { // if in-use, we show it in the connection row
 					String longDescription = status.getLongDescription();
 					if (longDescription != null)
 						longDescription = TextUtils.canonicalizeNewlines(longDescription, " "); //$NON-NLS-1$
 					return longDescription;
 				}
 			}
+			else if (value instanceof IConnection) {
+				if (isConnectionInUse((IConnection) value)) {
+					return Messages.getString("ConnectionsView.InUseDesc");
+				}
+			}
 			
 			return null;
 		}
@@ -738,5 +726,32 @@
 		super.dispose();
 	}
 	
+	private static IConnection findConnection(IConnectedService cs) {
+		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
+			for (IConnectedService connectedService : RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection)) {
+				if (cs.equals(connectedService))
+					return connection;
+			}
+		}
+		return null;
+	}
+
+	private static IStatus getFirstInUseStatus(IConnection connection) {
+		Collection<IConnectedService> connectedServices = 
+			RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
+		// if any service is in-use, then connection is in-use
+		for (IConnectedService connectedService : connectedServices) {
+			IStatus status = connectedService.getStatus();
+			if (status.getEStatus().equals(EStatus.IN_USE))
+				return status;
+		}
+		
+		return null;
+	}
+
+	private boolean isConnectionInUse(IConnection connection) {
+		return getFirstInUseStatus(connection) != null;
+	}
+
 }