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
30 extends AbstractUIPlugin
31 implements IConstants {
33 private static final String BUNDLE_NAME =
34 "net.sourceforge.phpdt.sql.PHPEclipseSQLResources";
35 private static final ResourceBundle RESOURCE_BUNDLE =
36 ResourceBundle.getBundle(BUNDLE_NAME);
38 private static PHPEclipseSQLPlugin plugin;
39 public final static String PLUGIN_ID = "net.sourceforge.phpeclipse.sql";
41 public PHPEclipseSQLPlugin(IPluginDescriptor descriptor) {
46 public static PHPEclipseSQLPlugin getDefault() {
49 protected void readStateFrom(File target) {
50 BookmarkContentProvider.getInstance().load(target);
53 public void startup() throws CoreException {
55 ISaveParticipant saveParticipant = new PHPSQLSaveParticipant();
56 ISavedState lastState =
57 ResourcesPlugin.getWorkspace().addSaveParticipant(this, saveParticipant);
58 if (lastState == null)
60 IPath location = lastState.lookup(new Path("save"));
63 // the plugin instance should read any important state from the file.
64 File f = getStateLocation().append(location).toFile();
67 protected void writeImportantState(File target) {
68 BookmarkContentProvider.getInstance().save(target);
70 public static ImageDescriptor getImageDescriptor(String name) {
71 ImageDescriptor descriptor = null;
74 PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
75 URL url = new URL(installURL, "icons/" + name);
76 descriptor = ImageDescriptor.createFromURL(url);
77 } catch (Exception e) {
82 public static Image getImage(String name) {
83 return getImageDescriptor(name).createImage();
86 public void dispose() throws CoreException {
87 MultiSQLServer.getInstance().shutdown();
90 protected void initializeDefaultPluginPreferences() {
91 RGB BACKGROUND = new RGB(255, 255, 255);
92 RGB COMMENT = new RGB(88, 148, 64);
93 RGB IDENTIFIER = new RGB(0, 0, 0);
94 RGB KEYWORD = new RGB(126, 0, 75);
95 RGB STRING = new RGB(0, 0, 255);
96 RGB NUMERIC = new RGB(255, 0, 0);
97 RGB DEFAULT = new RGB(0, 0, 0);
98 IPreferenceStore store = getPreferenceStore();
99 PreferenceConverter.setDefault(
101 "phpeclipse.sql.background.color",
103 PreferenceConverter.setDefault(store, "phpeclipse.sql.text.color", DEFAULT);
104 PreferenceConverter.setDefault(
106 "phpeclipse.sql.keyword.color",
108 PreferenceConverter.setDefault(
110 "phpeclipse.sql.comment.color",
112 PreferenceConverter.setDefault(
114 "phpeclipse.sql.string.color",
116 PreferenceConverter.setDefault(
118 "phpeclipse.sql.numeric.color",
120 getPreferenceStore().setDefault("phpeclipse.sql.text.bold", false);
121 getPreferenceStore().setDefault("phpeclipse.sql.keyword.bold", true);
122 getPreferenceStore().setDefault("phpeclipse.sql.string.bold", false);
123 getPreferenceStore().setDefault("phpeclipse.sql.comment.bold", false);
124 getPreferenceStore().setDefault("phpeclipse.sql.numeric.bold", false);
126 getPreferenceStore().setDefault(
127 "phpeclipse.sql.select.template",
128 "$results = mysql_query(\"SELECT {0} FROM {1} WHERE {2} \");");
130 getPreferenceStore().setDefault(
131 "phpeclipse.sql.insert.template",
132 "$results = mysql_query(\"INSERT INTO {0} ({1}) VALUES {2} \");");
134 getPreferenceStore().setDefault(
135 "phpeclipse.sql.update.template",
136 "$results = mysql_query(\"UPDATE {0} SET {1} WHERE {2} \");");
138 getPreferenceStore().setDefault(
139 "phpeclipse.sql.delete.template",
140 "$results = mysql_query(\"DELETE FROM {0} WHERE {1} \");");
142 getPreferenceStore().setDefault("phpeclipse.sql.username.connect", "root");
144 getPreferenceStore().setDefault(
145 "phpeclipse.sql.connect.connect",
146 "jdbc:mysql://localhost/test");
148 getPreferenceStore().setDefault(
149 "phpeclipse.sql.driver.connect",
150 "com.mysql.jdbc.Driver");
152 getPreferenceStore().setDefault("phpeclipse.sql.type.connect", "MySQL");
154 getPreferenceStore().setDefault(
155 "phpeclipse.sql.filename.connect",
156 "C:\\apache\\mysql\\lib\\mysql-connector-java-2.0.14-bin.jar");
158 PreferenceConverter.setDefault(
159 getPreferenceStore(),
160 "phpeclipse.sql.font",
165 class PHPSQLSaveParticipant implements ISaveParticipant, IConstants {
167 * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
169 public void doneSaving(ISaveContext context) {
173 * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
175 public void prepareToSave(ISaveContext context) throws CoreException {
179 * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
181 public void rollback(ISaveContext context) {
185 * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
187 public void saving(ISaveContext context) throws CoreException {
188 switch (context.getKind()) {
189 case ISaveContext.FULL_SAVE :
190 PHPEclipseSQLPlugin sqlPluginInstance =
191 PHPEclipseSQLPlugin.getDefault();
192 // save the plug in state
193 if (BookmarkContentProvider.getInstance().hasChanged()) {
194 int saveNumber = context.getSaveNumber();
195 String saveFileName = "save " + Integer.toString(saveNumber);
197 sqlPluginInstance.getStateLocation().append(saveFileName).toFile();
198 // if we fail to write, an exception is thrown and we do not update the path
199 sqlPluginInstance.writeImportantState(f);
200 context.map(new Path("save"), new Path(saveFileName));
201 context.needSaveNumber();
204 System.out.println("Not saving unchanged bookmarks");
208 case ISaveContext.PROJECT_SAVE :
209 // get the project related to this save operation
210 //IProject project = context.getProject();
211 // save its information, if necessary
213 case ISaveContext.SNAPSHOT :
214 // This operation needs to be really fast because
215 // snapshots can be requested frequently by the