3 import java.net.MalformedURLException;
5 import java.util.Collections;
6 import java.util.HashMap;
10 import com.quantum.util.versioning.VersioningHelper;
12 import org.eclipse.jface.resource.ImageDescriptor;
13 import org.eclipse.jface.resource.ImageRegistry;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.ui.plugin.AbstractUIPlugin;
22 public class ImageStore {
24 private static final Map imageDescriptorMap = Collections.synchronizedMap(new HashMap());
26 private static final String VERSION_2 = "_2x";
27 private static final String GIF_FILE_EXTENSION = ".gif";
29 public static final String ADD = "add";
30 public static final String ADD_SCHEMA = "add_schema";
31 public static final String APPEND = "append";
32 public static final String AUTOCOMMIT = "autocommit";
33 public static final String BOOKMARK = "bookmarks";
34 public static final String BOOKMARKFILE = "bookmarkfile";
35 public static final String CLASS = "class";
36 public static final String CLEAR = "clear";
37 public static final String CLOSE = "close";
38 public static final String COLUMN = "column";
39 public static final String CONNECT = "connect";
40 public static final String CONNECTED = "connected";
41 public static final String COPY = "copy";
42 public static final String CUT = "cut";
43 public static final String DELETE = "delete";
44 public static final String DISCONNECT = "disconnect";
45 public static final String DRIVER = "driver";
46 public static final String EDIT = "edit";
47 public static final String ENTITYGROUP = "entitygroup";
48 public static final String EXPORT = "export";
49 public static final String FILTER = "filter";
50 public static final String FOREIGNKEY = "foreignkey";
51 public static final String FULLDATA = "fulldata";
52 public static final String GRID = "grid";
53 public static final String GROUP = "group";
54 public static final String IMPORT = "import";
55 public static final String KEY = "key";
56 public static final String KEYCOLUMN = "keycolumn";
57 public static final String LOG = "log";
58 public static final String MISSINGSCHEMA = "missingschema";
59 public static final String MISSINGTABLE = "table";
60 public static final String NEXT = "next";
61 public static final String OPEN_TABLE = "table";
62 public static final String PASTE = "paste";
63 public static final String PLAY = "play";
64 public static final String PREVIOUS = "previous";
65 public static final String QMODEL = "qmodel";
66 public static final String QUANTUM = "quantum";
67 public static final String REFRESH = "refresh";
68 public static final String ROLLBACK = "rollback";
69 public static final String SAMPLE = "sample";
70 public static final String SCHEMA = "schema";
71 public static final String SCRIPT = "script";
72 public static final String SEQUENCE = "sequence";
73 public static final String STATEMENT = "statement";
74 public static final String STOP = "stop";
75 public static final String SUBSET = "subset";
76 public static final String SUCCESS = "success";
77 public static final String TABLE = "bigtable";
78 public static final String TEMPLATE = "template";
79 public static final String TORQUE = "torque";
80 public static final String TRIGGER = "trigger";
81 public static final String USER = "user";
82 public static final String VIEW = "view";
83 public static final String WARNING = "warning";
84 public static final String XML = "xml";
86 public static ImageDescriptor getImageDescriptor(String imageName) {
87 return getImageDescriptor(imageName, QuantumPlugin.getDefault());
90 public static Image getImage(String imageName) {
91 return getImage(imageName, QuantumPlugin.getDefault());
99 private static Image getImage(String imageName, AbstractUIPlugin plugin) {
100 ImageRegistry registry = plugin.getImageRegistry();
101 String key = stripSuffix(imageName);
102 Image image = registry.get(getVersionAppropriateImage(key));
106 public static ImageDescriptor getImageDescriptor(String imageName, AbstractUIPlugin plugin) {
107 ImageRegistry registry = plugin.getImageRegistry();
108 String key = stripSuffix(imageName);
109 key = getVersionAppropriateImage(key);
111 if (VersioningHelper.isEclipse21OrHigher()) {
112 return VersioningHelper.getDescriptor(registry, key);
114 return (ImageDescriptor) imageDescriptorMap.get(key);
122 private static String stripSuffix(String imageName) {
123 return imageName.endsWith(GIF_FILE_EXTENSION)
124 ? imageName.substring(0, imageName.length() - 4)
132 private static String getVersionAppropriateImage(String imageName) {
133 String version2Key = imageName + VERSION_2;
134 return !VersioningHelper.isEclipse30() && imageDescriptorMap.containsKey(version2Key)
135 ? version2Key : imageName;
142 static void initialize(ImageRegistry registry, URL url) {
144 addImage(registry, url, ADD);
145 addImage(registry, url, BOOKMARK);
146 addImage(registry, url, DISCONNECT);
147 addImage(registry, url, ADD);
148 addImage(registry, url, ADD_SCHEMA);
149 addImage(registry, url, APPEND);
150 addImage(registry, url, AUTOCOMMIT);
151 addImage(registry, url, BOOKMARK);
152 addImage(registry, url, BOOKMARKFILE);
153 addImage(registry, url, CLASS);
154 addImage(registry, url, CLEAR);
155 addImage(registry, url, CLOSE);
156 addImage(registry, url, COLUMN);
157 addImage(registry, url, CONNECT);
158 addImage(registry, url, CONNECTED);
159 addImage(registry, url, COPY);
160 addImage(registry, url, CUT);
161 addImage(registry, url, DELETE);
162 addImage(registry, url, DISCONNECT);
163 addImage(registry, url, DRIVER);
164 addImage(registry, url, EDIT);
165 addImage(registry, url, ENTITYGROUP);
166 addImage(registry, url, EXPORT);
167 addImage(registry, url, FILTER);
168 addImage(registry, url, FOREIGNKEY);
169 addImage(registry, url, FULLDATA);
170 addImage(registry, url, GRID);
171 addImage(registry, url, GROUP);
172 addImage(registry, url, IMPORT);
173 addImage(registry, url, KEY);
174 addImage(registry, url, KEYCOLUMN);
175 addImage(registry, url, LOG);
176 addImage(registry, url, MISSINGSCHEMA);
177 addImage(registry, url, MISSINGTABLE);
178 addImage(registry, url, NEXT);
179 addImage(registry, url, PASTE);
180 addImage(registry, url, PLAY);
181 addImage(registry, url, PREVIOUS);
182 addImage(registry, url, QMODEL);
183 addImage(registry, url, QUANTUM);
184 addImage(registry, url, REFRESH);
185 addImage(registry, url, ROLLBACK);
186 addImage(registry, url, SAMPLE);
187 addImage(registry, url, SCHEMA);
188 addImage(registry, url, SCRIPT);
189 addImage(registry, url, SEQUENCE);
190 addImage(registry, url, STATEMENT);
191 addImage(registry, url, STOP);
192 addImage(registry, url, SUBSET);
193 addImage(registry, url, SUCCESS);
194 addImage(registry, url, TABLE);
195 addImage(registry, url, TEMPLATE);
196 addImage(registry, url, TORQUE);
197 addImage(registry, url, TRIGGER);
198 addImage(registry, url, USER);
199 addImage(registry, url, VIEW);
200 addImage(registry, url, WARNING);
201 addImage(registry, url, XML);
203 if (!VersioningHelper.isEclipse30()) {
204 addImage(registry, url, CLOSE + VERSION_2);
205 addImage(registry, url, COPY + VERSION_2);
206 addImage(registry, url, DELETE + VERSION_2);
207 addImage(registry, url, EXPORT + VERSION_2);
208 addImage(registry, url, IMPORT + VERSION_2);
209 addImage(registry, url, PASTE + VERSION_2);
210 addImage(registry, url, REFRESH + VERSION_2);
218 private static void addImage(ImageRegistry registry, URL url, String key) {
220 ImageDescriptor descriptor = ImageDescriptor.createFromURL(
221 new URL(url, key + GIF_FILE_EXTENSION));
222 ImageStore.imageDescriptorMap.put(key, descriptor);
223 registry.put(key, descriptor);
224 } catch (MalformedURLException e) {
225 // skip, but try to go on to the next one...