16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 package com.nokia.carbide.remoteconnections.view; |
19 package com.nokia.carbide.remoteconnections.view; |
20 |
20 |
|
21 import java.text.MessageFormat; |
|
22 import java.util.ArrayList; |
|
23 import java.util.Collection; |
|
24 import java.util.HashMap; |
|
25 import java.util.List; |
|
26 import java.util.Map; |
|
27 |
|
28 import org.eclipse.jface.action.Action; |
|
29 import org.eclipse.jface.action.IAction; |
|
30 import org.eclipse.jface.action.IMenuListener; |
|
31 import org.eclipse.jface.action.IMenuManager; |
|
32 import org.eclipse.jface.action.IToolBarManager; |
|
33 import org.eclipse.jface.action.LegacyActionTools; |
|
34 import org.eclipse.jface.action.MenuManager; |
|
35 import org.eclipse.jface.action.Separator; |
|
36 import org.eclipse.jface.resource.ImageDescriptor; |
|
37 import org.eclipse.jface.resource.JFaceResources; |
|
38 import org.eclipse.jface.viewers.CellEditor; |
|
39 import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
40 import org.eclipse.jface.viewers.ColumnViewer; |
|
41 import org.eclipse.jface.viewers.ColumnViewerEditor; |
|
42 import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; |
|
43 import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; |
|
44 import org.eclipse.jface.viewers.DoubleClickEvent; |
|
45 import org.eclipse.jface.viewers.EditingSupport; |
|
46 import org.eclipse.jface.viewers.IDoubleClickListener; |
|
47 import org.eclipse.jface.viewers.ISelection; |
|
48 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
49 import org.eclipse.jface.viewers.IStructuredSelection; |
|
50 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
51 import org.eclipse.jface.viewers.StructuredSelection; |
|
52 import org.eclipse.jface.viewers.TextCellEditor; |
|
53 import org.eclipse.jface.viewers.TreeColumnViewerLabelProvider; |
|
54 import org.eclipse.jface.viewers.TreeNode; |
|
55 import org.eclipse.jface.viewers.TreeNodeContentProvider; |
|
56 import org.eclipse.jface.viewers.TreeViewer; |
|
57 import org.eclipse.jface.viewers.TreeViewerColumn; |
|
58 import org.eclipse.jface.viewers.TreeViewerEditor; |
|
59 import org.eclipse.jface.viewers.Viewer; |
|
60 import org.eclipse.jface.viewers.ViewerSorter; |
|
61 import org.eclipse.swt.SWT; |
|
62 import org.eclipse.swt.events.KeyAdapter; |
|
63 import org.eclipse.swt.events.KeyEvent; |
|
64 import org.eclipse.swt.graphics.Color; |
|
65 import org.eclipse.swt.graphics.Font; |
|
66 import org.eclipse.swt.graphics.Image; |
|
67 import org.eclipse.swt.widgets.Composite; |
|
68 import org.eclipse.swt.widgets.Display; |
|
69 import org.eclipse.swt.widgets.Menu; |
|
70 import org.eclipse.swt.widgets.TreeColumn; |
|
71 import org.eclipse.swt.widgets.TreeItem; |
|
72 import org.eclipse.ui.IActionBars; |
|
73 import org.eclipse.ui.ISharedImages; |
|
74 import org.eclipse.ui.PlatformUI; |
|
75 import org.eclipse.ui.part.ViewPart; |
|
76 |
21 import com.nokia.carbide.remoteconnections.Messages; |
77 import com.nokia.carbide.remoteconnections.Messages; |
22 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
78 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
23 import com.nokia.carbide.remoteconnections.interfaces.*; |
79 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
80 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
81 import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
|
82 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
24 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
83 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
25 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
84 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
26 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
85 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
86 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
27 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
87 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
|
88 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
|
89 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
|
90 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
|
91 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; |
28 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
92 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
|
93 import com.nokia.cpp.internal.api.utils.core.ObjectUtils; |
29 import com.nokia.cpp.internal.api.utils.core.TextUtils; |
94 import com.nokia.cpp.internal.api.utils.core.TextUtils; |
30 |
|
31 import org.eclipse.jface.action.*; |
|
32 import org.eclipse.jface.resource.ImageDescriptor; |
|
33 import org.eclipse.jface.resource.JFaceResources; |
|
34 import org.eclipse.jface.viewers.*; |
|
35 import org.eclipse.swt.SWT; |
|
36 import org.eclipse.swt.events.*; |
|
37 import org.eclipse.swt.graphics.Color; |
|
38 import org.eclipse.swt.graphics.Image; |
|
39 import org.eclipse.swt.widgets.*; |
|
40 import org.eclipse.ui.*; |
|
41 import org.eclipse.ui.part.ViewPart; |
|
42 |
|
43 import java.util.*; |
|
44 import java.util.List; |
|
45 |
95 |
46 |
96 |
47 /** |
97 /** |
48 * The view part for Remote connections |
98 * The view part for Remote connections |
49 */ |
99 */ |
|
100 @SuppressWarnings("deprecation") |
50 public class ConnectionsView extends ViewPart { |
101 public class ConnectionsView extends ViewPart { |
|
102 public static final String VIEW_ID = "com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ |
51 |
103 |
52 private TreeViewer viewer; |
104 private TreeViewer viewer; |
53 private IConnectionsManagerListener connectionStoreChangedListener; |
105 private IConnectionsManagerListener connectionStoreChangedListener; |
|
106 private IConnectionListener connectionListener; |
54 private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap; |
107 private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap; |
55 private List<Action> actions; |
108 private List<Action> actions; |
56 private List<Action> connectionSelectedActions; |
109 private List<Action> connectionSelectedActions; |
57 private List<Action> serviceSelectedActions; |
110 private List<Action> serviceSelectedActions; |
58 private static final String UID = ".uid"; //$NON-NLS-1$ |
111 private static final String UID = ".uid"; //$NON-NLS-1$ |
59 |
112 |
60 private static final ImageDescriptor STATUS_AVAIL_IMGDESC = |
113 private static final ImageDescriptor CONNECTION_NEW_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionNew.png"); //$NON-NLS-1$ |
61 RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ |
114 private static final ImageDescriptor CONNECTION_EDIT_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionEdit.png"); //$NON-NLS-1$ |
62 private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = |
115 private static final ImageDescriptor SERVICE_TEST_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/serviceTest.png"); //$NON-NLS-1$ |
63 RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ |
116 private static final ImageDescriptor CONNECTION_REFRESH_IMGDESC = RemoteConnectionsActivator.getImageDescriptor("icons/connectionRefresh.png"); //$NON-NLS-1$ |
64 private static final ImageDescriptor STATUS_UNK_IMGDESC = |
117 |
65 RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$ |
|
66 private static final ImageDescriptor CONNECTION_IMGDESC = |
|
67 RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$ |
|
68 private static final ImageDescriptor CONNECTION_NEW_IMGDESC = |
|
69 RemoteConnectionsActivator.getImageDescriptor("icons/connectionNew.png"); //$NON-NLS-1$ |
|
70 private static final ImageDescriptor CONNECTION_EDIT_IMGDESC = |
|
71 RemoteConnectionsActivator.getImageDescriptor("icons/connectionEdit.png"); //$NON-NLS-1$ |
|
72 private static final ImageDescriptor SERVICE_TEST_IMGDESC = |
|
73 RemoteConnectionsActivator.getImageDescriptor("icons/serviceTest.png"); //$NON-NLS-1$ |
|
74 private static final ImageDescriptor STATUS_INUSE_IMGDESC = |
|
75 RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ |
|
76 private static final ImageDescriptor CONNECTION_REFRESH_IMGDESC = |
|
77 RemoteConnectionsActivator.getImageDescriptor("icons/connectionRefresh.png"); //$NON-NLS-1$ |
|
78 private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage(); |
|
79 private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage(); |
|
80 private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage(); |
|
81 private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage(); |
|
82 private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); |
|
83 private static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); |
|
84 private static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); |
|
85 private static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); |
|
86 private static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); |
|
87 private static final String NEW_ACTION = "ConnectionsView.new"; //$NON-NLS-1$ |
118 private static final String NEW_ACTION = "ConnectionsView.new"; //$NON-NLS-1$ |
88 private static final String EDIT_ACTION = "ConnectionsView.edit"; //$NON-NLS-1$ |
119 private static final String EDIT_ACTION = "ConnectionsView.edit"; //$NON-NLS-1$ |
89 private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ |
120 private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ |
90 private static final String ENABLE_SERVICE_ACTION = "ConnectionsView.enableService"; //$NON-NLS-1$ |
121 private static final String ENABLE_SERVICE_ACTION = "ConnectionsView.enableService"; //$NON-NLS-1$ |
91 private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ |
122 private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ |
92 private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ |
123 private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ |
93 private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ |
124 private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ |
|
125 private static final String SET_CURRENT_ACTION = "ConnectionsView.makeCurrent"; //$NON-NLS-1$ |
94 private KeyAdapter keyListener; |
126 private KeyAdapter keyListener; |
95 private boolean isDisposed; |
127 private boolean isDisposed; |
|
128 |
|
129 // handle, do not dispose |
|
130 private Font boldViewerFont; |
96 |
131 |
97 private TreeNode[] loadConnections() { |
132 private TreeNode[] loadConnections() { |
98 if (serviceToListenerMap == null) |
133 if (serviceToListenerMap == null) |
99 serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>(); |
134 serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>(); |
100 removeServiceListeners(); |
135 removeServiceListeners(); |
101 List<TreeNode> connectionNodes = new ArrayList<TreeNode>(); |
136 List<TreeNode> connectionNodes = new ArrayList<TreeNode>(); |
102 Collection<IConnection> connections = |
137 Collection<IConnection> connections = |
103 RemoteConnectionsActivator.getConnectionsManager().getConnections(); |
138 Registry.instance().getConnections(); |
104 for (IConnection connection : connections) { |
139 for (IConnection connection : connections) { |
105 // create a node for the connection |
140 // create a node for the connection |
106 TreeNode connectionNode = new TreeNode(connection); |
141 TreeNode connectionNode = new TreeNode(connection); |
107 // create subnodes for the connected services |
142 // create subnodes for the connected services |
108 List<TreeNode> serviceNodes = new ArrayList<TreeNode>(); |
143 List<TreeNode> serviceNodes = new ArrayList<TreeNode>(); |
109 Collection<IConnectedService> connectedServicesForConnection = |
144 Collection<IConnectedService> connectedServicesForConnection = |
110 RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
145 Registry.instance().getConnectedServices(connection); |
111 for (IConnectedService connectedService : connectedServicesForConnection) { |
146 for (IConnectedService connectedService : connectedServicesForConnection) { |
112 final TreeNode treeNode = new TreeNode(connectedService); |
147 final TreeNode treeNode = new TreeNode(connectedService); |
113 IStatusChangedListener statusChangedListener = new IStatusChangedListener() { |
148 IStatusChangedListener statusChangedListener = new IStatusChangedListener() { |
114 public void statusChanged(final IStatus status) { |
149 public void statusChanged(final IStatus status) { |
115 Display.getDefault().asyncExec(new Runnable() { |
150 Display.getDefault().asyncExec(new Runnable() { |
165 |
201 |
166 @Override |
202 @Override |
167 protected void setValue(Object element, Object value) { |
203 protected void setValue(Object element, Object value) { |
168 IConnection connection = (IConnection) ((TreeNode) element).getValue(); |
204 IConnection connection = (IConnection) ((TreeNode) element).getValue(); |
169 connection.setDisplayName(value.toString()); |
205 connection.setDisplayName(value.toString()); |
170 viewer.refresh(true); |
206 //viewer.refresh(true); |
171 packColumns(); |
207 //packColumns(); |
172 RemoteConnectionsActivator.getConnectionsManager().storeConnections(); |
208 Registry.instance().updateDisplays(); |
|
209 Registry.instance().storeConnections(); |
173 } |
210 } |
174 } |
211 } |
175 |
212 |
176 private class NameLabelProvider extends ColumnLabelProvider { |
213 private class NameLabelProvider extends ColumnLabelProvider { |
177 |
214 |
178 public String getText(Object obj) { |
215 public String getText(Object obj) { |
179 return getNodeDisplayName(obj); |
216 return getNodeDisplayName(obj); |
|
217 } |
|
218 |
|
219 /* (non-Javadoc) |
|
220 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) |
|
221 */ |
|
222 @Override |
|
223 public Font getFont(Object element) { |
|
224 if (element instanceof TreeNode) { |
|
225 if (((TreeNode)element).getValue().equals(Registry.instance().getCurrentConnection())) { |
|
226 return boldViewerFont; |
|
227 } |
|
228 } |
|
229 return super.getFont(element); |
180 } |
230 } |
181 |
231 |
182 public Image getImage(Object obj) { |
232 public Image getImage(Object obj) { |
183 TreeNode node = (TreeNode) obj; |
233 TreeNode node = (TreeNode) obj; |
184 Object value = node.getValue(); |
234 Object value = node.getValue(); |
185 if (value instanceof IConnection) { |
235 if (value instanceof IConnection) { |
186 if (isConnectionInUse((IConnection) value)) { |
236 return ConnectionUIUtils.getConnectionImage((IConnection) value); |
187 return STATUS_INUSE_IMG; |
|
188 } |
|
189 return CONNECTION_IMG; |
|
190 } |
237 } |
191 else if (value instanceof IConnectedService) { |
238 else if (value instanceof IConnectedService) { |
192 EStatus status = ((IConnectedService) value).getStatus().getEStatus(); |
239 EStatus status = ((IConnectedService) value).getStatus().getEStatus(); |
193 IConnection connection = findConnection((IConnectedService) value); |
240 IConnection connection = findConnection((IConnectedService) value); |
194 if (connection != null && isConnectionInUse(connection)) |
241 if (connection != null && ConnectionUIUtils.isSomeServiceInUse(connection)) |
195 status = EStatus.IN_USE; |
242 status = EStatus.IN_USE; |
196 switch (status) { |
243 return ConnectionUIUtils.getConnectedServiceStatusImage(status); |
197 case DOWN: |
|
198 return STATUS_UNAVAIL_IMG; |
|
199 case UP: |
|
200 return STATUS_AVAIL_IMG; |
|
201 case IN_USE: |
|
202 return CONNECTION_IMG; |
|
203 case UNKNOWN: |
|
204 return STATUS_UNK_IMG; |
|
205 } |
|
206 } |
244 } |
207 return null; |
245 return null; |
208 } |
246 } |
209 } |
247 } |
210 |
248 |
605 action = new Action(Messages.getString("ConnectionsView.DeleteActionLabel"), //$NON-NLS-1$ |
719 action = new Action(Messages.getString("ConnectionsView.DeleteActionLabel"), //$NON-NLS-1$ |
606 PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { |
720 PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { |
607 @Override |
721 @Override |
608 public void run() { |
722 public void run() { |
609 ISelection selection = viewer.getSelection(); |
723 ISelection selection = viewer.getSelection(); |
610 if (selection.isEmpty()) |
724 if (selection.isEmpty() || !canBeEdited(selection)) |
611 return; |
725 return; |
612 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
726 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
613 Object value = node.getValue(); |
727 Object value = node.getValue(); |
614 if (value instanceof IConnection) { |
728 if (value instanceof IConnection) { |
615 RemoteConnectionsActivator.getConnectionsManager().removeConnection((IConnection) value); |
729 Registry.instance().removeConnection((IConnection) value); |
616 RemoteConnectionsActivator.getConnectionsManager().storeConnections(); |
730 Registry.instance().storeConnections(); |
617 } |
731 } |
|
732 } |
|
733 |
|
734 @Override |
|
735 public boolean isEnabled() { |
|
736 return selectionCanBeEdited(); |
618 } |
737 } |
619 }; |
738 }; |
620 action.setAccelerator(SWT.DEL); |
739 action.setAccelerator(SWT.DEL); |
621 action.setId(DELETE_ACTION); |
740 action.setId(DELETE_ACTION); |
622 actions.add(action); |
741 actions.add(action); |
623 connectionSelectedActions.add(action); |
742 connectionSelectedActions.add(action); |
624 |
743 |
625 Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); |
744 Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); |
626 ImageDescriptor desc = ImageDescriptor.createFromImage(image); |
745 ImageDescriptor desc = ImageDescriptor.createFromImage(image); |
627 action = new Action(Messages.getString("ConnectionsView.HelpActionLabel"), desc) { //$NON-NLS-1$ |
746 action = new Action(Messages.getString("ConnectionsView.NoHelpActionLabel"), desc) { //$NON-NLS-1$ |
628 |
747 |
629 private String getHelpContextFromSelection() { |
748 private String getHelpContextFromSelection() { |
630 ISelection selection = viewer.getSelection(); |
749 IConnection connection = getSelectedConnection(); |
631 if (!selection.isEmpty()) { |
750 if (connection != null) { |
632 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
751 return connection.getConnectionType().getHelpContext(); |
633 Object value = treeNode.getValue(); |
|
634 if (value instanceof IConnection) { |
|
635 return ((IConnection) value).getConnectionType().getHelpContext(); |
|
636 } |
|
637 } |
752 } |
638 return null; |
753 return null; |
|
754 } |
|
755 |
|
756 @Override |
|
757 public String getText() { |
|
758 if (isEnabled()) { |
|
759 IConnection connection = getSelectedConnection(); |
|
760 IConnectionType connectionType = connection.getConnectionType(); |
|
761 String displayName = connectionType.getDisplayName(); |
|
762 String pattern = Messages.getString("ConnectionsView.HelpActionLabel"); //$NON-NLS-1$ |
|
763 return MessageFormat.format(pattern, displayName); |
|
764 } |
|
765 return super.getText(); |
639 } |
766 } |
640 |
767 |
641 @Override |
768 @Override |
642 public boolean isEnabled() { |
769 public boolean isEnabled() { |
643 return getHelpContextFromSelection() != null; |
770 return getHelpContextFromSelection() != null; |
705 serviceToListenerMap.clear(); |
851 serviceToListenerMap.clear(); |
706 } |
852 } |
707 |
853 |
708 private void disableAllConnectedServices() { |
854 private void disableAllConnectedServices() { |
709 Collection<IConnection> connections = |
855 Collection<IConnection> connections = |
710 RemoteConnectionsActivator.getConnectionsManager().getConnections(); |
856 Registry.instance().getConnections(); |
711 for (IConnection connection : connections) { |
857 for (IConnection connection : connections) { |
712 Collection<IConnectedService> connectedServicesForConnection = |
858 Collection<IConnectedService> connectedServicesForConnection = |
713 RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
859 Registry.instance().getConnectedServices(connection); |
714 for (IConnectedService connectedService : connectedServicesForConnection) { |
860 for (IConnectedService connectedService : connectedServicesForConnection) { |
715 connectedService.setEnabled(false); |
861 connectedService.setEnabled(false); |
716 } |
862 } |
717 } |
863 } |
718 } |
864 } |
719 |
865 |
720 @Override |
866 @Override |
721 public void dispose() { |
867 public void dispose() { |
722 removeServiceListeners(); |
868 removeServiceListeners(); |
723 RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(connectionStoreChangedListener); |
869 Registry.instance().removeConnectionStoreChangedListener(connectionStoreChangedListener); |
|
870 Registry.instance().removeConnectionListener(connectionListener); |
724 disableAllConnectedServices(); |
871 disableAllConnectedServices(); |
725 isDisposed = true; |
872 isDisposed = true; |
726 super.dispose(); |
873 super.dispose(); |
727 } |
874 } |
728 |
875 |
729 private static IConnection findConnection(IConnectedService cs) { |
876 private static IConnection findConnection(IConnectedService cs) { |
730 for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) { |
877 for (IConnection connection : Registry.instance().getConnections()) { |
731 for (IConnectedService connectedService : RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection)) { |
878 for (IConnectedService connectedService : Registry.instance().getConnectedServices(connection)) { |
732 if (cs.equals(connectedService)) |
879 if (cs.equals(connectedService)) |
733 return connection; |
880 return connection; |
734 } |
881 } |
735 } |
882 } |
736 return null; |
883 return null; |
737 } |
884 } |
738 |
885 |
739 private static IStatus getFirstInUseStatus(IConnection connection) { |
886 private static boolean isDynamicConnection(Object object) { |
740 Collection<IConnectedService> connectedServices = |
887 return object instanceof IConnection2 && ((IConnection2) object).isDynamic(); |
741 RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
888 } |
742 // if any service is in-use, then connection is in-use |
889 |
743 for (IConnectedService connectedService : connectedServices) { |
890 private boolean selectionCanBeEdited() { |
744 IStatus status = connectedService.getStatus(); |
891 ISelection selection = viewer.getSelection(); |
745 if (status.getEStatus().equals(EStatus.IN_USE)) |
892 return canBeEdited(selection); |
746 return status; |
893 } |
747 } |
894 |
748 |
895 private static boolean canBeEdited(ISelection selection) { |
|
896 if (selection.isEmpty()) |
|
897 return false; |
|
898 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
899 return !isDynamicConnection(node.getValue()); |
|
900 } |
|
901 |
|
902 private IConnection getSelectedConnection() { |
|
903 ISelection selection = viewer.getSelection(); |
|
904 if (!selection.isEmpty()) { |
|
905 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
906 Object value = treeNode.getValue(); |
|
907 if (value instanceof IConnection) { |
|
908 return (IConnection) value; |
|
909 } |
|
910 } |
749 return null; |
911 return null; |
750 } |
912 } |
751 |
913 |
752 private boolean isConnectionInUse(IConnection connection) { |
914 public void setSelectedConnection(IConnection connection) { |
753 return getFirstInUseStatus(connection) != null; |
915 if (viewer != null && !viewer.getControl().isDisposed()) { |
754 } |
916 if (connection != null) { |
755 |
917 TreeNode node = new TreeNode(connection); |
|
918 viewer.setSelection(new StructuredSelection(node)); |
|
919 } else { |
|
920 viewer.setSelection(null); |
|
921 } |
|
922 } |
|
923 } |
756 } |
924 } |
757 |
925 |