1 package net.sourceforge.phpdt.sql;
5 import java.util.ResourceBundle;
7 import org.eclipse.core.resources.ISaveContext;
8 import org.eclipse.core.resources.ISaveParticipant;
9 import org.eclipse.core.resources.ISavedState;
10 import org.eclipse.core.resources.ResourcesPlugin;
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IPath;
13 import org.eclipse.core.runtime.IPluginDescriptor;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jface.preference.IPreferenceStore;
16 import org.eclipse.jface.preference.PreferenceConverter;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.swt.graphics.FontData;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.graphics.RGB;
21 import org.eclipse.ui.plugin.AbstractUIPlugin;
23 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
24 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
29 public class PHPEclipseSQLPlugin extends AbstractUIPlugin {
30 private static final String BUNDLE_NAME =
31 "net.sourceforge.phpdt.sql.PHPEclipseSQLResources";
32 private static final ResourceBundle RESOURCE_BUNDLE =
33 ResourceBundle.getBundle(BUNDLE_NAME);
35 private static PHPEclipseSQLPlugin plugin;
36 public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.sql";
38 public PHPEclipseSQLPlugin(IPluginDescriptor descriptor) {
43 public static PHPEclipseSQLPlugin getDefault() {
46 protected void readStateFrom(File target) {
47 BookmarkContentProvider.getInstance().load(target);
50 public void startup() throws CoreException {
52 ISaveParticipant saveParticipant = new QuantumSaveParticipant();
53 ISavedState lastState =
54 ResourcesPlugin.getWorkspace().addSaveParticipant(this, saveParticipant);
55 if (lastState == null)
57 IPath location = lastState.lookup(new Path("save"));
60 // the plugin instance should read any important state from the file.
61 File f = getStateLocation().append(location).toFile();
64 protected void writeImportantState(File target) {
65 BookmarkContentProvider.getInstance().save(target);
67 public static ImageDescriptor getImageDescriptor(String name) {
68 ImageDescriptor descriptor = null;
71 PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
72 URL url = new URL(installURL, "icons/" + name);
73 descriptor = ImageDescriptor.createFromURL(url);
74 } catch (Exception e) {
79 public static Image getImage(String name) {
80 return getImageDescriptor(name).createImage();
83 public void dispose() throws CoreException {
84 MultiSQLServer.getInstance().shutdown();
87 protected void initializeDefaultPluginPreferences() {
88 RGB BACKGROUND = new RGB(255, 255, 255);
89 RGB COMMENT = new RGB(88, 148, 64);
90 RGB IDENTIFIER = new RGB(0, 0, 0);
91 RGB KEYWORD = new RGB(126, 0, 75);
92 RGB STRING = new RGB(0, 0, 255);
93 RGB NUMERIC = new RGB(255, 0, 0);
94 RGB DEFAULT = new RGB(0, 0, 0);
95 IPreferenceStore store = getPreferenceStore();
96 PreferenceConverter.setDefault(
98 "quantum.background.color",
100 PreferenceConverter.setDefault(store, "quantum.text.color", DEFAULT);
101 PreferenceConverter.setDefault(store, "quantum.keyword.color", KEYWORD);
102 PreferenceConverter.setDefault(store, "quantum.comment.color", COMMENT);
103 PreferenceConverter.setDefault(store, "quantum.string.color", STRING);
104 PreferenceConverter.setDefault(store, "quantum.numeric.color", NUMERIC);
105 getPreferenceStore().setDefault("quantum.text.bold", false);
106 getPreferenceStore().setDefault("quantum.keyword.bold", true);
107 getPreferenceStore().setDefault("quantum.string.bold", false);
108 getPreferenceStore().setDefault("quantum.comment.bold", false);
109 getPreferenceStore().setDefault("quantum.numeric.bold", false);
110 PreferenceConverter.setDefault(
111 getPreferenceStore(),
117 class QuantumSaveParticipant implements ISaveParticipant {
119 * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
121 public void doneSaving(ISaveContext context) {
125 * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
127 public void prepareToSave(ISaveContext context) throws CoreException {
131 * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
133 public void rollback(ISaveContext context) {
137 * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
139 public void saving(ISaveContext context) throws CoreException {
140 switch (context.getKind()) {
141 case ISaveContext.FULL_SAVE :
142 PHPEclipseSQLPlugin quantumPluginInstance = PHPEclipseSQLPlugin.getDefault();
143 // save the plug in state
144 if (BookmarkContentProvider.getInstance().hasChanged()) {
145 int saveNumber = context.getSaveNumber();
146 String saveFileName = "save " + Integer.toString(saveNumber);
148 quantumPluginInstance
150 .append(saveFileName)
152 // if we fail to write, an exception is thrown and we do not update the path
153 quantumPluginInstance.writeImportantState(f);
154 context.map(new Path("save"), new Path(saveFileName));
155 context.needSaveNumber();
157 System.out.println("Not saving unchanged bookmarks");
160 case ISaveContext.PROJECT_SAVE :
161 // get the project related to this save operation
162 //IProject project = context.getProject();
163 // save its information, if necessary
165 case ISaveContext.SNAPSHOT :
166 // This operation needs to be really fast because
167 // snapshots can be requested frequently by the