author | John Dean <john.3.dean@nokia.com> |
Wed, 17 Feb 2010 12:59:07 -0800 | |
changeset 980 | 2856f9bc4ddf |
parent 979 | 1dc37cfc99cd |
child 981 | 77bc8173ce83 |
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; |
|
23 |
import org.eclipse.swt.graphics.Color; |
|
24 |
import org.eclipse.swt.graphics.Image; |
|
25 |
import org.eclipse.swt.widgets.Display; |
|
26 |
||
27 |
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
|
28 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
29 |
import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
711 | 30 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
31 |
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
706 | 32 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
33 |
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
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.EConnectionStatus; |
706 | 35 |
import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
36 |
||
37 |
/** |
|
38 |
* |
|
39 |
*/ |
|
40 |
public class ConnectionUIUtils { |
|
41 |
||
42 |
private static final ImageDescriptor STATUS_AVAIL_IMGDESC = |
|
43 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ |
|
44 |
private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = |
|
45 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ |
|
46 |
private static final ImageDescriptor STATUS_UNK_IMGDESC = |
|
47 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$ |
|
48 |
private static final ImageDescriptor STATUS_INUSE_IMGDESC = |
|
49 |
RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ |
|
50 |
||
51 |
private static final ImageDescriptor CONNECTION_READY_IMGDESC = |
|
52 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusReady.png"); //$NON-NLS-1$ |
|
53 |
private static final ImageDescriptor CONNECTION_IN_USE_IMGDESC = |
|
54 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUse.png"); //$NON-NLS-1$ |
|
55 |
private static final ImageDescriptor CONNECTION_NOT_READY_IMGDESC = |
|
56 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusNotReady.png"); //$NON-NLS-1$ |
|
57 |
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
|
58 |
RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUseDisconnected.png"); //$NON-NLS-1$ |
706 | 59 |
|
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
|
60 |
public static final ImageDescriptor CONNECTION_IMGDESC = |
706 | 61 |
RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$ |
62 |
||
63 |
private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage(); |
|
64 |
private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage(); |
|
65 |
private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage(); |
|
66 |
private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage(); |
|
67 |
||
68 |
private static final Image CONNECTION_READY_IMG = CONNECTION_READY_IMGDESC.createImage(); |
|
69 |
private static final Image CONNECTION_IN_USE_IMG = CONNECTION_IN_USE_IMGDESC.createImage(); |
|
70 |
private static final Image CONNECTION_NOT_READY_IMG = CONNECTION_NOT_READY_IMGDESC.createImage(); |
|
71 |
private static final Image CONNECTION_IN_USE_DISCONNECTED_IMG = CONNECTION_IN_USE_DISCONNECTED_IMGDESC.createImage(); |
|
72 |
||
73 |
private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); |
|
74 |
||
75 |
public static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); |
|
76 |
public static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); |
|
77 |
public static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); |
|
78 |
public static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); |
|
79 |
||
80 |
/** |
|
81 |
* Get the image representing the connection status. |
|
82 |
* @param connection |
|
83 |
* @return Image, not to be disposed |
|
84 |
*/ |
|
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
85 |
public static Image getConnectionStatusImage(IConnectionStatus status) { |
706 | 86 |
if (status != null) { |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
87 |
EConnectionStatus severity = status.getEConnectionStatus(); |
706 | 88 |
|
89 |
switch (severity) { |
|
90 |
case READY: |
|
91 |
return CONNECTION_READY_IMG; |
|
92 |
case IN_USE: |
|
93 |
return CONNECTION_IN_USE_IMG; |
|
94 |
case NOT_READY: |
|
95 |
return CONNECTION_NOT_READY_IMG; |
|
96 |
case IN_USE_DISCONNECTED: |
|
97 |
return CONNECTION_IN_USE_DISCONNECTED_IMG; |
|
98 |
} |
|
99 |
} |
|
100 |
return ConnectionUIUtils.CONNECTION_IMG; |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* Get the image representing the connection status. |
|
105 |
* @param connection |
|
106 |
* @return Image, not to be disposed |
|
107 |
*/ |
|
108 |
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
|
109 |
// 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
|
110 |
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
|
111 |
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
|
112 |
} |
706 | 113 |
if (connection instanceof IConnection2) { |
709
c92b05bdc957
Update for IConnectionStatus changes
Ed Swartz <ed.swartz@nokia.com>
parents:
706
diff
changeset
|
114 |
IConnectionStatus status = ((IConnection2) connection).getStatus(); |
706 | 115 |
return getConnectionStatusImage(status); |
710
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
116 |
} 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
|
117 |
// old connection logic |
711 | 118 |
if (isSomeServiceInUse(connection)) { |
710
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
119 |
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
|
120 |
} |
47bb893ba749
Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
709
diff
changeset
|
121 |
return ConnectionUIUtils.CONNECTION_IMG; |
706 | 122 |
} |
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* @param status |
|
127 |
* @return |
|
128 |
*/ |
|
129 |
public static Image getConnectedServiceStatusImage(IConnectedService.IStatus.EStatus status) { |
|
130 |
switch (status) { |
|
131 |
case DOWN: |
|
132 |
return ConnectionUIUtils.STATUS_UNAVAIL_IMG; |
|
133 |
case UP: |
|
134 |
return ConnectionUIUtils.STATUS_AVAIL_IMG; |
|
135 |
case IN_USE: |
|
136 |
return ConnectionUIUtils.CONNECTION_IMG; |
|
137 |
case UNKNOWN: |
|
138 |
return ConnectionUIUtils.STATUS_UNK_IMG; |
|
139 |
} |
|
140 |
return null; |
|
141 |
} |
|
142 |
||
711 | 143 |
public static IStatus getFirstInUseServiceStatus(IConnection connection) { |
144 |
Collection<IConnectedService> connectedServices = |
|
145 |
Registry.instance().getConnectedServices(connection); |
|
146 |
// if any service is in-use, then connection is in-use |
|
980
2856f9bc4ddf
Backed out changeset 1dc37cfc99cd
John Dean <john.3.dean@nokia.com>
parents:
979
diff
changeset
|
147 |
if (connectedServices == null) |
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
|
148 |
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
|
149 |
|
711 | 150 |
for (IConnectedService connectedService : connectedServices) { |
151 |
IStatus status = connectedService.getStatus(); |
|
152 |
if (status.getEStatus().equals(EStatus.IN_USE)) |
|
153 |
return status; |
|
154 |
} |
|
155 |
||
156 |
return null; |
|
157 |
} |
|
158 |
||
159 |
public static boolean isSomeServiceInUse(IConnection connection) { |
|
160 |
return getFirstInUseServiceStatus(connection) != null; |
|
161 |
} |
|
706 | 162 |
} |