connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/view/ConnectionsView.java
changeset 687 593d05f9d5ca
parent 381 9a15cc2691b5
child 699 fe13162b76cf
child 703 3a27d56389d5
equal deleted inserted replaced
686:745a1a177838 687:593d05f9d5ca
    23 import com.nokia.carbide.remoteconnections.interfaces.*;
    23 import com.nokia.carbide.remoteconnections.interfaces.*;
    24 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
    24 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
    25 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
    25 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
    26 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
    26 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
    27 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
    27 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
       
    28 import com.nokia.carbide.remoteconnections.internal.registry.Registry;
    28 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
    29 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
    29 import com.nokia.cpp.internal.api.utils.core.TextUtils;
    30 import com.nokia.cpp.internal.api.utils.core.TextUtils;
    30 
    31 
    31 import org.eclipse.jface.action.*;
    32 import org.eclipse.jface.action.*;
    32 import org.eclipse.jface.resource.ImageDescriptor;
    33 import org.eclipse.jface.resource.ImageDescriptor;
    98 		if (serviceToListenerMap == null)
    99 		if (serviceToListenerMap == null)
    99 			serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>();
   100 			serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>();
   100 		removeServiceListeners();
   101 		removeServiceListeners();
   101 		List<TreeNode> connectionNodes = new ArrayList<TreeNode>();
   102 		List<TreeNode> connectionNodes = new ArrayList<TreeNode>();
   102 		Collection<IConnection> connections = 
   103 		Collection<IConnection> connections = 
   103 			RemoteConnectionsActivator.getConnectionsManager().getConnections();
   104 			Registry.instance().getConnections();
   104 		for (IConnection connection : connections) {
   105 		for (IConnection connection : connections) {
   105 			// create a node for the connection
   106 			// create a node for the connection
   106 			TreeNode connectionNode = new TreeNode(connection);
   107 			TreeNode connectionNode = new TreeNode(connection);
   107 			// create subnodes for the connected services
   108 			// create subnodes for the connected services
   108 			List<TreeNode> serviceNodes = new ArrayList<TreeNode>();
   109 			List<TreeNode> serviceNodes = new ArrayList<TreeNode>();
   109 			Collection<IConnectedService> connectedServicesForConnection = 
   110 			Collection<IConnectedService> connectedServicesForConnection = 
   110 				RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
   111 				Registry.instance().getConnectedServices(connection);
   111 			for (IConnectedService connectedService : connectedServicesForConnection) {
   112 			for (IConnectedService connectedService : connectedServicesForConnection) {
   112 				final TreeNode treeNode = new TreeNode(connectedService);
   113 				final TreeNode treeNode = new TreeNode(connectedService);
   113 				IStatusChangedListener statusChangedListener = new IStatusChangedListener() {
   114 				IStatusChangedListener statusChangedListener = new IStatusChangedListener() {
   114 					public void statusChanged(final IStatus status) {
   115 					public void statusChanged(final IStatus status) {
   115 						Display.getDefault().asyncExec(new Runnable() {
   116 						Display.getDefault().asyncExec(new Runnable() {
   167 		protected void setValue(Object element, Object value) {
   168 		protected void setValue(Object element, Object value) {
   168 			IConnection connection = (IConnection) ((TreeNode) element).getValue();
   169 			IConnection connection = (IConnection) ((TreeNode) element).getValue();
   169 			connection.setDisplayName(value.toString());
   170 			connection.setDisplayName(value.toString());
   170 			viewer.refresh(true);
   171 			viewer.refresh(true);
   171 			packColumns();
   172 			packColumns();
   172 			RemoteConnectionsActivator.getConnectionsManager().storeConnections();
   173 			Registry.instance().storeConnections();
   173 		}
   174 		}
   174 	}
   175 	}
   175 
   176 
   176 	private class NameLabelProvider extends ColumnLabelProvider {
   177 	private class NameLabelProvider extends ColumnLabelProvider {
   177 
   178 
   453 						packColumns();
   454 						packColumns();
   454 					}
   455 					}
   455 				});
   456 				});
   456 			}
   457 			}
   457 		};
   458 		};
   458 		RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(connectionStoreChangedListener);
   459 		Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener);
   459 
   460 
   460 		RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$
   461 		RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$
   461 	}
   462 	}
   462 
   463 
   463 	private void packColumns() {
   464 	private void packColumns() {
   536 			}
   537 			}
   537 			
   538 			
   538 		};
   539 		};
   539 		action.setId(NEW_ACTION);
   540 		action.setId(NEW_ACTION);
   540 		actions.add(action);
   541 		actions.add(action);
   541 		action.setEnabled(!RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionTypes().isEmpty());
   542 		action.setEnabled(!Registry.instance().getConnectionTypes().isEmpty());
   542 		
   543 		
   543 		action = new Action(Messages.getString("ConnectionsView.EditActionLabel"), CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$
   544 		action = new Action(Messages.getString("ConnectionsView.EditActionLabel"), CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$
   544 			@Override
   545 			@Override
   545 			public void run() {
   546 			public void run() {
   546 				ISelection selection = viewer.getSelection();
   547 				ISelection selection = viewer.getSelection();
   585 		serviceSelectedActions.add(action);
   586 		serviceSelectedActions.add(action);
   586 		
   587 		
   587 		action = new Action(Messages.getString("ConnectionsView.RefreshActionLabel"), CONNECTION_REFRESH_IMGDESC) { //$NON-NLS-1$
   588 		action = new Action(Messages.getString("ConnectionsView.RefreshActionLabel"), CONNECTION_REFRESH_IMGDESC) { //$NON-NLS-1$
   588 			@Override
   589 			@Override
   589 			public void run() {
   590 			public void run() {
   590 				IConnectionsManager connectionsManager = RemoteConnectionsActivator.getConnectionsManager();
   591 				IConnectionsManager connectionsManager = Registry.instance();
   591 				for (IConnection connection : connectionsManager.getConnections()) {
   592 				for (IConnection connection : connectionsManager.getConnections()) {
   592 					Collection<IConnectedService> connectedServices = connectionsManager.getConnectedServices(connection);
   593 					Collection<IConnectedService> connectedServices = connectionsManager.getConnectedServices(connection);
   593 					for (IConnectedService connectedService : connectedServices) {
   594 					for (IConnectedService connectedService : connectedServices) {
   594 						connectedService.setEnabled(true);
   595 						connectedService.setEnabled(true);
   595 						connectedService.testStatus();
   596 						connectedService.testStatus();
   610 				if (selection.isEmpty())
   611 				if (selection.isEmpty())
   611 					return;
   612 					return;
   612 				TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
   613 				TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement();
   613 				Object value = node.getValue();
   614 				Object value = node.getValue();
   614 				if (value instanceof IConnection) {
   615 				if (value instanceof IConnection) {
   615 					RemoteConnectionsActivator.getConnectionsManager().removeConnection((IConnection) value);
   616 					Registry.instance().removeConnection((IConnection) value);
   616 					RemoteConnectionsActivator.getConnectionsManager().storeConnections();
   617 					Registry.instance().storeConnections();
   617 				}
   618 				}
   618 			}
   619 			}
   619 		};
   620 		};
   620 		action.setAccelerator(SWT.DEL);
   621 		action.setAccelerator(SWT.DEL);
   621 		action.setId(DELETE_ACTION);
   622 		action.setId(DELETE_ACTION);
   705 		serviceToListenerMap.clear();
   706 		serviceToListenerMap.clear();
   706 	}
   707 	}
   707 	
   708 	
   708 	private void disableAllConnectedServices() {
   709 	private void disableAllConnectedServices() {
   709 		Collection<IConnection> connections = 
   710 		Collection<IConnection> connections = 
   710 			RemoteConnectionsActivator.getConnectionsManager().getConnections();
   711 			Registry.instance().getConnections();
   711 		for (IConnection connection : connections) {
   712 		for (IConnection connection : connections) {
   712 			Collection<IConnectedService> connectedServicesForConnection = 
   713 			Collection<IConnectedService> connectedServicesForConnection = 
   713 				RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
   714 				Registry.instance().getConnectedServices(connection);
   714 			for (IConnectedService connectedService : connectedServicesForConnection) {
   715 			for (IConnectedService connectedService : connectedServicesForConnection) {
   715 				connectedService.setEnabled(false);
   716 				connectedService.setEnabled(false);
   716 			}
   717 			}
   717 		}
   718 		}
   718 	}
   719 	}
   719 	
   720 	
   720 	@Override
   721 	@Override
   721 	public void dispose() {
   722 	public void dispose() {
   722 		removeServiceListeners();
   723 		removeServiceListeners();
   723 		RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(connectionStoreChangedListener);
   724 		Registry.instance().removeConnectionStoreChangedListener(connectionStoreChangedListener);
   724 		disableAllConnectedServices();
   725 		disableAllConnectedServices();
   725 		isDisposed = true;
   726 		isDisposed = true;
   726 		super.dispose();
   727 		super.dispose();
   727 	}
   728 	}
   728 	
   729 	
   729 	private static IConnection findConnection(IConnectedService cs) {
   730 	private static IConnection findConnection(IConnectedService cs) {
   730 		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
   731 		for (IConnection connection : Registry.instance().getConnections()) {
   731 			for (IConnectedService connectedService : RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection)) {
   732 			for (IConnectedService connectedService : Registry.instance().getConnectedServices(connection)) {
   732 				if (cs.equals(connectedService))
   733 				if (cs.equals(connectedService))
   733 					return connection;
   734 					return connection;
   734 			}
   735 			}
   735 		}
   736 		}
   736 		return null;
   737 		return null;
   737 	}
   738 	}
   738 
   739 
   739 	private static IStatus getFirstInUseStatus(IConnection connection) {
   740 	private static IStatus getFirstInUseStatus(IConnection connection) {
   740 		Collection<IConnectedService> connectedServices = 
   741 		Collection<IConnectedService> connectedServices = 
   741 			RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection);
   742 			Registry.instance().getConnectedServices(connection);
   742 		// if any service is in-use, then connection is in-use
   743 		// if any service is in-use, then connection is in-use
   743 		for (IConnectedService connectedService : connectedServices) {
   744 		for (IConnectedService connectedService : connectedServices) {
   744 			IStatus status = connectedService.getStatus();
   745 			IStatus status = connectedService.getStatus();
   745 			if (status.getEStatus().equals(EStatus.IN_USE))
   746 			if (status.getEStatus().equals(EStatus.IN_USE))
   746 				return status;
   747 				return status;