Adding new code for feature save on unfocus. This is from ticket #542. It also adds...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / ImageStore.java
index 4d643d7..8d3305c 100644 (file)
@@ -25,6 +25,7 @@ public class ImageStore {
        
        private static final String VERSION_2 = "_2x";
        private static final String GIF_FILE_EXTENSION = ".gif";
+       private static final String JPG_FILE_EXTENSION = ".jpg";
        
        public static final String ADD = "add";
        public static final String ADD_SCHEMA = "add_schema";
@@ -35,6 +36,9 @@ public class ImageStore {
        public static final String CLASS = "class";
        public static final String CLEAR = "clear";
        public static final String CLOSE = "close";
+       public static final String CLOSE_DISABLED = "close_disabled";
+       public static final String CLOSE_ALL = "close_all";
+       public static final String CLOSE_ALL_DISABLED = "close_all_disabled";
        public static final String COLUMN = "column";
        public static final String CONNECT = "connect";
        public static final String CONNECTED = "connected";
@@ -46,6 +50,7 @@ public class ImageStore {
        public static final String EDIT = "edit";
        public static final String ENTITYGROUP = "entitygroup";
        public static final String EXPORT = "export";
+       public static final String EXTERNAL_JAR = "external_jar";
        public static final String FILTER = "filter";
        public static final String FOREIGNKEY = "foreignkey";
        public static final String FULLDATA = "fulldata";
@@ -58,6 +63,8 @@ public class ImageStore {
        public static final String MISSINGSCHEMA = "missingschema";
        public static final String MISSINGTABLE = "table";
        public static final String NEXT = "next";
+       public static final String NEW_BOOKMARK = "new_bookmark";
+       public static final String NEW_BOOKMARK_WIZARD = "new_bookmark_wizard";
        public static final String OPEN_TABLE = "table";
        public static final String PASTE = "paste";
        public static final String PLAY = "play";
@@ -75,13 +82,16 @@ public class ImageStore {
        public static final String SUBSET = "subset";
        public static final String SUCCESS = "success";
        public static final String TABLE = "bigtable";
+       public static final String SYNONYM_TABLE = "big_syn_table";
+       public static final String TABLE_DETAILS = "table_details";
        public static final String TEMPLATE = "template";
-       public static final String TORQUE = "torque";
        public static final String TRIGGER = "trigger";
        public static final String USER = "user";
        public static final String VIEW = "view";
        public static final String WARNING = "warning";
        public static final String XML = "xml";
+       public static final String CHECKED = "checked";
+       public static final String UNCHECKED = "unchecked";
        
        public static ImageDescriptor getImageDescriptor(String imageName) {
                return getImageDescriptor(imageName, QuantumPlugin.getDefault());
@@ -96,42 +106,54 @@ public class ImageStore {
         * @param default1
         * @return
         */
-       private static Image getImage(String imageName, AbstractUIPlugin plugin) {
+       public static Image getImage(String imageName, AbstractUIPlugin plugin) {
                ImageRegistry registry = plugin.getImageRegistry();
                String key = stripSuffix(imageName);
-               Image image = registry.get(getVersionAppropriateImage(key));
+               Image image = registry.get(getVersionAppropriateImage(key, plugin));
                return image;
        }
 
        public static ImageDescriptor getImageDescriptor(String imageName, AbstractUIPlugin plugin) {
                ImageRegistry registry = plugin.getImageRegistry();
                String key = stripSuffix(imageName);
-               key = getVersionAppropriateImage(key);
+               key = getVersionAppropriateImage(key, plugin);
 
                if (VersioningHelper.isEclipse21OrHigher()) {
                        return VersioningHelper.getDescriptor(registry, key);
                } else {
-                       return (ImageDescriptor) imageDescriptorMap.get(key);
+                       return (ImageDescriptor) getImageDescriptorMap(plugin).get(key);
                }
        }
+       
+       private static Map getImageDescriptorMap(AbstractUIPlugin plugin) {
+               String key = plugin.getClass().getName();
+               if (!imageDescriptorMap.containsKey(key)) {
+                       imageDescriptorMap.put(key, new HashMap());
+               }
+               return (Map) imageDescriptorMap.get(key);
+       }
 
        /**
         * @param imageName
         * @return
         */
        private static String stripSuffix(String imageName) {
-               return imageName.endsWith(GIF_FILE_EXTENSION) 
-                       ? imageName.substring(0, imageName.length() - 4)
-                       : imageName;
+               if (imageName.endsWith(GIF_FILE_EXTENSION)) {
+                       return imageName.substring(0, imageName.length() - 4);
+               }else if (imageName.endsWith(JPG_FILE_EXTENSION)) {
+                               return imageName.substring(0, imageName.length() - 4);
+               } else {
+                       return imageName;
+               }
        }
 
        /**
         * @param imageName
         * @return
         */
-       private static String getVersionAppropriateImage(String imageName) {
+       private static String getVersionAppropriateImage(String imageName, AbstractUIPlugin plugin) {
                String version2Key = imageName + VERSION_2;
-               return !VersioningHelper.isEclipse30() && imageDescriptorMap.containsKey(version2Key) 
+               return !VersioningHelper.isEclipse30() && getImageDescriptorMap(plugin).containsKey(version2Key) 
                        ? version2Key : imageName;
        }
 
@@ -139,87 +161,99 @@ public class ImageStore {
         * @param registry
         * @param url
         */
-       static void initialize(ImageRegistry registry, URL url) {
+       static void initialize(AbstractUIPlugin plugin, ImageRegistry registry, URL url) {
                
-               addImage(registry, url, ADD);
-               addImage(registry, url, BOOKMARK);
-               addImage(registry, url, DISCONNECT);
-               addImage(registry, url, ADD);
-               addImage(registry, url, ADD_SCHEMA);
-               addImage(registry, url, APPEND);
-               addImage(registry, url, AUTOCOMMIT);
-               addImage(registry, url, BOOKMARK);
-               addImage(registry, url, BOOKMARKFILE);
-               addImage(registry, url, CLASS);
-               addImage(registry, url, CLEAR);
-               addImage(registry, url, CLOSE);
-               addImage(registry, url, COLUMN);
-               addImage(registry, url, CONNECT);
-               addImage(registry, url, CONNECTED);
-               addImage(registry, url, COPY);
-               addImage(registry, url, CUT);
-               addImage(registry, url, DELETE);
-               addImage(registry, url, DISCONNECT);
-               addImage(registry, url, DRIVER);
-               addImage(registry, url, EDIT);
-               addImage(registry, url, ENTITYGROUP);
-               addImage(registry, url, EXPORT);
-               addImage(registry, url, FILTER);
-               addImage(registry, url, FOREIGNKEY);
-               addImage(registry, url, FULLDATA);
-               addImage(registry, url, GRID);
-               addImage(registry, url, GROUP);
-               addImage(registry, url, IMPORT);
-               addImage(registry, url, KEY);
-               addImage(registry, url, KEYCOLUMN);
-               addImage(registry, url, LOG);
-               addImage(registry, url, MISSINGSCHEMA);
-               addImage(registry, url, MISSINGTABLE);
-               addImage(registry, url, NEXT);
-               addImage(registry, url, PASTE);
-               addImage(registry, url, PLAY);
-               addImage(registry, url, PREVIOUS);
-               addImage(registry, url, QMODEL);
-               addImage(registry, url, QUANTUM);
-               addImage(registry, url, REFRESH);
-               addImage(registry, url, ROLLBACK);
-               addImage(registry, url, SAMPLE);
-               addImage(registry, url, SCHEMA);
-               addImage(registry, url, SCRIPT);
-               addImage(registry, url, SEQUENCE);
-               addImage(registry, url, STATEMENT);
-               addImage(registry, url, STOP);
-               addImage(registry, url, SUBSET);
-               addImage(registry, url, SUCCESS);
-               addImage(registry, url, TABLE);
-               addImage(registry, url, TEMPLATE);
-               addImage(registry, url, TORQUE);
-               addImage(registry, url, TRIGGER);
-               addImage(registry, url, USER);
-               addImage(registry, url, VIEW);
-               addImage(registry, url, WARNING);
-               addImage(registry, url, XML);
+               addImage(plugin, registry, url, ADD);
+               addImage(plugin, registry, url, BOOKMARK);
+               addImage(plugin, registry, url, DISCONNECT);
+               addImage(plugin, registry, url, ADD);
+               addImage(plugin, registry, url, ADD_SCHEMA);
+               addImage(plugin, registry, url, APPEND);
+               addImage(plugin, registry, url, AUTOCOMMIT);
+               addImage(plugin, registry, url, BOOKMARK);
+               addImage(plugin, registry, url, BOOKMARKFILE);
+               addImage(plugin, registry, url, CLASS);
+               addImage(plugin, registry, url, CLEAR);
+               addImage(plugin, registry, url, CLOSE);
+               addImage(plugin, registry, url, CLOSE_DISABLED);
+               addImage(plugin, registry, url, CLOSE_ALL);
+               addImage(plugin, registry, url, CLOSE_ALL_DISABLED);
+               addImage(plugin, registry, url, COLUMN);
+               addImage(plugin, registry, url, CONNECT);
+               addImage(plugin, registry, url, CONNECTED);
+               addImage(plugin, registry, url, COPY);
+               addImage(plugin, registry, url, CUT);
+               addImage(plugin, registry, url, DELETE);
+               addImage(plugin, registry, url, DISCONNECT);
+               addImage(plugin, registry, url, DRIVER);
+               addImage(plugin, registry, url, EDIT);
+               addImage(plugin, registry, url, ENTITYGROUP);
+               addImage(plugin, registry, url, EXPORT);
+               addImage(plugin, registry, url, EXTERNAL_JAR);
+               addImage(plugin, registry, url, FILTER);
+               addImage(plugin, registry, url, FOREIGNKEY);
+               addImage(plugin, registry, url, FULLDATA);
+               addImage(plugin, registry, url, GRID);
+               addImage(plugin, registry, url, GROUP);
+               addImage(plugin, registry, url, IMPORT);
+               addImage(plugin, registry, url, KEY);
+               addImage(plugin, registry, url, KEYCOLUMN);
+               addImage(plugin, registry, url, LOG);
+               addImage(plugin, registry, url, MISSINGSCHEMA);
+               addImage(plugin, registry, url, MISSINGTABLE);
+               addImage(plugin, registry, url, NEXT);
+               addImage(plugin, registry, url, NEW_BOOKMARK);
+               addImage(plugin, registry, url, NEW_BOOKMARK_WIZARD, JPG_FILE_EXTENSION);
+               addImage(plugin, registry, url, PASTE);
+               addImage(plugin, registry, url, PLAY);
+               addImage(plugin, registry, url, PREVIOUS);
+               addImage(plugin, registry, url, QMODEL);
+               addImage(plugin, registry, url, QUANTUM);
+               addImage(plugin, registry, url, REFRESH);
+               addImage(plugin, registry, url, ROLLBACK);
+               addImage(plugin, registry, url, SAMPLE);
+               addImage(plugin, registry, url, SCHEMA);
+               addImage(plugin, registry, url, SCRIPT);
+               addImage(plugin, registry, url, SEQUENCE);
+               addImage(plugin, registry, url, STATEMENT);
+               addImage(plugin, registry, url, STOP);
+               addImage(plugin, registry, url, SUBSET);
+               addImage(plugin, registry, url, SUCCESS);
+               addImage(plugin, registry, url, TABLE);
+               addImage(plugin, registry, url, SYNONYM_TABLE);
+               addImage(plugin, registry, url, TABLE_DETAILS);
+               addImage(plugin, registry, url, TEMPLATE);
+               addImage(plugin, registry, url, TRIGGER);
+               addImage(plugin, registry, url, USER);
+               addImage(plugin, registry, url, VIEW);
+               addImage(plugin, registry, url, WARNING);
+               addImage(plugin, registry, url, XML);
+               addImage(plugin, registry, url, CHECKED);
+               addImage(plugin, registry, url, UNCHECKED);
                
                if (!VersioningHelper.isEclipse30()) {
-                       addImage(registry, url, CLOSE + VERSION_2);
-                       addImage(registry, url, COPY + VERSION_2);
-                       addImage(registry, url, DELETE + VERSION_2);
-                       addImage(registry, url, EXPORT + VERSION_2);
-                       addImage(registry, url, IMPORT + VERSION_2);
-                       addImage(registry, url, PASTE + VERSION_2);
-                       addImage(registry, url, REFRESH + VERSION_2);
+                       addImage(plugin, registry, url, CLOSE + VERSION_2);
+                       addImage(plugin, registry, url, CLOSE_ALL + VERSION_2);
+                       addImage(plugin, registry, url, COPY + VERSION_2);
+                       addImage(plugin, registry, url, DELETE + VERSION_2);
+                       addImage(plugin, registry, url, EXPORT + VERSION_2);
+                       addImage(plugin, registry, url, EXTERNAL_JAR + VERSION_2);
+                       addImage(plugin, registry, url, IMPORT + VERSION_2);
+                       addImage(plugin, registry, url, PASTE + VERSION_2);
+                       addImage(plugin, registry, url, REFRESH + VERSION_2);
                }
        }
+       public static void addImage(AbstractUIPlugin plugin, ImageRegistry registry, 
+                       URL url, String key) {
+               addImage(plugin, registry, url, key, GIF_FILE_EXTENSION);
+       }
 
-       /**
-        * @param registry
-        * @param url
-        */
-       private static void addImage(ImageRegistry registry, URL url, String key) {
+       public static void addImage(AbstractUIPlugin plugin, ImageRegistry registry, 
+                       URL url, String key, String extension) {
                try {
                        ImageDescriptor descriptor = ImageDescriptor.createFromURL(
-                                       new URL(url, key + GIF_FILE_EXTENSION));
-                       ImageStore.imageDescriptorMap.put(key, descriptor);
+                                       new URL(url, key + extension));
+                       getImageDescriptorMap(plugin).put(key, descriptor);
                        registry.put(key, descriptor);
                } catch (MalformedURLException e) {
                        // skip, but try to go on to the next one...