1 17 package org.eclipse.emf.codegen.presentation; 18 19 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 import java.text.MessageFormat ; 23 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IStatus; 26 import org.eclipse.core.runtime.Platform; 27 import org.eclipse.core.runtime.Status; 28 import org.eclipse.jface.dialogs.ErrorDialog; 29 import org.eclipse.jface.resource.ImageDescriptor; 30 import org.eclipse.ui.plugin.AbstractUIPlugin; 31 32 import org.eclipse.emf.codegen.jet.JETException; 33 34 35 38 public class CodeGenUIPlugin extends AbstractUIPlugin 39 { 40 43 public static CodeGenUIPlugin getPlugin() 44 { 45 return plugin; 46 } 47 48 51 private static CodeGenUIPlugin plugin; 52 53 56 public CodeGenUIPlugin() 57 { 58 super(); 59 60 plugin = this; 63 } 64 65 68 public String getString(String key) 69 { 70 return Platform.getResourceBundle(plugin.getBundle()).getString(key); 71 } 72 73 public ImageDescriptor getImage(String key) 74 { 75 try 76 { 77 return ImageDescriptor.createFromURL(new URL (getBundle().getEntry("/") + "icons/" + key + ".gif")); 78 } 79 catch (MalformedURLException exception) 80 { 81 write(exception); 82 return null; 83 } 84 } 85 86 89 public String getString(String key, Object [] objects) 90 { 91 return MessageFormat.format(getString(key), objects); 92 } 93 94 public static void write(Exception exception) 95 { 96 IStatus status; 97 String message; 98 if (exception instanceof JETException) 99 { 100 status = ((JETException)exception).getStatus(); 101 message = getPlugin().getString("_UI_JETCompileProblem_message"); 102 } 103 else if (exception instanceof CoreException) 104 { 105 status = ((CoreException)exception).getStatus(); 106 message = exception.getLocalizedMessage(); 107 } 108 else 109 { 110 status = 111 new Status 112 (IStatus.ERROR, 113 getPlugin().getBundle().getSymbolicName(), 114 0, 115 exception.getLocalizedMessage(), 116 exception); 117 118 message = exception.getLocalizedMessage(); 119 } 120 121 ErrorDialog.openError 122 (getPlugin().getWorkbench().getActiveWorkbenchWindow().getShell(), 123 getPlugin().getString("_UI_JETProblem_title"), 124 message, 125 status); 126 } 127 } 128 | Popular Tags |