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 |
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; |