KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > ui > internal > AptUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.apt.ui.internal;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.ui.IWorkbenchWindow;
18 import org.eclipse.ui.plugin.AbstractUIPlugin;
19 import org.osgi.framework.BundleContext;
20
21 /**
22  * The main plugin class to be used in the desktop.
23  */

24 public class AptUIPlugin extends AbstractUIPlugin {
25
26     //The shared instance.
27
private static AptUIPlugin plugin;
28     
29     // The plugin ID
30
public static final String JavaDoc PLUGIN_ID = "org.eclipse.jdt.apt.ui"; //$NON-NLS-1$
31

32     /**
33      * Status IDs for system log entries. Must be unique per plugin.
34      */

35     public static final int STATUS_EXCEPTION = 1;
36     public static final int INTERNAL_ERROR = 2;
37
38     /**
39      * The constructor.
40      */

41     public AptUIPlugin() {
42         plugin = this;
43     }
44
45     /**
46      * This method is called upon plug-in activation
47      */

48     public void start(BundleContext context) throws Exception JavaDoc {
49         super.start(context);
50     }
51
52     /**
53      * This method is called when the plug-in is stopped
54      */

55     public void stop(BundleContext context) throws Exception JavaDoc {
56         super.stop(context);
57         plugin = null;
58     }
59
60     /**
61      * Returns the shared instance.
62      */

63     public static AptUIPlugin getDefault() {
64         return plugin;
65     }
66
67     public static IWorkbenchWindow getActiveWorkbenchWindow() {
68         return getDefault().getWorkbench().getActiveWorkbenchWindow();
69     }
70     
71     public static Shell getActiveWorkbenchShell() {
72          IWorkbenchWindow window= getActiveWorkbenchWindow();
73          if (window != null) {
74             return window.getShell();
75          }
76          return null;
77     }
78     
79     /**
80      * Returns an image descriptor for the image file at the given
81      * plug-in relative path.
82      *
83      * @param path the path
84      * @return the image descriptor
85      */

86     public static ImageDescriptor getImageDescriptor(String JavaDoc path) {
87         return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
88     }
89     
90     public static void log(IStatus status) {
91         getDefault().getLog().log(status);
92     }
93     
94     public static void log(Throwable JavaDoc e) {
95         log(new Status(IStatus.ERROR, PLUGIN_ID, STATUS_EXCEPTION, Messages.AptUIPlugin_exceptionThrown, e));
96     }
97     
98 }
99
Popular Tags