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 implements IConstants {
31 private static final String BUNDLE_NAME =
32 "net.sourceforge.phpdt.sql.PHPEclipseSQLResources";
33 private static final ResourceBundle RESOURCE_BUNDLE =
34 ResourceBundle.getBundle(BUNDLE_NAME);
36 private static PHPEclipseSQLPlugin plugin;
37 public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.sql";
39 public PHPEclipseSQLPlugin(IPluginDescriptor descriptor) {
44 public static PHPEclipseSQLPlugin getDefault() {
47 protected void readStateFrom(File target) {
48 BookmarkContentProvider.getInstance().load(target);
51 public void startup() throws CoreException {
53 ISaveParticipant saveParticipant = new PHPSQLSaveParticipant();
54 ISavedState lastState =
55 ResourcesPlugin.getWorkspace().addSaveParticipant(this, saveParticipant);
56 if (lastState == null)
58 IPath location = lastState.lookup(new Path("save"));
61 // the plugin instance should read any important state from the file.
62 File f = getStateLocation().append(location).toFile();
65 protected void writeImportantState(File target) {
66 BookmarkContentProvider.getInstance().save(target);
68 public static ImageDescriptor getImageDescriptor(String name) {
69 ImageDescriptor descriptor = null;
72 PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
73 URL url = new URL(installURL, "icons/" + name);
74 descriptor = ImageDescriptor.createFromURL(url);
75 } catch (Exception e) {
80 public static Image getImage(String name) {
81 return getImageDescriptor(name).createImage();
84 public void dispose() throws CoreException {
85 MultiSQLServer.getInstance().shutdown();
88 protected void initializeDefaultPluginPreferences() {
89 RGB BACKGROUND = new RGB(255, 255, 255);
90 RGB COMMENT = new RGB(88, 148, 64);
91 RGB IDENTIFIER = new RGB(0, 0, 0);
92 RGB KEYWORD = new RGB(126, 0, 75);
93 RGB STRING = new RGB(0, 0, 255);
94 RGB NUMERIC = new RGB(255, 0, 0);
95 RGB DEFAULT = new RGB(0, 0, 0);
96 IPreferenceStore store = getPreferenceStore();
97 PreferenceConverter.setDefault(
99 "phpeclipse.sql.background.color",
101 PreferenceConverter.setDefault(store, "phpeclipse.sql.text.color", DEFAULT);
102 PreferenceConverter.setDefault(store, "phpeclipse.sql.keyword.color", KEYWORD);
103 PreferenceConverter.setDefault(store, "phpeclipse.sql.comment.color", COMMENT);
104 PreferenceConverter.setDefault(store, "phpeclipse.sql.string.color", STRING);
105 PreferenceConverter.setDefault(store, "phpeclipse.sql.numeric.color", NUMERIC);
106 getPreferenceStore().setDefault("phpeclipse.sql.text.bold", false);
107 getPreferenceStore().setDefault("phpeclipse.sql.keyword.bold", true);
108 getPreferenceStore().setDefault("phpeclipse.sql.string.bold", false);
109 getPreferenceStore().setDefault("phpeclipse.sql.comment.bold", false);
110 getPreferenceStore().setDefault("phpeclipse.sql.numeric.bold", false);
111 PreferenceConverter.setDefault(
112 getPreferenceStore(),
113 "phpeclipse.sql.font",
118 class PHPSQLSaveParticipant implements ISaveParticipant, IConstants {
120 * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
122 public void doneSaving(ISaveContext context) {
126 * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
128 public void prepareToSave(ISaveContext context) throws CoreException {
132 * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
134 public void rollback(ISaveContext context) {
138 * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
140 public void saving(ISaveContext context) throws CoreException {
141 switch (context.getKind()) {
142 case ISaveContext.FULL_SAVE :
143 PHPEclipseSQLPlugin sqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
144 // save the plug in state
145 if (BookmarkContentProvider.getInstance().hasChanged()) {
146 int saveNumber = context.getSaveNumber();
147 String saveFileName = "save " + Integer.toString(saveNumber);
151 .append(saveFileName)
153 // if we fail to write, an exception is thrown and we do not update the path
154 sqlPluginInstance.writeImportantState(f);
155 context.map(new Path("save"), new Path(saveFileName));
156 context.needSaveNumber();
159 System.out.println("Not saving unchanged bookmarks");
163 case ISaveContext.PROJECT_SAVE :
164 // get the project related to this save operation
165 //IProject project = context.getProject();
166 // save its information, if necessary
168 case ISaveContext.SNAPSHOT :
169 // This operation needs to be really fast because
170 // snapshots can be requested frequently by the