|
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; |
|
30 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
|
31 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
|
32 |
|
33 /** |
|
34 * |
|
35 */ |
|
36 public class ConnectionUIUtils { |
|
37 |
|
38 public static IConnectedService.IStatus getFirstInUseStatus(IConnection connection) { |
|
39 Collection<IConnectedService> connectedServices = |
|
40 Registry.instance().getConnectedServices(connection); |
|
41 // if any service is in-use, then connection is in-use |
|
42 for (IConnectedService connectedService : connectedServices) { |
|
43 IConnectedService.IStatus status = connectedService.getStatus(); |
|
44 if (status.getEStatus().equals(IConnectedService.IStatus.EStatus.IN_USE)) |
|
45 return status; |
|
46 } |
|
47 |
|
48 return null; |
|
49 } |
|
50 |
|
51 public static boolean isConnectionInUse(IConnection connection) { |
|
52 return getFirstInUseStatus(connection) != null; |
|
53 } |
|
54 |
|
55 private static final ImageDescriptor STATUS_AVAIL_IMGDESC = |
|
56 RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$ |
|
57 private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC = |
|
58 RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$ |
|
59 private static final ImageDescriptor STATUS_UNK_IMGDESC = |
|
60 RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$ |
|
61 private static final ImageDescriptor STATUS_INUSE_IMGDESC = |
|
62 RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$ |
|
63 |
|
64 private static final ImageDescriptor CONNECTION_READY_IMGDESC = |
|
65 RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusReady.png"); //$NON-NLS-1$ |
|
66 private static final ImageDescriptor CONNECTION_IN_USE_IMGDESC = |
|
67 RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUse.png"); //$NON-NLS-1$ |
|
68 private static final ImageDescriptor CONNECTION_NOT_READY_IMGDESC = |
|
69 RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusNotReady.png"); //$NON-NLS-1$ |
|
70 private static final ImageDescriptor CONNECTION_IN_USE_DISCONNECTED_IMGDESC = |
|
71 RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusDisconnected.png"); //$NON-NLS-1$ |
|
72 |
|
73 private static final ImageDescriptor CONNECTION_IMGDESC = |
|
74 RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$ |
|
75 |
|
76 private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage(); |
|
77 private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage(); |
|
78 private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage(); |
|
79 private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage(); |
|
80 |
|
81 private static final Image CONNECTION_READY_IMG = CONNECTION_READY_IMGDESC.createImage(); |
|
82 private static final Image CONNECTION_IN_USE_IMG = CONNECTION_IN_USE_IMGDESC.createImage(); |
|
83 private static final Image CONNECTION_NOT_READY_IMG = CONNECTION_NOT_READY_IMGDESC.createImage(); |
|
84 private static final Image CONNECTION_IN_USE_DISCONNECTED_IMG = CONNECTION_IN_USE_DISCONNECTED_IMGDESC.createImage(); |
|
85 |
|
86 private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage(); |
|
87 |
|
88 public static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0); |
|
89 public static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0); |
|
90 public static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255); |
|
91 public static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96); |
|
92 |
|
93 /** |
|
94 * Get the image representing the connection status. |
|
95 * @param connection |
|
96 * @return Image, not to be disposed |
|
97 */ |
|
98 public static Image getConnectionStatusImage(IConnection2.IStatus status) { |
|
99 if (status != null) { |
|
100 IConnection2.IStatus.EStatus severity = status.getEStatus(); |
|
101 |
|
102 switch (severity) { |
|
103 case READY: |
|
104 return CONNECTION_READY_IMG; |
|
105 case IN_USE: |
|
106 return CONNECTION_IN_USE_IMG; |
|
107 case NOT_READY: |
|
108 return CONNECTION_NOT_READY_IMG; |
|
109 case IN_USE_DISCONNECTED: |
|
110 return CONNECTION_IN_USE_DISCONNECTED_IMG; |
|
111 } |
|
112 } |
|
113 return ConnectionUIUtils.CONNECTION_IMG; |
|
114 } |
|
115 |
|
116 /** |
|
117 * Get the image representing the connection status. |
|
118 * @param connection |
|
119 * @return Image, not to be disposed |
|
120 */ |
|
121 public static Image getConnectionImage(IConnection connection) { |
|
122 if (connection instanceof IConnection2) { |
|
123 IConnection2.IStatus status = ((IConnection2) connection).getStatus(); |
|
124 return getConnectionStatusImage(status); |
|
125 } |
|
126 if (isConnectionInUse(connection)) { |
|
127 return ConnectionUIUtils.STATUS_INUSE_IMG; |
|
128 } |
|
129 return ConnectionUIUtils.CONNECTION_IMG; |
|
130 } |
|
131 |
|
132 /** |
|
133 * @param status |
|
134 * @return |
|
135 */ |
|
136 public static Image getConnectedServiceStatusImage(IConnectedService.IStatus.EStatus status) { |
|
137 switch (status) { |
|
138 case DOWN: |
|
139 return ConnectionUIUtils.STATUS_UNAVAIL_IMG; |
|
140 case UP: |
|
141 return ConnectionUIUtils.STATUS_AVAIL_IMG; |
|
142 case IN_USE: |
|
143 return ConnectionUIUtils.CONNECTION_IMG; |
|
144 case UNKNOWN: |
|
145 return ConnectionUIUtils.STATUS_UNK_IMG; |
|
146 } |
|
147 return null; |
|
148 } |
|
149 |
|
150 } |