1 8 package de.loskutov.bco; 9 10 import java.util.MissingResourceException ; 11 import java.util.ResourceBundle ; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.core.runtime.Status; 15 import org.eclipse.jface.dialogs.MessageDialog; 16 import org.eclipse.swt.widgets.Shell; 17 import org.eclipse.ui.plugin.AbstractUIPlugin; 18 import org.osgi.framework.BundleContext; 19 20 23 public class BytecodeOutlinePlugin extends AbstractUIPlugin { 24 private static BytecodeOutlinePlugin plugin; 26 private ResourceBundle resourceBundle; 28 29 32 public BytecodeOutlinePlugin() { 33 super(); 34 plugin = this; 35 try { 36 resourceBundle = ResourceBundle 37 .getBundle("de.loskutov.bco.BytecodeOutlinePluginResources"); } catch (MissingResourceException x) { 39 resourceBundle = null; 40 } 41 } 42 43 48 public void start(BundleContext context) throws Exception { 49 super.start(context); 50 } 51 52 57 public void stop(BundleContext context) throws Exception { 58 super.stop(context); 59 } 60 61 65 public static BytecodeOutlinePlugin getDefault() { 66 return plugin; 67 } 68 69 74 public static String getResourceString(String key) { 75 ResourceBundle bundle = BytecodeOutlinePlugin.getDefault() 76 .getResourceBundle(); 77 try { 78 return (bundle != null) 79 ? bundle.getString(key) 80 : key; 81 } catch (MissingResourceException e) { 82 return key; 83 } 84 } 85 86 89 public ResourceBundle getResourceBundle() { 90 return resourceBundle; 91 } 92 93 97 public static Shell getShell() { 98 return getDefault().getWorkbench().getActiveWorkbenchWindow() 99 .getShell(); 100 } 101 102 106 public static void error(String messageID, Throwable error) { 107 Shell shell = getShell(); 108 String message = getResourceString("BytecodeOutline.Error"); if (messageID != null) { 110 message = getResourceString(messageID); 111 } 112 message = message + " " + error.getMessage(); MessageDialog.openError( 114 shell, getResourceString("BytecodeOutline.Title"), message); 116 117 getDefault().getLog().log( 118 new Status(IStatus.ERROR, "BytecodeOutline", 0, message, error)); } 120 121 125 public static void log(Throwable error, int statusID) { 126 String message = error.getMessage(); 127 if(message == null){ 128 message = error.toString(); 129 } 130 getDefault().getLog() 131 .log( 132 new Status( 133 statusID, 134 "BytecodeOutline", 0, message, error)); } 136 137 138 } | Popular Tags |