0
|
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 "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.s60tools.hticonnection;
|
|
19 |
|
|
20 |
import java.io.File;
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.net.URL;
|
|
23 |
|
|
24 |
import org.eclipse.core.runtime.FileLocator;
|
|
25 |
import org.eclipse.jface.preference.IPreferenceStore;
|
|
26 |
import org.eclipse.swt.widgets.Shell;
|
|
27 |
import org.eclipse.ui.IWorkbenchPage;
|
|
28 |
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
29 |
import org.osgi.framework.BundleContext;
|
|
30 |
|
|
31 |
import com.nokia.s60tools.hticonnection.common.ProductInfoRegistry;
|
|
32 |
import com.nokia.s60tools.hticonnection.core.HtiConnection;
|
|
33 |
import com.nokia.s60tools.hticonnection.core.RequestQueueManager;
|
|
34 |
import com.nokia.s60tools.hticonnection.preferences.HtiApiPreferences;
|
|
35 |
import com.nokia.s60tools.hticonnection.preferences.IHtiApiPreferences;
|
|
36 |
import com.nokia.s60tools.hticonnection.resources.ImageResourceManager;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* The activator class controls the plug-in life cycle
|
|
40 |
*/
|
|
41 |
public class HtiApiActivator extends AbstractUIPlugin {
|
|
42 |
|
|
43 |
// The plug-in ID
|
|
44 |
public static final String PLUGIN_ID = "com.nokia.s60tools.hticonnection"; //$NON-NLS-1$
|
|
45 |
|
|
46 |
// The shared instance
|
|
47 |
private static HtiApiActivator plugin;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Shared singleton preferences instance available for whole plug-in lifetime
|
|
51 |
*/
|
|
52 |
private static IHtiApiPreferences preferences;
|
|
53 |
|
|
54 |
/**
|
|
55 |
* Keeps HTI requests in queue and runs them.
|
|
56 |
*/
|
|
57 |
private RequestQueueManager queueManager;
|
|
58 |
/**
|
|
59 |
* Manages connection status and tests connection when necessary.
|
|
60 |
*/
|
|
61 |
private HtiConnection connectionManager;
|
|
62 |
|
|
63 |
/**
|
|
64 |
* Storing preferences
|
|
65 |
*/
|
|
66 |
private static IPreferenceStore prefsStore;
|
|
67 |
|
|
68 |
/**
|
|
69 |
* Plugin installation location.
|
|
70 |
*/
|
|
71 |
private static String pluginInstallLocation;
|
|
72 |
|
|
73 |
/**
|
|
74 |
* This member variable is only used internally for JUnit testing purposes.
|
|
75 |
*/
|
|
76 |
private String alternatePluginInstallPath = null;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* The constructor
|
|
80 |
*/
|
|
81 |
public HtiApiActivator() {
|
|
82 |
plugin = this;
|
|
83 |
}
|
|
84 |
|
|
85 |
/* (non-Javadoc)
|
|
86 |
* @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
|
|
87 |
*/
|
|
88 |
public void start(BundleContext context) throws Exception {
|
|
89 |
super.start(context);
|
|
90 |
plugin = this;
|
|
91 |
|
|
92 |
pluginInstallLocation = getPluginInstallPath();
|
|
93 |
|
|
94 |
//This startup debug println has been left into the code in purpose
|
|
95 |
System.out.println("pluginInstallLocation: " + pluginInstallLocation); //$NON-NLS-1$
|
|
96 |
|
|
97 |
// Call to getImagesPath requires that getPluginInstallPath() is
|
|
98 |
// called beforehand.
|
|
99 |
String imagesPath = getImagesPath();
|
|
100 |
|
|
101 |
//This startup debug println has been left into the code in purpose
|
|
102 |
System.out.println("imagesPath: " + imagesPath); //$NON-NLS-1$
|
|
103 |
|
|
104 |
// Loading images required by this plug-in
|
|
105 |
ImageResourceManager.loadImages(imagesPath);
|
|
106 |
|
|
107 |
//This startup debug println has been left into the code in purpose
|
|
108 |
System.out.println("HTI-API Plugin STARTUP..."); //$NON-NLS-1$
|
|
109 |
|
|
110 |
initializeSettings();
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* This method is the correct place for initializing plugin-wide settings during start-up.
|
|
115 |
*/
|
|
116 |
private void initializeSettings() {
|
|
117 |
queueManager = RequestQueueManager.getInstance();
|
|
118 |
connectionManager = HtiConnection.getInstance();
|
|
119 |
// Initialization is not needed before starting activator and tests don't require initialization.
|
|
120 |
connectionManager.init();
|
|
121 |
|
|
122 |
// Initialize default values for preferences
|
|
123 |
getPreferences().initDefaultValues();
|
|
124 |
}
|
|
125 |
|
|
126 |
/* (non-Javadoc)
|
|
127 |
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
|
|
128 |
*/
|
|
129 |
public void stop(BundleContext context) throws Exception {
|
|
130 |
//This shutdown debug println has been left into the code in purpose
|
|
131 |
System.out.println("HTI-API Plugin SHUTDOWN..."); //$NON-NLS-1$
|
|
132 |
|
|
133 |
// Stopping and clearing the request queue.
|
|
134 |
queueManager.stop();
|
|
135 |
connectionManager.stop();
|
|
136 |
|
|
137 |
plugin = null;
|
|
138 |
super.stop(context);
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Returns the shared instance.
|
|
143 |
* @return the shared instance
|
|
144 |
*/
|
|
145 |
public static HtiApiActivator getDefault() {
|
|
146 |
return plugin;
|
|
147 |
}
|
|
148 |
|
|
149 |
/**
|
|
150 |
* This must be called from UI thread. If called
|
|
151 |
* from non-ui thread this returns <code>null</code>.
|
|
152 |
* @return Currently active workbench page.
|
|
153 |
*/
|
|
154 |
public static IWorkbenchPage getCurrentlyActivePage(){
|
|
155 |
return getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
|
156 |
}
|
|
157 |
|
|
158 |
/**
|
|
159 |
* This must be called from UI thread. If called
|
|
160 |
* from non-ui thread this returns <code>null</code>.
|
|
161 |
* @return The shell of the currently active workbench window..
|
|
162 |
*/
|
|
163 |
public static Shell getCurrentlyActiveWbWindowShell(){
|
|
164 |
IWorkbenchPage page = getCurrentlyActivePage();
|
|
165 |
if(page != null){
|
|
166 |
return page.getWorkbenchWindow().getShell();
|
|
167 |
}
|
|
168 |
return null;
|
|
169 |
}
|
|
170 |
|
|
171 |
/**
|
|
172 |
* Gets plug-in's installation path.
|
|
173 |
* @return plug-in's installation path.
|
|
174 |
* @throws IOException
|
|
175 |
*/
|
|
176 |
public String getPluginInstallPath() throws IOException{
|
|
177 |
// Returning alternate install path, if set for JUnit testing purposes.
|
|
178 |
if(alternatePluginInstallPath != null){
|
|
179 |
return alternatePluginInstallPath;
|
|
180 |
}
|
|
181 |
// URL to the plugin's root ("/")
|
|
182 |
URL relativeURL = getBundle().getEntry("/"); //$NON-NLS-1$
|
|
183 |
// Converting into local path
|
|
184 |
URL localURL = FileLocator.toFileURL(relativeURL);
|
|
185 |
// Getting install location in correct form
|
|
186 |
File f = new File(localURL.getPath());
|
|
187 |
String pluginInstallLocation = f.getAbsolutePath();
|
|
188 |
|
|
189 |
return pluginInstallLocation;
|
|
190 |
}
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Gets images path relative to given plugin install path.
|
|
194 |
* @return Path were image resources are located.
|
|
195 |
*/
|
|
196 |
private String getImagesPath(){
|
|
197 |
return pluginInstallLocation
|
|
198 |
+ File.separatorChar
|
|
199 |
+ ProductInfoRegistry.getImagesDirectoryName();
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Returns the PreferenceStore where plugin preferences are stored
|
|
204 |
* @return the PreferenceStore where plugin preferences are stored
|
|
205 |
*/
|
|
206 |
public static IPreferenceStore getPrefsStore(){
|
|
207 |
if (prefsStore == null){
|
|
208 |
prefsStore = getDefault().getPreferenceStore();
|
|
209 |
}
|
|
210 |
|
|
211 |
return prefsStore;
|
|
212 |
}
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Gets if preference store is initialized.
|
|
216 |
* @return True if preference store is initialized.
|
|
217 |
*/
|
|
218 |
public static boolean isPrefStoreinitialized() {
|
|
219 |
if (prefsStore != null) {
|
|
220 |
return true;
|
|
221 |
} else {
|
|
222 |
return false;
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
/**
|
|
227 |
* Gets reference to plug-in's preference store.
|
|
228 |
* @return Reference to plug-in's preference store.
|
|
229 |
*/
|
|
230 |
public static IHtiApiPreferences getPreferences(){
|
|
231 |
if(preferences == null){
|
|
232 |
preferences = new HtiApiPreferences();
|
|
233 |
}
|
|
234 |
return preferences;
|
|
235 |
}
|
|
236 |
|
|
237 |
//
|
|
238 |
// Internally used methods.
|
|
239 |
//
|
|
240 |
|
|
241 |
/**
|
|
242 |
* This constructor is only used for setting alternate
|
|
243 |
* preference store just used for JUnit tests.
|
|
244 |
* @param alternatePreferences Alternate preference store implementation.
|
|
245 |
* @param alternateInstallPath Alternate plug-in install path.
|
|
246 |
*/
|
|
247 |
private HtiApiActivator(IHtiApiPreferences alternatePreferences, String alternateInstallPath){
|
|
248 |
preferences = alternatePreferences;
|
|
249 |
alternatePluginInstallPath = alternateInstallPath;
|
|
250 |
}
|
|
251 |
|
|
252 |
/**
|
|
253 |
* Creates activator instance if not already created, with reference
|
|
254 |
* to alternate preference store, and with different plugin install path.
|
|
255 |
* This creates always a new instance of the activator, and need to be called
|
|
256 |
* only when needed.
|
|
257 |
*
|
|
258 |
* This methods to be used only from JUnit tests
|
|
259 |
* and can be used to set alternate preference store
|
|
260 |
* that is just used for JUnit tests.
|
|
261 |
*
|
|
262 |
* @param alternatePreferences Alternate preference store implementation.
|
|
263 |
* @param alternateInstallPath Alternate plugin install path used for testing.
|
|
264 |
* @return Reference to activator instance
|
|
265 |
*/
|
|
266 |
public static HtiApiActivator createWithAlternateSettings(IHtiApiPreferences alternatePreferences, String alternateInstallPath){
|
|
267 |
plugin = new HtiApiActivator(alternatePreferences, alternateInstallPath);
|
|
268 |
return plugin;
|
|
269 |
}
|
|
270 |
}
|