01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * wharley@bea.com - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.apt.ui.internal;
11:
12: import org.eclipse.core.runtime.IStatus;
13: import org.eclipse.core.runtime.Status;
14: import org.eclipse.jface.resource.ImageDescriptor;
15: import org.eclipse.swt.widgets.Shell;
16: import org.eclipse.ui.IWorkbenchWindow;
17: import org.eclipse.ui.plugin.AbstractUIPlugin;
18: import org.osgi.framework.BundleContext;
19:
20: /**
21: * The main plugin class to be used in the desktop.
22: */
23: public class AptUIPlugin extends AbstractUIPlugin {
24:
25: //The shared instance.
26: private static AptUIPlugin plugin;
27:
28: // The plugin ID
29: public static final String PLUGIN_ID = "org.eclipse.jdt.apt.ui"; //$NON-NLS-1$
30:
31: /**
32: * Status IDs for system log entries. Must be unique per plugin.
33: */
34: public static final int STATUS_EXCEPTION = 1;
35: public static final int INTERNAL_ERROR = 2;
36:
37: /**
38: * The constructor.
39: */
40: public AptUIPlugin() {
41: plugin = this ;
42: }
43:
44: /**
45: * This method is called upon plug-in activation
46: */
47: public void start(BundleContext context) throws Exception {
48: super .start(context);
49: }
50:
51: /**
52: * This method is called when the plug-in is stopped
53: */
54: public void stop(BundleContext context) throws Exception {
55: super .stop(context);
56: plugin = null;
57: }
58:
59: /**
60: * Returns the shared instance.
61: */
62: public static AptUIPlugin getDefault() {
63: return plugin;
64: }
65:
66: public static IWorkbenchWindow getActiveWorkbenchWindow() {
67: return getDefault().getWorkbench().getActiveWorkbenchWindow();
68: }
69:
70: public static Shell getActiveWorkbenchShell() {
71: IWorkbenchWindow window = getActiveWorkbenchWindow();
72: if (window != null) {
73: return window.getShell();
74: }
75: return null;
76: }
77:
78: /**
79: * Returns an image descriptor for the image file at the given
80: * plug-in relative path.
81: *
82: * @param path the path
83: * @return the image descriptor
84: */
85: public static ImageDescriptor getImageDescriptor(String path) {
86: return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID,
87: path);
88: }
89:
90: public static void log(IStatus status) {
91: getDefault().getLog().log(status);
92: }
93:
94: public static void log(Throwable e) {
95: log(new Status(IStatus.ERROR, PLUGIN_ID, STATUS_EXCEPTION,
96: Messages.AptUIPlugin_exceptionThrown, e));
97: }
98:
99: }
|