sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.ui/src/com/nokia/carbide/cpp/internal/pi/ui/PIUiPlugin.java
changeset 2 b9ab3b238396
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     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 the License "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.carbide.cpp.internal.pi.ui;
       
    19 
       
    20 import org.eclipse.core.runtime.IStatus;
       
    21 import org.eclipse.core.runtime.Status;
       
    22 import org.eclipse.jface.resource.ImageDescriptor;
       
    23 import org.eclipse.swt.widgets.Display;
       
    24 import org.eclipse.ui.plugin.AbstractUIPlugin;
       
    25 import org.osgi.framework.BundleContext;
       
    26 
       
    27 /**
       
    28  * The main plugin class to be used in the desktop.
       
    29  */
       
    30 public class PIUiPlugin extends AbstractUIPlugin {
       
    31 
       
    32 	public static final String PLUGIN_ID = "com.nokia.carbide.cpp.pi.ui"; //$NON-NLS-1$
       
    33 
       
    34 	//The shared instance.
       
    35 	private static PIUiPlugin plugin;
       
    36 
       
    37 	private static void setPlugin(PIUiPlugin newPlugin)
       
    38 	{
       
    39 		plugin = newPlugin;
       
    40 	}
       
    41 
       
    42 	/**
       
    43 	 * The constructor.
       
    44 	 */
       
    45 	public PIUiPlugin() {
       
    46 		setPlugin(this);
       
    47 	}
       
    48 
       
    49 	/**
       
    50 	 * This method is called upon plug-in activation
       
    51 	 */
       
    52 	public void start(BundleContext context) throws Exception {
       
    53 		super.start(context);
       
    54 	}
       
    55 
       
    56 	/**
       
    57 	 * This method is called when the plug-in is stopped
       
    58 	 */
       
    59 	public void stop(BundleContext context) throws Exception {
       
    60 		super.stop(context);
       
    61 		setPlugin(null);
       
    62 	}
       
    63 
       
    64 	/**
       
    65 	 * Returns the shared instance.
       
    66 	 */
       
    67 	public static PIUiPlugin getDefault() {
       
    68 		return plugin;
       
    69 	}
       
    70 
       
    71 	/**
       
    72 	 * Returns an image descriptor for the image file at the given
       
    73 	 * plug-in relative path.
       
    74 	 *
       
    75 	 * @param path the path
       
    76 	 * @return the image descriptor
       
    77 	 */
       
    78 	public static ImageDescriptor getImageDescriptor(String path) {
       
    79 		return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.carbide.cpp.pi.ui", path); //$NON-NLS-1$
       
    80 	}
       
    81 
       
    82 	/**
       
    83 	 * Returns the standard display to be used. The method first checks, if
       
    84 	 * the thread calling this method has an associated display. If so, this
       
    85 	 * display is returned. Otherwise the method returns the default display.
       
    86 	 */
       
    87 	public static Display getStandardDisplay() {
       
    88 		Display display= Display.getCurrent();
       
    89 		if (display == null) {
       
    90 			display= Display.getDefault();
       
    91 		}
       
    92 		return display;		
       
    93 	}
       
    94 
       
    95 	public void log(Throwable e) {
       
    96 		log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, Messages.getString("PIUiPlugin.error"), e)); //$NON-NLS-1$
       
    97 	}
       
    98 
       
    99 	public void log(IStatus status) {
       
   100 		getLog().log(status);
       
   101 	}
       
   102 }