Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9a5060fcd4af986d3468f43f4eecd969ade15bbc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.eclipse.tm.internal.tcf.cdt.ui;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

        public static final String PLUGIN_ID = "org.eclipse.tm.tcf.cdt.ui";
        private static Activator plugin;
        
        public void start(BundleContext context) throws Exception {
                super.start(context);
                plugin = this;
        }

        public void stop(BundleContext context) throws Exception {
                plugin = null;
                super.stop(context);
        }

        public static Activator getDefault() {
                return plugin;
        }

        public static void log(IStatus status) {
                getDefault().getLog().log(status);
        }

        public static void log(Throwable e) {
                log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        }

        public static IWorkbenchWindow getActiveWorkbenchWindow() {
                return getDefault().getWorkbench().getActiveWorkbenchWindow();
        }

        public static IWorkbenchPage getActivePage() {
                IWorkbenchWindow w = getActiveWorkbenchWindow();
                if (w != null) {
                        return w.getActivePage();
                }
                return null;
        }

        public static Shell getActiveWorkbenchShell() {
                IWorkbenchWindow window = getActiveWorkbenchWindow();
                if (window != null) {
                        return window.getShell();
                }
                return null;
        }

        public static void errorDialog(String message, IStatus status) {
                log(status);
                Shell shell = getActiveWorkbenchShell();
                if (shell == null) return;
                ErrorDialog.openError(shell, "Error", message, status);
        }

        public static void errorDialog(String message, Throwable t) {
                log(t);
                Shell shell = getActiveWorkbenchShell();
                if (shell == null) return;
                IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, 1, t.getMessage(), null);
                ErrorDialog.openError(shell, "Error", message, status);
        }
}

Back to the top