frameworkplugins/com.nokia.s60tools.ui/src/com/nokia/s60tools/ui/internal/S60ToolsUiPlugin.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) 2006 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
 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
package com.nokia.s60tools.ui.internal;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
import java.io.File;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import java.io.IOException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import java.net.URL;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import org.eclipse.core.runtime.FileLocator;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import org.eclipse.jface.resource.ImageDescriptor;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import org.eclipse.jface.resource.ImageRegistry;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import org.eclipse.swt.graphics.Image;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
import org.eclipse.swt.widgets.Display;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
import org.eclipse.ui.plugin.AbstractUIPlugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
import org.osgi.framework.BundleContext;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
import com.nokia.s60tools.ui.UiUtils;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
import com.nokia.s60tools.ui.actions.OpenPreferencePageAction;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
import com.nokia.s60tools.ui.actions.S60ToolsBaseAction;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
 * The main plugin class to be used in the desktop.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
public class S60ToolsUiPlugin extends AbstractUIPlugin {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
	 * Shared plug-in ID.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
	public static final String PLUGIN_ID = "com.nokia.s60tools.ui";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
	 * The shared plug-in instance.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
	private static S60ToolsUiPlugin plugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
	 * Plugin installation location.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
	private static String pluginInstallLocation;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
	 * The constructor.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
	public S60ToolsUiPlugin() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
		plugin = this;
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
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
	 * This method is called upon plug-in activation
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
	public void start(BundleContext context) throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
		super.start(context);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
		pluginInstallLocation = getPluginInstallPath();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
	 * This method is called when the plug-in is stopped
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
	public void stop(BundleContext context) throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
		super.stop(context);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
		plugin = null;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
	 * Returns the shared instance.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
	public static S60ToolsUiPlugin getDefault() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		return plugin;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
	 * Returns an image descriptor for the image file at the given
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
	 * plug-in relative path.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
	 *
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
	 * @param path the path
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
	 * @return the image descriptor
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    94
	public static ImageDescriptor getImageDescriptor(String path) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    95
		return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    96
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    97
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    98
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    99
	 * 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   100
	 * @return plugin install path
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   101
	 * @throws IOException
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   102
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   103
	public String getPluginInstallPath() throws IOException{
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   104
		 // URL to the plugin's root ("/")
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   105
		URL relativeURL = getBundle().getEntry("/"); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   106
		//	Converting into local path
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   107
		URL localURL = FileLocator.toFileURL(relativeURL);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   108
		//	Getting install location in correct form
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   109
		File f = new File(localURL.getPath());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   110
		String pluginInstallLocation = f.getAbsolutePath();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   111
				
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   112
		return pluginInstallLocation;		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   113
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   114
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   115
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   116
	 * Gets images path relative to given plugin install path.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   117
	 * @return Path were image resources are located.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   118
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   119
	private String getImagesPath(){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   120
		return pluginInstallLocation
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   121
				+ File.separatorChar
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   122
				+ "icons"; //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   123
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   124
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   125
	/* (non-Javadoc)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   126
     * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   127
     */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   128
    protected void initializeImageRegistry(ImageRegistry imgReg) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   129
    	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   130
    	//
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   131
    	// Storing images to plugin's image registry
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   132
    	//
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   133
    	Display disp = Display.getCurrent();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   134
    	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   135
    	Image img = new Image( disp, getImagesPath() + File.separator + "empty_banner.png" );        	 //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   136
        imgReg.put( UiUtils.NOKIA_TOOLS_BANNER, img );
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   137
        
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   138
    	img = new Image( disp, getImagesPath() + File.separator + "s60tools_action_icon.png" );        	 //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   139
        imgReg.put( S60ToolsBaseAction.S60TOOLS_ACTION_ICON, img );
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   140
        
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   141
    	img = new Image( disp, getImagesPath() + File.separator + "preferences.png"); //$NON-NLS-1$
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   142
        imgReg.put( OpenPreferencePageAction.IMG_PREFERENCE_PAGE, img );        
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   143
        
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   144
    }
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   145
    
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   146
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   147
	 * Returns image descriptor for the given key from the plugin's image registry.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   148
	 * @param key Key to search descriptor for.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   149
	 * @return Image descriptor for the given key from the plugin's image registry.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   150
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   151
	public static ImageDescriptor getImageDescriptorForKey( String key ){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   152
    	ImageRegistry imgReg = getDefault().getImageRegistry();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   153
    	return  imgReg.getDescriptor( key );		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   154
	}	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   155
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   156
	/**
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   157
	 * Returns image for the given key from the plugin's image registry.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   158
	 * @param key Key to search image for.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   159
	 * @return Image for the given key from the plugin's image registry.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   160
	 */
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   161
	public static Image getImageForKey( String key ){
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   162
    	ImageRegistry imgReg = getDefault().getImageRegistry();    	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   163
    	return  imgReg.get(key);		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   164
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   165
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
   166
}