newest quantum CVS sources
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / QuantumPlugin.java
index 140a149..d3028d8 100644 (file)
@@ -5,18 +5,13 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import com.quantum.model.BookmarkCollection;
-import com.quantum.util.xml.XMLHelper;
-import com.quantum.view.subset.SubsetContentProvider;
-
-import org.eclipse.core.resources.ISaveContext;
-import org.eclipse.core.resources.ISaveParticipant;
 import org.eclipse.core.resources.ISavedState;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
@@ -26,6 +21,7 @@ import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.dnd.Clipboard;
 import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.Image;
@@ -41,16 +37,27 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
+import com.quantum.model.BookmarkCollection;
+import com.quantum.util.xml.XMLHelper;
+import com.quantum.view.subset.SubsetContentProvider;
+
 /**
- * @author root
  * Main class of the quantum plugin, sets defaults, saves and recovers state.
+ * @author root
  */
 public class QuantumPlugin extends AbstractUIPlugin {
-    public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.quantum.sql";
+    public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.quantum.sql"; 
        private static QuantumPlugin plugin;
        private Clipboard sysClip;
 
-       
+       /**
+        * 
+        * TODO: BCH - this constructor has changed in Eclipse 3.0.  This
+        * old version of the constructor is still necessary for running under
+        * Eclipse 2.x.
+        * 
+        * @param descriptor
+        */
        public QuantumPlugin(IPluginDescriptor descriptor) {
                super(descriptor);
                plugin = this;
@@ -107,11 +114,10 @@ public class QuantumPlugin extends AbstractUIPlugin {
         */
        public void startup() throws CoreException {
                super.startup();
-               ISaveParticipant saveParticipant = new QuantumSaveParticipant();
                ISavedState lastState =
                        ResourcesPlugin.getWorkspace().addSaveParticipant(
                                this,
-                               saveParticipant);
+                               new QuantumSaveParticipant());
                if (lastState != null) {
                IPath location = lastState.lookup(new Path(Messages.getString("QuantumPlugin.saveDir"))); //$NON-NLS-1$
                if (location != null) {
@@ -128,8 +134,10 @@ public class QuantumPlugin extends AbstractUIPlugin {
         * @see org.eclipse.core.runtime.Plugin#shutdown()
         */
        public void shutdown() throws CoreException {
+               if (!sysClip.isDisposed()) {
+                       sysClip.dispose();
+               }
                super.shutdown();
-//             sysClip.dispose();
        }
 
        /**
@@ -148,7 +156,7 @@ public class QuantumPlugin extends AbstractUIPlugin {
 
             FileWriter writer =  new FileWriter(target);
             try {
-                XMLHelper.createDOMSerializer(writer).serialize(document);
+                XMLHelper.write(writer, document);
                } finally {
                        writer.close();
                }
@@ -159,27 +167,11 @@ public class QuantumPlugin extends AbstractUIPlugin {
         }
        }
        
-       /**
-        *  Gets an image descriptof from a file in the icons directory 
-        * @param name of the file to get
-        * @return ImageDescriptor or null if not found
-        */
-       public static ImageDescriptor getImageDescriptor(String name) {
-               ImageDescriptor descriptor = null;
-               try {
-                       URL installURL =
-                               QuantumPlugin.getDefault().getDescriptor().getInstallURL();
-                       URL url = new URL(installURL, Messages.getString("QuantumPlugin.iconsDir") + name); //$NON-NLS-1$
-                       descriptor = ImageDescriptor.createFromURL(url);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-               return descriptor;
-       }
-       public static Image getImage(String name) {
-        ImageDescriptor imageDescriptor = getImageDescriptor(name);
-               return imageDescriptor == null ? null : imageDescriptor.createImage();
-       }
+       
+//     public static Image getImage(String name) {
+//        ImageDescriptor imageDescriptor = getImageDescriptor(name);
+//             return imageDescriptor == null ? null : imageDescriptor.createImage();
+//     }
 
        protected void initializeDefaultPluginPreferences() {
                RGB BACKGROUND = new RGB(255, 255, 255);
@@ -208,7 +200,8 @@ public class QuantumPlugin extends AbstractUIPlugin {
                getPreferenceStore().setDefault("quantum.numeric.bold", false); //$NON-NLS-1$
                PreferenceConverter.setDefault(getPreferenceStore(), "quantum.font", (FontData) null); //$NON-NLS-1$
         getPreferenceStore().setDefault("com.quantum.model.Bookmark.queryHistorySize", 20); //$NON-NLS-1$
-        
+           
+
         getPreferenceStore().setDefault(
             "phpeclipse.sql.select.template",
             "$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");");
@@ -267,68 +260,27 @@ public class QuantumPlugin extends AbstractUIPlugin {
                return tableView;
        }
 
-
-
-       class QuantumSaveParticipant implements ISaveParticipant {
-               /**
-               * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
-               */
-               public void doneSaving(ISaveContext context) {
-               }
-               /**
-                * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
-                */
-               public void prepareToSave(ISaveContext context) throws CoreException {
-               }
-
-               /**
-                * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
-                */
-               public void rollback(ISaveContext context) {
-               }
-
-               /**
-                * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
-                */
-               public void saving(ISaveContext context) throws CoreException {
-                       switch (context.getKind()) {
-                               case ISaveContext.FULL_SAVE :
-                                       QuantumPlugin quantumPluginInstance = QuantumPlugin.getDefault();
-                                       // save the plug in state 
-                                       if (BookmarkCollection.getInstance().isAnythingChanged()
-                                               || SubsetContentProvider.getInstance().hasChanged()) {
-
-                                               int saveNumber = context.getSaveNumber();
-                                               String saveFileName = Messages.getString("QuantumPlugin.saveDir") + "-" + Integer.toString(saveNumber) + Messages.getString("QuantumPlugin.saveFileExtension"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                                               File f = quantumPluginInstance.getStateLocation().append(saveFileName).toFile();
-
-                                               // if we fail to write, an exception is thrown and we do not update the path 
-                                               quantumPluginInstance.writeImportantState(f);
-
-                                               context.map(new Path(Messages.getString("QuantumPlugin.saveDir")), new Path(saveFileName)); //$NON-NLS-1$
-                                               context.needSaveNumber();
-
-                                       } else {
-                                               System.out.println("Not saving unchanged bookmarks"); //$NON-NLS-1$
-                                       }
-                                       break;
-                               case ISaveContext.PROJECT_SAVE :
-                                       // get the project related to this save operation 
-                                       //IProject project = context.getProject(); 
-                                       // save its information, if necessary 
-                                       break;
-                               case ISaveContext.SNAPSHOT :
-                                       // This operation needs to be really fast because 
-                                       // snapshots can be requested frequently by the 
-                                       // workspace. 
-                                       break;
-                       }
-               }
-       }
        /**
         * @return
         */
        public Clipboard getSysClip() {
                return sysClip;
        }
+       protected void initializeImageRegistry(ImageRegistry registry) {
+               super.initializeImageRegistry(registry);
+               try {
+                       ImageStore.initialize(registry, getIconLocation());
+               } catch (MalformedURLException e) {
+                       // this should never happen, but if it does, we don't get images.
+               }
+       }
+
+       /**
+        * @return
+        * @throws MalformedURLException
+        */
+       URL getIconLocation() throws MalformedURLException {
+               URL installURL = QuantumPlugin.getDefault().getDescriptor().getInstallURL();
+               return new URL(installURL, "icons/");
+       }
 }
\ No newline at end of file