01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
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: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.tests.macro;
11:
12: import java.lang.reflect.InvocationTargetException;
13:
14: import org.eclipse.core.resources.ResourcesPlugin;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.core.runtime.IStatus;
17: import org.eclipse.core.runtime.Status;
18: import org.eclipse.jface.dialogs.ErrorDialog;
19: import org.eclipse.swt.widgets.Display;
20: import org.eclipse.ui.plugin.AbstractUIPlugin;
21: import org.osgi.framework.BundleContext;
22:
23: /**
24: * The main plugin class to be used in the desktop.
25: */
26: public class MacroPlugin extends AbstractUIPlugin {
27: //The shared instance.
28: private static MacroPlugin plugin;
29:
30: private MacroManager recorder;
31:
32: /**
33: * The constructor.
34: */
35: public MacroPlugin() {
36: super ();
37: plugin = this ;
38: recorder = new MacroManager();
39: }
40:
41: public MacroManager getMacroManager() {
42: return recorder;
43: }
44:
45: /**
46: * This method is called upon plug-in activation
47: */
48: public void start(BundleContext context) throws Exception {
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 {
56: recorder.shutdown();
57: super .stop(context);
58: }
59:
60: /**
61: * Returns the shared instance.
62: */
63: public static MacroPlugin getDefault() {
64: return plugin;
65: }
66:
67: public static void logException(Throwable e) {
68: logException(e, null, null);
69: }
70:
71: public static void logException(Throwable e, final String title,
72: String message) {
73: if (e instanceof InvocationTargetException) {
74: e = ((InvocationTargetException) e).getTargetException();
75: }
76: IStatus status = null;
77: if (e instanceof CoreException)
78: status = ((CoreException) e).getStatus();
79: else {
80: if (message == null)
81: message = e.getMessage();
82: if (message == null)
83: message = e.toString();
84: status = new Status(IStatus.ERROR,
85: "org.eclipse.pde.ui.tests", IStatus.OK, message, e);
86: }
87: ResourcesPlugin.getPlugin().getLog().log(status);
88: Display display = Display.getCurrent();
89: if (display == null)
90: display = Display.getDefault();
91: final IStatus fstatus = status;
92: display.asyncExec(new Runnable() {
93: public void run() {
94: ErrorDialog.openError(null, title, null, fstatus);
95: }
96: });
97: }
98: }
|