1 17 package org.eclipse.emf.mapping.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.Platform; 25 import org.eclipse.jface.resource.ImageDescriptor; 26 import org.eclipse.jface.resource.ImageRegistry; 27 import org.eclipse.swt.graphics.Image; 28 import org.eclipse.ui.plugin.AbstractUIPlugin; 29 30 import org.eclipse.emf.mapping.MappingFactory; 31 import org.eclipse.emf.mapping.MappingRoot; 32 33 34 37 public class MappingUIPlugin extends AbstractUIPlugin 38 { 39 42 public static MappingUIPlugin getPlugin() 43 { 44 return instance; 45 } 46 47 50 protected static MappingUIPlugin instance; 51 52 55 public MappingUIPlugin() 56 { 57 super(); 58 59 instance = this; 62 } 63 64 67 MappingRoot createInitialModel() 68 { 69 MappingRoot mappingRoot = MappingFactory.eINSTANCE.createMappingRoot(); 70 return mappingRoot; 71 } 72 73 public String getString(String key) 74 { 75 return Platform.getResourceBundle(getBundle()).getString(key); 76 } 77 78 public String getString(String key, Object s1) 79 { 80 return MessageFormat.format(getString(key), new Object [] { s1 }); 81 } 82 83 public String getString(String key, Object s1, Object s2) 84 { 85 return MessageFormat.format(getString(key), new Object [] { s1, s2 }); 86 } 87 88 91 public ImageDescriptor getImageDescriptor(String key) 92 { 93 try 94 { 95 ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(new URL (getBundle().getEntry("/"), "icons/" + key + ".gif")); 96 return imageDescriptor; 97 } 98 catch (MalformedURLException exception) 99 { 100 System.out.println("Failed to load image for '" + key + "'"); 101 exception.printStackTrace(); 102 } 103 104 return null; 105 } 106 107 110 public Image getImage(String key) 111 { 112 ImageRegistry imageRegistry = getImageRegistry(); 113 Image image = imageRegistry.get(key); 114 if (image == null) 115 { 116 imageRegistry.put(key, getImageDescriptor(key)); 117 image = imageRegistry.get(key); 118 } 119 120 return image; 121 } 122 } 123 | Popular Tags |