author | dadubrow |
Thu, 16 Sep 2010 09:17:01 -0500 | |
changeset 2028 | ff6b4aae1c1e |
parent 981 | 77bc8173ce83 |
child 2038 | dd457404f42f |
permissions | -rw-r--r-- |
706 | 1 |
/* |
2 |
* Copyright (c) 2009 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 |
package com.nokia.carbide.remoteconnections.internal.ui; |
|
19 |
||
20 |
import java.util.Collection; |
|
21 |
||
22 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
2028
ff6b4aae1c1e
Bug 11620 - provide support for links (including special support for installer page link) in description column of remote connections view
dadubrow
parents:
981
diff
changeset
|
23 |
import org.eclipse.jface.resource.JFaceColors; |
706 | 24 |
import org.eclipse.swt.graphics.Color; |
25 |
import org.eclipse.swt.graphics.Image; |
|
26 |
import org.eclipse.swt.widgets.Display; |
|
27 |
||
28 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
29 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
30 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
711 | 31 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
32 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
706 | 33 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
34 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
35 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
706 | 36 |
import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
37 |
||
38 |
/** |
|
39 |
* |
|
40 |
*/ |
|
41 |
public class ConnectionUIUtils { |
|
42 |
||
43 |
private static final ImageDescriptor STATUS_AVAIL_IMGDESC = |
|
44 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ |
|
45 |
private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = |
|
46 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ |
|
47 |
private static final ImageDescriptor STATUS_UNK_IMGDESC = |
|
48 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$ |
|
49 |
private static final ImageDescriptor STATUS_INUSE_IMGDESC = |
|
50 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ |
|
51 |
||
52 |
private static final ImageDescriptor CONNECTION_READY_IMGDESC = |
|
53 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusReady.png"); //$NON-NLS-1$ |
|
54 |
private static final ImageDescriptor CONNECTION_IN_USE_IMGDESC = |
|
55 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUse.png"); //$NON-NLS-1$ |
|
56 |
private static final ImageDescriptor CONNECTION_NOT_READY_IMGDESC = |
|
57 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusNotReady.png"); //$NON-NLS-1$ |
|
58 |
private static final ImageDescriptor CONNECTION_IN_USE_DISCONNECTED_IMGDESC = |
|
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
59 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUseDisconnected.png"); //$NON-NLS-1$ |
706 | 60 |
|
732
c6b80e0b9fe2
In Remote Connections view, wire up indication of default connection and menu item for switching it.
Ed Swartz <ed.swartz@nokia.com>
parents:
721
diff
changeset
|
61 |
public static final ImageDescriptor CONNECTION_IMGDESC = |
706 | 62 |
RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$ |
63 |
||
64 |
private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage(); |
|
65 |
private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage(); |
|
66 |
private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage(); |
|
67 |
private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage(); |
|
68 |
||
69 |
private static final Image CONNECTION_READY_IMG = CONNECTION_READY_IMGDESC.createImage(); |
|
70 |
private static final Image CONNECTION_IN_USE_IMG = CONNECTION_IN_USE_IMGDESC.createImage(); |
|
71 |
private static final Image CONNECTION_NOT_READY_IMG = CONNECTION_NOT_READY_IMGDESC.createImage(); |
|
72 |
private static final Image CONNECTION_IN_USE_DISCONNECTED_IMG = CONNECTION_IN_USE_DISCONNECTED_IMGDESC.createImage(); |
|
73 |
||
74 |
private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); |
|
75 |
||
76 |
public static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); |
|
77 |
public static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); |
|
78 |
public static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); |
|
79 |
public static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); |
|
2028
ff6b4aae1c1e
Bug 11620 - provide support for links (including special support for installer page link) in description column of remote connections view
dadubrow
parents:
981
diff
changeset
|
80 |
public static final Color COLOR_HYPERLINK = JFaceColors.getHyperlinkText(Display.getDefault()); |
706 | 81 |
|
82 |
/** |
|
83 |
* Get the image representing the connection status. |
|
84 |
* @param connection |
|
85 |
* @return Image, not to be disposed |
|
86 |
*/ |
|
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
87 |
public static Image getConnectionStatusImage(IConnectionStatus status) { |
706 | 88 |
if (status != null) { |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
89 |
EConnectionStatus severity = status.getEConnectionStatus(); |
706 | 90 |
|
91 |
switch (severity) { |
|
92 |
case READY: |
|
93 |
return CONNECTION_READY_IMG; |
|
94 |
case IN_USE: |
|
95 |
return CONNECTION_IN_USE_IMG; |
|
96 |
case NOT_READY: |
|
97 |
return CONNECTION_NOT_READY_IMG; |
|
98 |
case IN_USE_DISCONNECTED: |
|
99 |
return CONNECTION_IN_USE_DISCONNECTED_IMG; |
|
100 |
} |
|
101 |
} |
|
102 |
return ConnectionUIUtils.CONNECTION_IMG; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Get the image representing the connection status. |
|
107 |
* @param connection |
|
108 |
* @return Image, not to be disposed |
|
109 |
*/ |
|
110 |
public static Image getConnectionImage(IConnection connection) { |
|
721
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
111 |
// TODO: remove this when we have real statuses from a connection |
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
112 |
if (isSomeServiceInUse(connection)) { |
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
113 |
return ConnectionUIUtils.STATUS_INUSE_IMG; |
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
114 |
} |
706 | 115 |
if (connection instanceof IConnection2) { |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
116 |
IConnectionStatus status = ((IConnection2) connection).getStatus(); |
706 | 117 |
return getConnectionStatusImage(status); |
710
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
118 |
} else { |
721
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
119 |
// old connection logic |
711 | 120 |
if (isSomeServiceInUse(connection)) { |
710
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
121 |
return ConnectionUIUtils.STATUS_INUSE_IMG; |
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
122 |
} |
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
123 |
return ConnectionUIUtils.CONNECTION_IMG; |
706 | 124 |
} |
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* @param status |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
public static Image getConnectedServiceStatusImage(IConnectedService.IStatus.EStatus status) { |
|
132 |
switch (status) { |
|
133 |
case DOWN: |
|
134 |
return ConnectionUIUtils.STATUS_UNAVAIL_IMG; |
|
135 |
case UP: |
|
136 |
return ConnectionUIUtils.STATUS_AVAIL_IMG; |
|
137 |
case IN_USE: |
|
138 |
return ConnectionUIUtils.CONNECTION_IMG; |
|
139 |
case UNKNOWN: |
|
140 |
return ConnectionUIUtils.STATUS_UNK_IMG; |
|
141 |
} |
|
142 |
return null; |
|
143 |
} |
|
144 |
||
711 | 145 |
public static IStatus getFirstInUseServiceStatus(IConnection connection) { |
146 |
Collection<IConnectedService> connectedServices = |
|
147 |
Registry.instance().getConnectedServices(connection); |
|
148 |
// if any service is in-use, then connection is in-use |
|
981
77bc8173ce83
Fixes bug 10733. In Registry.getConnectedServices(IConnection), return empty collection instead of null. Use isEmpty() instead of == null for caller conditionals
John Dean <john.3.dean@nokia.com>
parents:
980
diff
changeset
|
149 |
if (connectedServices.isEmpty()) |
721
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
150 |
return null; |
dbd80b3d41cc
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents:
711
diff
changeset
|
151 |
|
711 | 152 |
for (IConnectedService connectedService : connectedServices) { |
153 |
IStatus status = connectedService.getStatus(); |
|
154 |
if (status.getEStatus().equals(EStatus.IN_USE)) |
|
155 |
return status; |
|
156 |
} |
|
157 |
||
158 |
return null; |
|
159 |
} |
|
160 |
||
161 |
public static boolean isSomeServiceInUse(IConnection connection) { |
|
162 |
return getFirstInUseServiceStatus(connection) != null; |
|
163 |
} |
|
706 | 164 |
} |