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