author | dadubrow |
Mon, 06 Apr 2009 14:33:24 -0500 | |
branch | RCL_2_0 |
changeset 55 | 8254273d11c0 |
parent 2 | d760517a8095 |
child 163 | b25acbfc406a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
package com.nokia.carbide.remoteconnections.view; |
|
20 |
||
21 |
import com.nokia.carbide.remoteconnections.Messages; |
|
22 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
23 |
import com.nokia.carbide.remoteconnections.interfaces.*; |
|
24 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
|
25 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
|
26 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
27 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
|
28 |
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
29 |
import com.nokia.cpp.internal.api.utils.core.TextUtils; |
2 | 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 |
||
46 |
||
47 |
/** |
|
48 |
* The view part for Remote connections |
|
49 |
*/ |
|
50 |
public class ConnectionsView extends ViewPart { |
|
51 |
||
52 |
private TreeViewer viewer; |
|
53 |
private IConnectionsManagerListener connectionStoreChangedListener; |
|
54 |
private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap; |
|
55 |
private List<Action> actions; |
|
56 |
private List<Action> connectionSelectedActions; |
|
57 |
private List<Action> serviceSelectedActions; |
|
58 |
private static final String UID = ".uid"; //$NON-NLS-1$ |
|
59 |
||
60 |
private static final ImageDescriptor STATUS_AVAIL_IMGDESC = |
|
61 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ |
|
62 |
private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = |
|
63 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ |
|
64 |
private static final ImageDescriptor STATUS_UNK_IMGDESC = |
|
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); |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
85 |
private static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); |
2 | 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$ |
|
88 |
private static final String EDIT_ACTION = "ConnectionsView.edit"; //$NON-NLS-1$ |
|
89 |
private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ |
|
90 |
private static final String ENABLE_SERVICE_ACTION = "ConnectionsView.enableService"; //$NON-NLS-1$ |
|
91 |
private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ |
|
92 |
private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ |
|
93 |
private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ |
|
94 |
private KeyAdapter keyListener; |
|
95 |
private boolean isDisposed; |
|
96 |
||
97 |
private TreeNode[] loadConnections() { |
|
98 |
if (serviceToListenerMap == null) |
|
99 |
serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>(); |
|
100 |
removeServiceListeners(); |
|
101 |
List<TreeNode> connectionNodes = new ArrayList<TreeNode>(); |
|
102 |
Collection<IConnection> connections = |
|
103 |
RemoteConnectionsActivator.getConnectionsManager().getConnections(); |
|
104 |
for (IConnection connection : connections) { |
|
105 |
// create a node for the connection |
|
106 |
TreeNode connectionNode = new TreeNode(connection); |
|
107 |
// create subnodes for the connected services |
|
108 |
List<TreeNode> serviceNodes = new ArrayList<TreeNode>(); |
|
109 |
Collection<IConnectedService> connectedServicesForConnection = |
|
110 |
RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
|
111 |
for (IConnectedService connectedService : connectedServicesForConnection) { |
|
112 |
final TreeNode treeNode = new TreeNode(connectedService); |
|
113 |
IStatusChangedListener statusChangedListener = new IStatusChangedListener() { |
|
114 |
public void statusChanged(final IStatus status) { |
|
115 |
Display.getDefault().asyncExec(new Runnable() { |
|
116 |
public void run() { |
|
117 |
if (!isDisposed) { |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
118 |
viewer.refresh(true); |
2 | 119 |
packColumns(); |
120 |
} |
|
121 |
} |
|
122 |
}); |
|
123 |
} |
|
124 |
}; |
|
125 |
connectedService.addStatusChangedListener(statusChangedListener); |
|
126 |
serviceToListenerMap.put(connectedService, statusChangedListener); |
|
127 |
connectedService.setEnabled(true); |
|
128 |
serviceNodes.add(treeNode); |
|
129 |
} |
|
130 |
for (TreeNode serviceNode : serviceNodes) { |
|
131 |
serviceNode.setParent(connectionNode); |
|
132 |
} |
|
133 |
connectionNode.setChildren((TreeNode[]) serviceNodes.toArray(new TreeNode[serviceNodes.size()])); |
|
134 |
connectionNodes.add(connectionNode); |
|
135 |
} |
|
136 |
||
137 |
return (TreeNode[]) connectionNodes.toArray(new TreeNode[connectionNodes.size()]); |
|
138 |
} |
|
139 |
||
140 |
private class NameEditingSupport extends EditingSupport { |
|
141 |
private TextCellEditor editor; |
|
142 |
||
143 |
private NameEditingSupport(ColumnViewer viewer) { |
|
144 |
super(viewer); |
|
145 |
editor = new TextCellEditor((Composite) viewer.getControl(), SWT.BORDER); |
|
146 |
} |
|
147 |
||
148 |
@Override |
|
149 |
protected boolean canEdit(Object element) { |
|
150 |
if (((TreeNode) element).getValue() instanceof IConnection) |
|
151 |
return true; |
|
152 |
return false; |
|
153 |
} |
|
154 |
||
155 |
@Override |
|
156 |
protected CellEditor getCellEditor(Object element) { |
|
157 |
return editor; |
|
158 |
} |
|
159 |
||
160 |
@Override |
|
161 |
protected Object getValue(Object element) { |
|
162 |
IConnection connection = (IConnection) ((TreeNode) element).getValue(); |
|
163 |
return connection.getDisplayName(); |
|
164 |
} |
|
165 |
||
166 |
@Override |
|
167 |
protected void setValue(Object element, Object value) { |
|
168 |
IConnection connection = (IConnection) ((TreeNode) element).getValue(); |
|
169 |
connection.setDisplayName(value.toString()); |
|
170 |
viewer.refresh(true); |
|
171 |
packColumns(); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
private class NameLabelProvider extends ColumnLabelProvider { |
|
176 |
||
177 |
public String getText(Object obj) { |
|
178 |
return getNodeDisplayName(obj); |
|
179 |
} |
|
180 |
||
181 |
public Image getImage(Object obj) { |
|
182 |
TreeNode node = (TreeNode) obj; |
|
183 |
Object value = node.getValue(); |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
184 |
if (value instanceof IConnection) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
185 |
if (isConnectionInUse((IConnection) value)) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
186 |
return STATUS_INUSE_IMG; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
187 |
} |
2 | 188 |
return CONNECTION_IMG; |
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
189 |
} |
2 | 190 |
else if (value instanceof IConnectedService) { |
191 |
EStatus status = ((IConnectedService) value).getStatus().getEStatus(); |
|
192 |
switch (status) { |
|
193 |
case DOWN: |
|
194 |
return STATUS_UNAVAIL_IMG; |
|
195 |
case UP: |
|
196 |
return STATUS_AVAIL_IMG; |
|
197 |
case IN_USE: |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
198 |
return CONNECTION_IMG; |
2 | 199 |
case UNKNOWN: |
200 |
return STATUS_UNK_IMG; |
|
201 |
} |
|
202 |
} |
|
203 |
return null; |
|
204 |
} |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
205 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
206 |
private boolean isConnectionInUse(IConnection connection) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
207 |
Collection<IConnectedService> connectedServices = |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
208 |
RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
209 |
// if any service is in-use, then connection is in-use |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
210 |
for (IConnectedService connectedService : connectedServices) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
211 |
IStatus status = connectedService.getStatus(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
212 |
if (status.getEStatus().equals(EStatus.IN_USE)) |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
213 |
return true; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
214 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
215 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
216 |
return false; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
217 |
} |
2 | 218 |
} |
219 |
||
220 |
private class StatusLabelProvider extends ColumnLabelProvider { |
|
221 |
||
222 |
public String getText(Object obj) { |
|
223 |
TreeNode node = (TreeNode) obj; |
|
224 |
Object value = node.getValue(); |
|
225 |
if (value instanceof IConnectedService) { |
|
226 |
IStatus status = ((IConnectedService) value).getStatus(); |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
227 |
if (!status.getEStatus().equals(EStatus.IN_USE)) // if in-use, we show it in the connection row |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
228 |
return status.getShortDescription(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
229 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
230 |
else if (value instanceof IConnection) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
231 |
IStatus status = getFirstInUseStatus((IConnection) value); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
232 |
if (status != null) |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
233 |
return status.getShortDescription(); |
2 | 234 |
} |
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
235 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
236 |
return null; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
237 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
238 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
239 |
private IStatus getFirstInUseStatus(IConnection connection) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
240 |
Collection<IConnectedService> connectedServices = |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
241 |
RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
242 |
// if any service is in-use, then connection is in-use |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
243 |
for (IConnectedService connectedService : connectedServices) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
244 |
IStatus status = connectedService.getStatus(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
245 |
if (status.getEStatus().equals(EStatus.IN_USE)) |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
246 |
return status; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
247 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
248 |
|
2 | 249 |
return null; |
250 |
} |
|
251 |
||
252 |
@Override |
|
253 |
public Color getForeground(Object obj) { |
|
254 |
TreeNode node = (TreeNode) obj; |
|
255 |
Object value = node.getValue(); |
|
256 |
if (value instanceof IConnectedService) { |
|
257 |
EStatus status = ((IConnectedService) value).getStatus().getEStatus(); |
|
258 |
switch (status) { |
|
259 |
case DOWN: |
|
260 |
return COLOR_RED; |
|
261 |
case UP: |
|
262 |
return COLOR_GREEN; |
|
263 |
case UNKNOWN: |
|
264 |
return COLOR_GREY; |
|
265 |
} |
|
266 |
} |
|
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
267 |
else if (value instanceof IConnection) // only showing in-use for connections |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
268 |
return COLOR_ELECTRIC; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
269 |
|
2 | 270 |
return null; |
271 |
} |
|
272 |
} |
|
273 |
||
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
274 |
public class DescriptionLabelProvider extends ColumnLabelProvider { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
275 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
276 |
@Override |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
277 |
public String getText(Object obj) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
278 |
TreeNode node = (TreeNode) obj; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
279 |
Object value = node.getValue(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
280 |
if (value instanceof IConnectedService) { |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
281 |
IStatus status = ((IConnectedService) value).getStatus(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
282 |
if (!status.getEStatus().equals(EStatus.IN_USE)) { // if in-use, we show it in the connection row |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
283 |
String longDescription = status.getLongDescription(); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
284 |
if (longDescription != null) |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
285 |
longDescription = TextUtils.canonicalizeNewlines(longDescription, " "); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
286 |
return longDescription; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
287 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
288 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
289 |
|
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
290 |
return null; |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
291 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
292 |
} |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
293 |
|
2 | 294 |
private class TypeLabelProvider extends ColumnLabelProvider { |
295 |
||
296 |
public String getText(Object obj) { |
|
297 |
TreeNode node = (TreeNode) obj; |
|
298 |
Object value = node.getValue(); |
|
299 |
if (value instanceof IConnection) { |
|
300 |
return ((IConnection) value).getConnectionType().getDisplayName(); |
|
301 |
} |
|
302 |
return null; |
|
303 |
} |
|
304 |
} |
|
305 |
||
306 |
private class EnableConnectedServiceAction extends Action { |
|
307 |
private EnableConnectedServiceAction() { |
|
308 |
super("", SERVICE_TEST_IMGDESC); //$NON-NLS-1$ |
|
309 |
} |
|
310 |
||
311 |
private IConnectedService getSelectedConnectedService() { |
|
312 |
ISelection selection = viewer.getSelection(); |
|
313 |
if (selection.isEmpty()) |
|
314 |
return null; |
|
315 |
TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
316 |
Object value = node.getValue(); |
|
317 |
if (value instanceof IConnectedService) { |
|
318 |
return (IConnectedService) value; |
|
319 |
} |
|
320 |
return null; |
|
321 |
} |
|
322 |
||
323 |
@Override |
|
324 |
public void run() { |
|
325 |
IConnectedService connectedService = getSelectedConnectedService(); |
|
326 |
if (connectedService != null) { |
|
327 |
connectedService.setEnabled(!connectedService.isEnabled()); |
|
328 |
updateLabel(); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
public void updateLabel() { |
|
333 |
IConnectedService connectedService = getSelectedConnectedService(); |
|
334 |
if (connectedService == null) |
|
335 |
return; |
|
336 |
String label = connectedService.isEnabled() ? |
|
337 |
Messages.getString("ConnectionsView.DisableTestActionLabel") : //$NON-NLS-1$ |
|
338 |
Messages.getString("ConnectionsView.EnableTestActionLabel"); //$NON-NLS-1$ |
|
339 |
setText(label); |
|
340 |
} |
|
341 |
||
342 |
@Override |
|
343 |
public void setEnabled(boolean enabled) { |
|
344 |
super.setEnabled(enabled); |
|
345 |
updateLabel(); |
|
346 |
} |
|
347 |
||
348 |
@Override |
|
349 |
public boolean isEnabled() { |
|
350 |
IConnectedService connectedService = getSelectedConnectedService(); |
|
351 |
return connectedService != null && connectedService.getService().isTestable(); |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
/* (non-Javadoc) |
|
356 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
357 |
*/ |
|
358 |
public void createPartControl(Composite parent) { |
|
359 |
viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL); |
|
360 |
||
361 |
TreeViewerColumn nameColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
|
362 |
nameColumn.setLabelProvider(new TreeColumnViewerLabelProvider(new NameLabelProvider())); |
|
363 |
nameColumn.getColumn().setText(Messages.getString("ConnectionsView.NameColumnHeader")); //$NON-NLS-1$ |
|
364 |
nameColumn.setEditingSupport(new NameEditingSupport(nameColumn.getViewer())); |
|
365 |
ColumnViewerEditorActivationStrategy activationStrategy = new ColumnViewerEditorActivationStrategy(nameColumn.getViewer()) { |
|
366 |
@Override |
|
367 |
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { |
|
368 |
return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
|
369 |
} |
|
370 |
}; |
|
371 |
TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT); |
|
372 |
||
373 |
TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
|
374 |
typeColumn.setLabelProvider(new TypeLabelProvider()); |
|
375 |
typeColumn.getColumn().setText(Messages.getString("ConnectionsView.TypeColumnHeader")); //$NON-NLS-1$ |
|
376 |
||
377 |
TreeViewerColumn statusColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
|
378 |
statusColumn.setLabelProvider(new StatusLabelProvider()); |
|
379 |
statusColumn.getColumn().setText(Messages.getString("ConnectionsView.StatusColumnHeader")); //$NON-NLS-1$ |
|
380 |
||
55
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
381 |
TreeViewerColumn descriptionColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
382 |
descriptionColumn.setLabelProvider(new DescriptionLabelProvider()); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
383 |
descriptionColumn.getColumn().setText("Description"); |
8254273d11c0
[Bug 8297] add description column to remote connections view with long description of status and move in-use UI to connection rather than displaying on each service - use blue color for in-use status text rather than yellow
dadubrow
parents:
2
diff
changeset
|
384 |
|
2 | 385 |
viewer.setContentProvider(new TreeNodeContentProvider()); |
386 |
viewer.setInput(loadConnections()); |
|
387 |
viewer.expandAll(); |
|
388 |
viewer.getTree().setHeaderVisible(true); |
|
389 |
viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$ |
|
390 |
viewer.setSorter(new ViewerSorter() { |
|
391 |
@Override |
|
392 |
public int compare(Viewer viewer, Object e1, Object e2) { |
|
393 |
return getNodeDisplayName(e1).compareToIgnoreCase(getNodeDisplayName(e2)); |
|
394 |
} |
|
395 |
}); |
|
396 |
viewer.addSelectionChangedListener(new ISelectionChangedListener() { |
|
397 |
public void selectionChanged(SelectionChangedEvent event) { |
|
398 |
enableConnectionSelectedActions(false); |
|
399 |
enableServiceSelectedActions(false); |
|
400 |
ISelection selection = event.getSelection(); |
|
401 |
if (!selection.isEmpty()) { |
|
402 |
IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
|
403 |
TreeNode treeNode = (TreeNode) structuredSelection.getFirstElement(); |
|
404 |
Object value = treeNode.getValue(); |
|
405 |
if (value instanceof IConnection) { |
|
406 |
enableConnectionSelectedActions(true); |
|
407 |
} |
|
408 |
else if (value instanceof IConnectedService) { |
|
409 |
enableServiceSelectedActions(true); |
|
410 |
} |
|
411 |
} |
|
412 |
} |
|
413 |
}); |
|
414 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
|
415 |
public void doubleClick(DoubleClickEvent event) { |
|
416 |
ISelection selection = event.getSelection(); |
|
417 |
if (!selection.isEmpty()) { |
|
418 |
IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
|
419 |
TreeNode treeNode = (TreeNode) structuredSelection.getFirstElement(); |
|
420 |
Object value = treeNode.getValue(); |
|
421 |
if (value instanceof IConnection) { |
|
422 |
SettingsWizard wizard = new SettingsWizard((IConnection) value); |
|
423 |
wizard.open(getViewSite().getShell()); |
|
424 |
} |
|
425 |
else if (value instanceof IConnectedService) { |
|
426 |
IConnectedService connectedService = (IConnectedService) value; |
|
427 |
connectedService.setEnabled(true); |
|
428 |
connectedService.testStatus(); |
|
429 |
((EnableConnectedServiceAction) getAction(ENABLE_SERVICE_ACTION)).updateLabel(); |
|
430 |
} |
|
431 |
} |
|
432 |
} |
|
433 |
}); |
|
434 |
||
435 |
packColumns(); |
|
436 |
||
437 |
makeActions(); |
|
438 |
hookContextMenu(); |
|
439 |
contributeToActionBars(); |
|
440 |
hookAccelerators(); |
|
441 |
||
442 |
connectionStoreChangedListener = new IConnectionsManagerListener() { |
|
443 |
public void connectionStoreChanged() { |
|
444 |
Display.getDefault().asyncExec(new Runnable() { |
|
445 |
public void run() { |
|
446 |
viewer.setInput(loadConnections()); |
|
447 |
viewer.expandAll(); |
|
448 |
packColumns(); |
|
449 |
if (viewer.getSelection().isEmpty() && viewer.getTree().getItemCount() > 0) { |
|
450 |
TreeItem item = viewer.getTree().getItem(0); |
|
451 |
if (item != null) { |
|
452 |
viewer.getTree().select(item); |
|
453 |
} |
|
454 |
} |
|
455 |
viewer.setSelection(viewer.getSelection()); // force selection changed |
|
456 |
} |
|
457 |
}); |
|
458 |
} |
|
459 |
||
460 |
public void displayChanged() { |
|
461 |
Display.getDefault().asyncExec(new Runnable() { |
|
462 |
public void run() { |
|
463 |
viewer.refresh(true); |
|
464 |
packColumns(); |
|
465 |
} |
|
466 |
}); |
|
467 |
} |
|
468 |
}; |
|
469 |
RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(connectionStoreChangedListener); |
|
470 |
||
471 |
RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$ |
|
472 |
} |
|
473 |
||
474 |
private void packColumns() { |
|
475 |
TreeColumn[] columns = viewer.getTree().getColumns(); |
|
476 |
for (TreeColumn column : columns) { |
|
477 |
column.pack(); |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
private String getNodeDisplayName(Object obj) { |
|
482 |
Object value = ((TreeNode) obj).getValue(); |
|
483 |
if (value instanceof IConnection) |
|
484 |
return ((IConnection) value).getDisplayName(); |
|
485 |
else if (value instanceof IConnectedService) |
|
486 |
return ((IConnectedService) value).getService().getDisplayName(); |
|
487 |
||
488 |
return ""; //$NON-NLS-1$ |
|
489 |
} |
|
490 |
||
491 |
private void hookContextMenu() { |
|
492 |
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
|
493 |
menuMgr.setRemoveAllWhenShown(true); |
|
494 |
menuMgr.addMenuListener(new IMenuListener() { |
|
495 |
public void menuAboutToShow(IMenuManager manager) { |
|
496 |
ConnectionsView.this.fillContextMenu(manager); |
|
497 |
} |
|
498 |
}); |
|
499 |
Menu menu = menuMgr.createContextMenu(viewer.getControl()); |
|
500 |
viewer.getControl().setMenu(menu); |
|
501 |
getSite().registerContextMenu(menuMgr, viewer); |
|
502 |
} |
|
503 |
||
504 |
private void contributeToActionBars() { |
|
505 |
IActionBars bars = getViewSite().getActionBars(); |
|
506 |
fillLocalPullDown(bars.getMenuManager()); |
|
507 |
fillLocalToolBar(bars.getToolBarManager()); |
|
508 |
} |
|
509 |
||
510 |
private void fillLocalPullDown(IMenuManager manager) { |
|
511 |
// nothing for now |
|
512 |
} |
|
513 |
||
514 |
private void fillContextMenu(IMenuManager manager) { |
|
515 |
manager.add(getAction(NEW_ACTION)); |
|
516 |
ISelection selection = viewer.getSelection(); |
|
517 |
if (selection.isEmpty()) |
|
518 |
return; |
|
519 |
TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
520 |
Object value = node.getValue(); |
|
521 |
if (value instanceof IConnectedService) |
|
522 |
manager.add(getAction(ENABLE_SERVICE_ACTION)); |
|
523 |
else { |
|
524 |
manager.add(getAction(RENAME_ACTION)); |
|
525 |
manager.add(getAction(EDIT_ACTION)); |
|
526 |
manager.add(getAction(DELETE_ACTION)); |
|
527 |
manager.add(getAction(HELP_ACTION)); |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
private void fillLocalToolBar(IToolBarManager manager) { |
|
532 |
manager.add(getAction(REFRESH_ACTION)); |
|
533 |
manager.add(getAction(NEW_ACTION)); |
|
534 |
manager.add(getAction(EDIT_ACTION)); |
|
535 |
} |
|
536 |
||
537 |
private void makeActions() { |
|
538 |
actions = new ArrayList<Action>(); |
|
539 |
connectionSelectedActions = new ArrayList<Action>(); |
|
540 |
serviceSelectedActions = new ArrayList<Action>(); |
|
541 |
||
542 |
Action action = new Action(Messages.getString("ConnectionsView.NewActionLabel"), CONNECTION_NEW_IMGDESC) { //$NON-NLS-1$ |
|
543 |
@Override |
|
544 |
public void run() { |
|
545 |
SettingsWizard wizard = new SettingsWizard(); |
|
546 |
wizard.open(getViewSite().getShell()); |
|
547 |
} |
|
548 |
||
549 |
}; |
|
550 |
action.setId(NEW_ACTION); |
|
551 |
actions.add(action); |
|
552 |
action.setEnabled(!RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionTypes().isEmpty()); |
|
553 |
||
554 |
action = new Action(Messages.getString("ConnectionsView.EditActionLabel"), CONNECTION_EDIT_IMGDESC) { //$NON-NLS-1$ |
|
555 |
@Override |
|
556 |
public void run() { |
|
557 |
ISelection selection = viewer.getSelection(); |
|
558 |
if (selection.isEmpty()) |
|
559 |
return; |
|
560 |
TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
561 |
Object value = node.getValue(); |
|
562 |
if (value instanceof IConnection) { |
|
563 |
SettingsWizard wizard = new SettingsWizard((IConnection) value); |
|
564 |
wizard.open(getViewSite().getShell()); |
|
565 |
} |
|
566 |
} |
|
567 |
}; |
|
568 |
action.setId(EDIT_ACTION); |
|
569 |
actions.add(action); |
|
570 |
connectionSelectedActions.add(action); |
|
571 |
||
572 |
action = new Action() { |
|
573 |
@Override |
|
574 |
public void run() { |
|
575 |
ISelection selection = viewer.getSelection(); |
|
576 |
if (selection.isEmpty()) |
|
577 |
return; |
|
578 |
TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
579 |
Object value = node.getValue(); |
|
580 |
if (value instanceof IConnection) { |
|
581 |
viewer.editElement(node, 0); |
|
582 |
} |
|
583 |
} |
|
584 |
}; |
|
585 |
action.setId(RENAME_ACTION); |
|
586 |
action.setAccelerator(SWT.F2); |
|
587 |
action.setText(Messages.getString("ConnectionsView.RenameMenuLabel") + //$NON-NLS-1$ |
|
588 |
"\t" + //$NON-NLS-1$ |
|
589 |
LegacyActionTools.convertAccelerator(action.getAccelerator())); |
|
590 |
actions.add(action); |
|
591 |
connectionSelectedActions.add(action); |
|
592 |
||
593 |
action = new EnableConnectedServiceAction(); |
|
594 |
action.setId(ENABLE_SERVICE_ACTION); |
|
595 |
actions.add(action); |
|
596 |
serviceSelectedActions.add(action); |
|
597 |
||
598 |
action = new Action(Messages.getString("ConnectionsView.RefreshActionLabel"), CONNECTION_REFRESH_IMGDESC) { //$NON-NLS-1$ |
|
599 |
@Override |
|
600 |
public void run() { |
|
601 |
IConnectionsManager connectionsManager = RemoteConnectionsActivator.getConnectionsManager(); |
|
602 |
for (IConnection connection : connectionsManager.getConnections()) { |
|
603 |
Collection<IConnectedService> connectedServices = connectionsManager.getConnectedServices(connection); |
|
604 |
for (IConnectedService connectedService : connectedServices) { |
|
605 |
connectedService.setEnabled(true); |
|
606 |
connectedService.testStatus(); |
|
607 |
} |
|
608 |
} |
|
609 |
((EnableConnectedServiceAction) getAction(ENABLE_SERVICE_ACTION)).updateLabel(); |
|
610 |
} |
|
611 |
}; |
|
612 |
action.setAccelerator(SWT.F5); |
|
613 |
action.setId(REFRESH_ACTION); |
|
614 |
actions.add(action); |
|
615 |
||
616 |
action = new Action(Messages.getString("ConnectionsView.DeleteActionLabel"), //$NON-NLS-1$ |
|
617 |
PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { |
|
618 |
@Override |
|
619 |
public void run() { |
|
620 |
ISelection selection = viewer.getSelection(); |
|
621 |
if (selection.isEmpty()) |
|
622 |
return; |
|
623 |
TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
624 |
Object value = node.getValue(); |
|
625 |
if (value instanceof IConnection) { |
|
626 |
RemoteConnectionsActivator.getConnectionsManager().removeConnection((IConnection) value); |
|
627 |
RemoteConnectionsActivator.getConnectionsManager().storeConnections(); |
|
628 |
} |
|
629 |
} |
|
630 |
}; |
|
631 |
action.setAccelerator(SWT.DEL); |
|
632 |
action.setId(DELETE_ACTION); |
|
633 |
actions.add(action); |
|
634 |
connectionSelectedActions.add(action); |
|
635 |
||
636 |
Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); |
|
637 |
ImageDescriptor desc = ImageDescriptor.createFromImage(image); |
|
638 |
action = new Action(Messages.getString("ConnectionsView.HelpActionLabel"), desc) { //$NON-NLS-1$ |
|
639 |
||
640 |
private String getHelpContextFromSelection() { |
|
641 |
ISelection selection = viewer.getSelection(); |
|
642 |
if (!selection.isEmpty()) { |
|
643 |
TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
644 |
Object value = treeNode.getValue(); |
|
645 |
if (value instanceof IConnection) { |
|
646 |
return ((IConnection) value).getConnectionType().getHelpContext(); |
|
647 |
} |
|
648 |
} |
|
649 |
return null; |
|
650 |
} |
|
651 |
||
652 |
@Override |
|
653 |
public boolean isEnabled() { |
|
654 |
return getHelpContextFromSelection() != null; |
|
655 |
} |
|
656 |
||
657 |
@Override |
|
658 |
public void run() { |
|
659 |
PlatformUI.getWorkbench().getHelpSystem().displayHelp(getHelpContextFromSelection()); |
|
660 |
} |
|
661 |
}; |
|
662 |
action.setId(HELP_ACTION); |
|
663 |
actions.add(action); |
|
664 |
connectionSelectedActions.add(action); |
|
665 |
enableConnectionSelectedActions(false); |
|
666 |
enableServiceSelectedActions(false); |
|
667 |
} |
|
668 |
||
669 |
private void enableConnectionSelectedActions(boolean enable) { |
|
670 |
for (Action action : connectionSelectedActions) { |
|
671 |
action.setEnabled(enable); |
|
672 |
} |
|
673 |
} |
|
674 |
||
675 |
private void enableServiceSelectedActions(boolean enable) { |
|
676 |
for (Action action : serviceSelectedActions) { |
|
677 |
action.setEnabled(enable); |
|
678 |
} |
|
679 |
} |
|
680 |
||
681 |
private Action getAction(String id) { |
|
682 |
for (Action action : actions) { |
|
683 |
if (action.getId().equals(id)) |
|
684 |
return action; |
|
685 |
} |
|
686 |
||
687 |
return null; |
|
688 |
} |
|
689 |
||
690 |
private void hookAccelerators() { |
|
691 |
keyListener = new KeyAdapter() { |
|
692 |
public void keyPressed(KeyEvent e) { |
|
693 |
for (Action action : actions) { |
|
694 |
if (e.keyCode == action.getAccelerator()) { |
|
695 |
action.run(); |
|
696 |
break; |
|
697 |
} |
|
698 |
} |
|
699 |
} |
|
700 |
}; |
|
701 |
viewer.getControl().addKeyListener(keyListener); |
|
702 |
} |
|
703 |
||
704 |
/** |
|
705 |
* Passing the focus request to the viewer's control. |
|
706 |
*/ |
|
707 |
public void setFocus() { |
|
708 |
viewer.getControl().setFocus(); |
|
709 |
} |
|
710 |
||
711 |
private void removeServiceListeners() { |
|
712 |
for (IConnectedService connectedService : serviceToListenerMap.keySet()) { |
|
713 |
IStatusChangedListener listener = serviceToListenerMap.get(connectedService); |
|
714 |
connectedService.removeStatusChangedListener(listener); |
|
715 |
} |
|
716 |
serviceToListenerMap.clear(); |
|
717 |
} |
|
718 |
||
719 |
private void disableAllConnectedServices() { |
|
720 |
Collection<IConnection> connections = |
|
721 |
RemoteConnectionsActivator.getConnectionsManager().getConnections(); |
|
722 |
for (IConnection connection : connections) { |
|
723 |
Collection<IConnectedService> connectedServicesForConnection = |
|
724 |
RemoteConnectionsActivator.getConnectionsManager().getConnectedServices(connection); |
|
725 |
for (IConnectedService connectedService : connectedServicesForConnection) { |
|
726 |
connectedService.setEnabled(false); |
|
727 |
} |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
@Override |
|
732 |
public void dispose() { |
|
733 |
removeServiceListeners(); |
|
734 |
RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(connectionStoreChangedListener); |
|
735 |
disableAllConnectedServices(); |
|
736 |
isDisposed = true; |
|
737 |
super.dispose(); |
|
738 |
} |
|
739 |
||
740 |
} |
|
741 |