author | dadubrow |
Mon, 02 Aug 2010 08:44:45 -0500 | |
changeset 1734 | bf670d38123a |
parent 1721 | 18638adda547 |
child 1744 | 48b623de4c8e |
permissions | -rw-r--r-- |
1377
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
1 |
/* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
3 |
* All rights reserved. |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
8 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
9 |
* Initial Contributors: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
11 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
12 |
* Contributors: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
13 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
14 |
* Description: |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
15 |
* |
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
16 |
*/ |
1360 | 17 |
package com.nokia.carbide.discovery.ui; |
18 |
||
1634 | 19 |
import java.io.File; |
20 |
import java.io.FileInputStream; |
|
21 |
import java.io.IOException; |
|
22 |
import java.io.InputStream; |
|
1637 | 23 |
import java.net.URI; |
1734 | 24 |
import java.net.URISyntaxException; |
1634 | 25 |
import java.net.URL; |
26 |
import java.text.MessageFormat; |
|
27 |
import java.util.Properties; |
|
28 |
||
1637 | 29 |
import org.eclipse.core.net.proxy.IProxyData; |
1634 | 30 |
import org.eclipse.core.runtime.IPath; |
1734 | 31 |
import org.eclipse.core.runtime.IProgressMonitor; |
1363 | 32 |
import org.eclipse.core.runtime.IStatus; |
1634 | 33 |
import org.eclipse.core.runtime.Path; |
34 |
import org.eclipse.core.runtime.Platform; |
|
1363 | 35 |
import org.eclipse.core.runtime.Status; |
1734 | 36 |
import org.eclipse.core.runtime.jobs.Job; |
1360 | 37 |
import org.eclipse.jface.resource.ImageDescriptor; |
1634 | 38 |
import org.eclipse.osgi.service.datalocation.Location; |
1734 | 39 |
import org.eclipse.swt.SWT; |
40 |
import org.eclipse.swt.widgets.Control; |
|
41 |
import org.eclipse.swt.widgets.Display; |
|
1360 | 42 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
43 |
import org.osgi.framework.BundleContext; |
|
44 |
||
1637 | 45 |
import com.nokia.cpp.internal.api.utils.core.ProxyUtils; |
46 |
||
1360 | 47 |
/** |
48 |
* The activator class controls the plug-in life cycle |
|
49 |
*/ |
|
50 |
public class Activator extends AbstractUIPlugin { |
|
51 |
// The plug-in ID |
|
52 |
public static final String PLUGIN_ID = "com.nokia.carbide.discovery.ui"; //$NON-NLS-1$ |
|
53 |
||
54 |
// The shared instance |
|
55 |
private static Activator plugin; |
|
56 |
||
1637 | 57 |
private static final String PROPERTY_PROXYPORT = "network.proxy_port"; //$NON-NLS-1$ |
58 |
private static final String PROPERTY_PROXYHOST = "network.proxy_host"; //$NON-NLS-1$ |
|
1734 | 59 |
|
60 |
private boolean proxyDataAvailable; |
|
1637 | 61 |
|
1360 | 62 |
/** |
63 |
* The constructor |
|
64 |
*/ |
|
65 |
public Activator() { |
|
66 |
} |
|
67 |
||
68 |
/* |
|
69 |
* (non-Javadoc) |
|
70 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
71 |
*/ |
|
72 |
public void start(BundleContext context) throws Exception { |
|
1721 | 73 |
plugin = this; |
1360 | 74 |
super.start(context); |
1734 | 75 |
Job j = new Job("Getting proxy info") { |
76 |
@Override |
|
77 |
protected IStatus run(IProgressMonitor monitor) { |
|
78 |
try { |
|
79 |
IProxyData proxyData = ProxyUtils.getProxyData(new URI("http://www.yahoo.com")); |
|
80 |
if (proxyData != null) { |
|
81 |
System.setProperty(PROPERTY_PROXYHOST, proxyData.getHost()); |
|
82 |
System.setProperty(PROPERTY_PROXYPORT, String.valueOf(proxyData.getPort())); |
|
83 |
} |
|
84 |
} catch (URISyntaxException e) { |
|
85 |
} //$NON-NLS-1$ |
|
86 |
setProxyDataAvailable(); |
|
87 |
return Status.OK_STATUS; |
|
88 |
} |
|
89 |
}; |
|
90 |
j.setSystem(true); |
|
91 |
j.setUser(false); |
|
92 |
j.schedule(); |
|
93 |
} |
|
94 |
||
95 |
private synchronized void setProxyDataAvailable() { |
|
96 |
proxyDataAvailable = true; |
|
97 |
} |
|
98 |
||
99 |
public synchronized boolean isProxyDataAvailable() { |
|
100 |
return proxyDataAvailable; |
|
1360 | 101 |
} |
102 |
||
1734 | 103 |
public static void runInUIThreadWhenProxyDataSet(final Control control, final Runnable r) { |
104 |
Job j = new Job("") { |
|
105 |
@Override |
|
106 |
protected IStatus run(IProgressMonitor monitor) { |
|
107 |
setBusyCursor(control, true); |
|
108 |
Activator activator = getDefault(); |
|
109 |
while (!activator.isProxyDataAvailable()) { |
|
110 |
try { |
|
111 |
Thread.sleep(200); |
|
112 |
} catch (InterruptedException e) { |
|
113 |
} |
|
114 |
} |
|
115 |
setBusyCursor(control, false); |
|
116 |
Display.getDefault().asyncExec(r); |
|
117 |
return Status.OK_STATUS; |
|
118 |
} |
|
119 |
}; |
|
120 |
j.setSystem(true); |
|
121 |
j.setUser(false); |
|
122 |
j.schedule(); |
|
123 |
} |
|
124 |
||
125 |
public static void setBusyCursor(final Control control, final boolean isBusy) { |
|
126 |
final Display display = control.getDisplay(); |
|
127 |
display.syncExec(new Runnable() { |
|
128 |
@Override |
|
129 |
public void run() { |
|
130 |
control.setCursor(isBusy ? display.getSystemCursor(SWT.CURSOR_WAIT) : null); |
|
131 |
} |
|
132 |
}); |
|
133 |
} |
|
134 |
||
1360 | 135 |
/* |
136 |
* (non-Javadoc) |
|
137 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
138 |
*/ |
|
139 |
public void stop(BundleContext context) throws Exception { |
|
1377
40401ea8b1fd
move p2 policy code to discovery plugin for now + add system property for disabling unsigned check
dadubrow
parents:
1363
diff
changeset
|
140 |
super.stop(context); |
1360 | 141 |
plugin = null; |
142 |
} |
|
143 |
||
144 |
/** |
|
145 |
* Returns the shared instance |
|
146 |
* |
|
147 |
* @return the shared instance |
|
148 |
*/ |
|
149 |
public static Activator getDefault() { |
|
150 |
return plugin; |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Returns an image descriptor for the image file at the given |
|
155 |
* plug-in relative path |
|
156 |
* |
|
157 |
* @param path the path |
|
158 |
* @return the image descriptor |
|
159 |
*/ |
|
160 |
public static ImageDescriptor getImageDescriptor(String path) { |
|
161 |
return imageDescriptorFromPlugin(PLUGIN_ID, path); |
|
162 |
} |
|
1363 | 163 |
|
164 |
/** |
|
165 |
* Log to error log |
|
166 |
* @param message |
|
167 |
* @param t |
|
168 |
*/ |
|
169 |
public static void logError(String message, Throwable t) { |
|
170 |
getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, t)); |
|
171 |
} |
|
1634 | 172 |
|
173 |
/** |
|
174 |
* Get a value from the server.properties file |
|
175 |
* @param key |
|
176 |
* @return |
|
177 |
*/ |
|
178 |
public static String getFromServerProperties(String key) { |
|
179 |
Location installLocation = Platform.getInstallLocation(); |
|
180 |
URL url = installLocation.getURL(); |
|
181 |
IPath path = new Path(url.getPath()); |
|
182 |
path = path.append("configuration/server.properties"); //$NON-NLS-1$ |
|
183 |
File file = path.toFile(); |
|
184 |
Properties properties = new Properties(); |
|
185 |
try { |
|
186 |
InputStream is = new FileInputStream(file); |
|
187 |
properties.load(is); |
|
188 |
is.close(); |
|
189 |
} catch (IOException e) { |
|
190 |
String message = |
|
1661 | 191 |
MessageFormat.format(Messages.Activator_MissingConfigURLError, key); |
1634 | 192 |
Activator.logError(message, e); |
193 |
} |
|
194 |
return (String) properties.get(key); |
|
195 |
} |
|
196 |
||
1360 | 197 |
} |