uidesigner/com.nokia.sdt.symbian.ui/src/com/nokia/sdt/symbian/ui/UIPlugin.java
author fturovic <frank.turovich@nokia.com>
Tue, 07 Apr 2009 15:28:30 -0500
changeset 72 5464a0b24d87
parent 2 d760517a8095
permissions -rw-r--r--
removed license page and TOC entry for 2.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
package com.nokia.sdt.symbian.ui;
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
import com.nokia.cpp.internal.api.utils.core.Logging;
cawthron
parents:
diff changeset
    20
cawthron
parents:
diff changeset
    21
import org.eclipse.ui.plugin.*;
cawthron
parents:
diff changeset
    22
import org.eclipse.core.runtime.IStatus;
cawthron
parents:
diff changeset
    23
import org.eclipse.jface.resource.ImageDescriptor;
cawthron
parents:
diff changeset
    24
import org.osgi.framework.BundleContext;
cawthron
parents:
diff changeset
    25
cawthron
parents:
diff changeset
    26
import java.util.*;
cawthron
parents:
diff changeset
    27
cawthron
parents:
diff changeset
    28
/**
cawthron
parents:
diff changeset
    29
 * The main plugin class to be used in the desktop.
cawthron
parents:
diff changeset
    30
 */
cawthron
parents:
diff changeset
    31
public class UIPlugin extends AbstractUIPlugin {
cawthron
parents:
diff changeset
    32
cawthron
parents:
diff changeset
    33
	public static String PLUGIN_ID = "com.nokia.sdt.symbian.ui"; //$NON-NLS-1$
cawthron
parents:
diff changeset
    34
cawthron
parents:
diff changeset
    35
	//The shared instance.
cawthron
parents:
diff changeset
    36
	private static UIPlugin plugin;
cawthron
parents:
diff changeset
    37
	
cawthron
parents:
diff changeset
    38
	// Resource bundle.
cawthron
parents:
diff changeset
    39
	private ResourceBundle resourceBundle;
cawthron
parents:
diff changeset
    40
cawthron
parents:
diff changeset
    41
	/**
cawthron
parents:
diff changeset
    42
	 * The constructor.
cawthron
parents:
diff changeset
    43
	 */
cawthron
parents:
diff changeset
    44
	public UIPlugin() {
cawthron
parents:
diff changeset
    45
		plugin = this;
cawthron
parents:
diff changeset
    46
		try {
cawthron
parents:
diff changeset
    47
			resourceBundle = ResourceBundle.getBundle("com.nokia.sdt.symbian.ui.messages");
cawthron
parents:
diff changeset
    48
		} catch (MissingResourceException x) {
cawthron
parents:
diff changeset
    49
			resourceBundle = null;
cawthron
parents:
diff changeset
    50
		}
cawthron
parents:
diff changeset
    51
	}
cawthron
parents:
diff changeset
    52
cawthron
parents:
diff changeset
    53
	/**
cawthron
parents:
diff changeset
    54
	 * This method is called upon plug-in activation
cawthron
parents:
diff changeset
    55
	 */
cawthron
parents:
diff changeset
    56
	public void start(BundleContext context) throws Exception {
cawthron
parents:
diff changeset
    57
		super.start(context);
cawthron
parents:
diff changeset
    58
	}
cawthron
parents:
diff changeset
    59
cawthron
parents:
diff changeset
    60
	/**
cawthron
parents:
diff changeset
    61
	 * This method is called when the plug-in is stopped
cawthron
parents:
diff changeset
    62
	 */
cawthron
parents:
diff changeset
    63
	public void stop(BundleContext context) throws Exception {
cawthron
parents:
diff changeset
    64
		super.stop(context);
cawthron
parents:
diff changeset
    65
		plugin = null;
cawthron
parents:
diff changeset
    66
	}
cawthron
parents:
diff changeset
    67
cawthron
parents:
diff changeset
    68
	/**
cawthron
parents:
diff changeset
    69
	 * Returns the shared instance.
cawthron
parents:
diff changeset
    70
	 */
cawthron
parents:
diff changeset
    71
	public static UIPlugin getDefault() {
cawthron
parents:
diff changeset
    72
		return plugin;
cawthron
parents:
diff changeset
    73
	}
cawthron
parents:
diff changeset
    74
cawthron
parents:
diff changeset
    75
	/**
cawthron
parents:
diff changeset
    76
	 * Returns the string from the plugin's resource bundle, or 'key' if not
cawthron
parents:
diff changeset
    77
	 * found.
cawthron
parents:
diff changeset
    78
	 */
cawthron
parents:
diff changeset
    79
	public static String getResourceString(String key) {
cawthron
parents:
diff changeset
    80
		ResourceBundle bundle = UIPlugin.getDefault().getResourceBundle();
cawthron
parents:
diff changeset
    81
		try {
cawthron
parents:
diff changeset
    82
			return (bundle != null) ? bundle.getString(key) : key;
cawthron
parents:
diff changeset
    83
		} catch (MissingResourceException e) {
cawthron
parents:
diff changeset
    84
			return key;
cawthron
parents:
diff changeset
    85
		}
cawthron
parents:
diff changeset
    86
	}
cawthron
parents:
diff changeset
    87
cawthron
parents:
diff changeset
    88
	/**
cawthron
parents:
diff changeset
    89
	 * Returns the plugin's resource bundle,
cawthron
parents:
diff changeset
    90
	 */
cawthron
parents:
diff changeset
    91
	public ResourceBundle getResourceBundle() {
cawthron
parents:
diff changeset
    92
		return resourceBundle;
cawthron
parents:
diff changeset
    93
	}
cawthron
parents:
diff changeset
    94
	
cawthron
parents:
diff changeset
    95
	/**
cawthron
parents:
diff changeset
    96
	 * Returns an image descriptor for the image file at the given
cawthron
parents:
diff changeset
    97
	 * plug-in relative path.
cawthron
parents:
diff changeset
    98
	 *
cawthron
parents:
diff changeset
    99
	 * @param path the path
cawthron
parents:
diff changeset
   100
	 * @return the image descriptor
cawthron
parents:
diff changeset
   101
	 */
cawthron
parents:
diff changeset
   102
	public static ImageDescriptor getImageDescriptor(String path) {
cawthron
parents:
diff changeset
   103
		return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.sdt.uidesigner.wizard", path);
cawthron
parents:
diff changeset
   104
	}
cawthron
parents:
diff changeset
   105
        
cawthron
parents:
diff changeset
   106
    static public void log(IStatus status) {
cawthron
parents:
diff changeset
   107
        Logging.log(plugin, status);
cawthron
parents:
diff changeset
   108
    }
cawthron
parents:
diff changeset
   109
cawthron
parents:
diff changeset
   110
    static public void log(Throwable thr) {
cawthron
parents:
diff changeset
   111
        Logging.log(plugin, Logging.newStatus(plugin, thr));
cawthron
parents:
diff changeset
   112
    }
cawthron
parents:
diff changeset
   113
cawthron
parents:
diff changeset
   114
    static public void log(Throwable thr, String msg) {
cawthron
parents:
diff changeset
   115
        Logging.log(plugin, Logging.newStatus(plugin, IStatus.ERROR, msg, thr));
cawthron
parents:
diff changeset
   116
    }
cawthron
parents:
diff changeset
   117
}