1 11 12 package org.eclipse.ui.console; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.jface.dialogs.ErrorDialog; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.ui.internal.console.ConsoleManager; 23 import org.eclipse.ui.internal.console.ConsolePluginImages; 24 import org.eclipse.ui.plugin.AbstractUIPlugin; 25 import org.osgi.framework.BundleContext; 26 27 32 33 public class ConsolePlugin extends AbstractUIPlugin { 34 35 38 private IConsoleManager fConsoleManager = null; 39 40 43 private static ConsolePlugin fgPlugin= null; 44 45 49 private static final String PI_UI_CONSOLE = "org.eclipse.ui.console"; 51 54 public static ConsolePlugin getDefault() { 55 return fgPlugin; 56 } 57 58 public ConsolePlugin() { 59 super(); 60 fgPlugin = this; 61 } 62 63 66 public static String getUniqueIdentifier() { 67 return PI_UI_CONSOLE; 68 } 69 70 75 public static void log(IStatus status) { 76 getDefault().getLog().log(status); 77 } 78 79 84 public static void log(Throwable t) { 85 if (t instanceof CoreException) { 86 log(((CoreException)t).getStatus()); 87 } else { 88 log(newErrorStatus("Error logged from Console plug-in: ", t)); } 90 } 91 92 98 public static IStatus newErrorStatus(String message, Throwable exception) { 99 return new Status(IStatus.ERROR, getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, message, exception); 100 } 101 102 108 public IConsoleManager getConsoleManager() { 109 if (fConsoleManager == null) { 110 fConsoleManager = new ConsoleManager(); 111 } 112 return fConsoleManager; 113 } 114 115 120 public static Display getStandardDisplay() { 121 Display display= Display.getCurrent(); 122 if (display == null) { 123 display= Display.getDefault(); 124 } 125 return display; 126 } 127 128 131 public static void errorDialog(Shell shell, String title, String message, Throwable t) { 132 IStatus status; 133 if (t instanceof CoreException) { 134 status= ((CoreException)t).getStatus(); 135 if (status != null && message.equals(status.getMessage())) { 138 message= null; 139 } 140 } else { 141 status= new Status(IStatus.ERROR, getUniqueIdentifier(), IConsoleConstants.INTERNAL_ERROR, "Error within Debug UI: ", t); log(status); 143 } 144 ErrorDialog.openError(shell, title, message, status); 145 } 146 147 155 public static Image getImage(String key) { 156 return ConsolePluginImages.getImage(key); 157 } 158 159 167 public static ImageDescriptor getImageDescriptor(String key) { 168 return ConsolePluginImages.getImageDescriptor(key); 169 } 170 171 174 public void stop(BundleContext context) throws Exception { 175 if (fConsoleManager != null) { 176 IConsole[] consoles = fConsoleManager.getConsoles(); 177 if (consoles != null) { 178 fConsoleManager.removeConsoles(consoles); 179 } 180 } 181 super.stop(context); 182 } 183 184 185 } 186 | Popular Tags |