|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui; |
|
6 |
|
7 import org.eclipse.core.runtime.IStatus; |
|
8 import org.eclipse.jface.dialogs.ErrorDialog; |
|
9 import org.eclipse.jface.dialogs.MessageDialog; |
|
10 import org.eclipse.swt.widgets.Display; |
|
11 import org.eclipse.swt.widgets.Shell; |
|
12 import org.eclipse.ui.IWorkbenchWindow; |
|
13 import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
14 import org.osgi.framework.BundleContext; |
|
15 |
|
16 /** |
|
17 * The activator class controls the plug-in life cycle |
|
18 */ |
|
19 public class ChromiumDebugUIPlugin extends AbstractUIPlugin { |
|
20 |
|
21 /** The plug-in ID. */ |
|
22 public static final String PLUGIN_ID = "org.chromium.debug.ui"; //$NON-NLS-1$ |
|
23 |
|
24 /** Editor ID for JS files. */ |
|
25 public static final String EDITOR_ID = PLUGIN_ID + ".editor"; //$NON-NLS-1$ |
|
26 |
|
27 /** The shared instance. */ |
|
28 private static ChromiumDebugUIPlugin plugin; |
|
29 |
|
30 public ChromiumDebugUIPlugin() { |
|
31 } |
|
32 |
|
33 @Override |
|
34 public void start(BundleContext context) throws Exception { |
|
35 super.start(context); |
|
36 plugin = this; |
|
37 JsEvalContextManager.startup(); |
|
38 } |
|
39 |
|
40 @Override |
|
41 public void stop(BundleContext context) throws Exception { |
|
42 plugin = null; |
|
43 super.stop(context); |
|
44 } |
|
45 |
|
46 /** |
|
47 * Returns the shared instance. |
|
48 * |
|
49 * @return the shared instance |
|
50 */ |
|
51 public static ChromiumDebugUIPlugin getDefault() { |
|
52 return plugin; |
|
53 } |
|
54 |
|
55 /** |
|
56 * @return a current display, or the default one if the current one is not |
|
57 * available |
|
58 */ |
|
59 public static Display getDisplay() { |
|
60 Display display = Display.getCurrent(); |
|
61 if (display == null) { |
|
62 display = Display.getDefault(); |
|
63 } |
|
64 return display; |
|
65 } |
|
66 |
|
67 /** |
|
68 * @return the active workbench shell, or {@code null} if one is not available |
|
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 * @return the active workbench window |
|
80 */ |
|
81 public static IWorkbenchWindow getActiveWorkbenchWindow() { |
|
82 return getDefault().getWorkbench().getActiveWorkbenchWindow(); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Creates a status dialog using the given {@code status}. |
|
87 * |
|
88 * @param status to derive the severity |
|
89 */ |
|
90 public static void statusDialog(IStatus status) { |
|
91 switch (status.getSeverity()) { |
|
92 case IStatus.ERROR: |
|
93 statusDialog(Messages.ChromiumDebugUIPlugin_Error, status); |
|
94 break; |
|
95 case IStatus.WARNING: |
|
96 statusDialog(Messages.ChromiumDebugUIPlugin_Warning, status); |
|
97 break; |
|
98 case IStatus.INFO: |
|
99 statusDialog(Messages.ChromiumDebugUIPlugin_Info, status); |
|
100 break; |
|
101 } |
|
102 } |
|
103 |
|
104 /** |
|
105 * Creates a status dialog using the given {@code status} and {@code title}. |
|
106 * |
|
107 * @param title of the dialog |
|
108 * @param status to derive the severity |
|
109 */ |
|
110 public static void statusDialog(String title, IStatus status) { |
|
111 Shell shell = getActiveWorkbenchWindow().getShell(); |
|
112 if (shell != null) { |
|
113 switch (status.getSeverity()) { |
|
114 case IStatus.ERROR: |
|
115 ErrorDialog.openError(shell, title, null, status); |
|
116 break; |
|
117 case IStatus.WARNING: |
|
118 MessageDialog.openWarning(shell, title, status.getMessage()); |
|
119 break; |
|
120 case IStatus.INFO: |
|
121 MessageDialog.openInformation(shell, title, status.getMessage()); |
|
122 break; |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 } |