<plugin
id="net.sourceforge.phpeclipse.quantum.sql"
name="%quantum.name"
- version="2.3.2"
+ version="2.3.3"
provider-name="Tom Schneider, Julen Parra, BC Holmes"
class="com.quantum.QuantumPlugin">
class="com.quantum.view.SQLLogView"
id="com.quantum.view.logview">
</view>
+ <view name="%driverview.name"
+ icon="icons/driver.gif"
+ category="com.quantum.views"
+ class="com.quantum.view.JDBCDriverView"
+ id="com.quantum.view.JDBCDriverView">
+ </view>
<view
name="%tableview.name"
icon="icons/table.gif"
--- /dev/null
+package com.quantum;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+
+import java.util.Map;
+
+import com.quantum.util.versioning.VersioningHelper;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+
+/**
+ * @author BC
+ */
+public class ImageStore {
+
+ private static final Map imageDescriptorMap = Collections.synchronizedMap(new HashMap());
+
+ private static final String VERSION_2 = "_2x";
+ private static final String GIF_FILE_EXTENSION = ".gif";
+
+ public static final String ADD = "add";
+ public static final String ADD_SCHEMA = "add_schema";
+ public static final String APPEND = "append";
+ public static final String AUTOCOMMIT = "autocommit";
+ public static final String BOOKMARK = "bookmarks";
+ public static final String BOOKMARKFILE = "bookmarkfile";
+ public static final String CLASS = "class";
+ public static final String CLEAR = "clear";
+ public static final String CLOSE = "close";
+ public static final String COLUMN = "column";
+ public static final String CONNECT = "connect";
+ public static final String CONNECTED = "connected";
+ public static final String COPY = "copy";
+ public static final String CUT = "cut";
+ public static final String DELETE = "delete";
+ public static final String DISCONNECT = "disconnect";
+ public static final String DRIVER = "driver";
+ public static final String EDIT = "edit";
+ public static final String ENTITYGROUP = "entitygroup";
+ public static final String EXPORT = "export";
+ public static final String FILTER = "filter";
+ public static final String FOREIGNKEY = "foreignkey";
+ public static final String FULLDATA = "fulldata";
+ public static final String GRID = "grid";
+ public static final String GROUP = "group";
+ public static final String IMPORT = "import";
+ public static final String KEY = "key";
+ public static final String KEYCOLUMN = "keycolumn";
+ public static final String LOG = "log";
+ public static final String MISSINGSCHEMA = "missingschema";
+ public static final String MISSINGTABLE = "table";
+ public static final String NEXT = "next";
+ public static final String OPEN_TABLE = "table";
+ public static final String PASTE = "paste";
+ public static final String PLAY = "play";
+ public static final String PREVIOUS = "previous";
+ public static final String QMODEL = "qmodel";
+ public static final String QUANTUM = "quantum";
+ public static final String REFRESH = "refresh";
+ public static final String ROLLBACK = "rollback";
+ public static final String SAMPLE = "sample";
+ public static final String SCHEMA = "schema";
+ public static final String SCRIPT = "script";
+ public static final String SEQUENCE = "sequence";
+ public static final String STATEMENT = "statement";
+ public static final String STOP = "stop";
+ public static final String SUBSET = "subset";
+ public static final String SUCCESS = "success";
+ public static final String TABLE = "bigtable";
+ 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 ImageDescriptor getImageDescriptor(String imageName) {
+ return getImageDescriptor(imageName, QuantumPlugin.getDefault());
+ }
+
+ public static Image getImage(String imageName) {
+ return getImage(imageName, QuantumPlugin.getDefault());
+ }
+
+ /**
+ * @param imageName
+ * @param default1
+ * @return
+ */
+ private static Image getImage(String imageName, AbstractUIPlugin plugin) {
+ ImageRegistry registry = plugin.getImageRegistry();
+ String key = stripSuffix(imageName);
+ Image image = registry.get(getVersionAppropriateImage(key));
+ return image;
+ }
+
+ public static ImageDescriptor getImageDescriptor(String imageName, AbstractUIPlugin plugin) {
+ ImageRegistry registry = plugin.getImageRegistry();
+ String key = stripSuffix(imageName);
+ key = getVersionAppropriateImage(key);
+
+ if (VersioningHelper.isEclipse21OrHigher()) {
+ return VersioningHelper.getDescriptor(registry, key);
+ } else {
+ return (ImageDescriptor) 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;
+ }
+
+ /**
+ * @param imageName
+ * @return
+ */
+ private static String getVersionAppropriateImage(String imageName) {
+ String version2Key = imageName + VERSION_2;
+ return !VersioningHelper.isEclipse30() && imageDescriptorMap.containsKey(version2Key)
+ ? version2Key : imageName;
+ }
+
+ /**
+ * @param registry
+ * @param url
+ */
+ static void initialize(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);
+
+ 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);
+ }
+ }
+
+ /**
+ * @param registry
+ * @param url
+ */
+ private static void addImage(ImageRegistry registry, URL url, String key) {
+ try {
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(
+ new URL(url, key + GIF_FILE_EXTENSION));
+ ImageStore.imageDescriptorMap.put(key, descriptor);
+ registry.put(key, descriptor);
+ } catch (MalformedURLException e) {
+ // skip, but try to go on to the next one...
+ }
+ }
+}
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;
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;
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;
+
/**
* Main class of the quantum plugin, sets defaults, saves and recovers state.
* @author root
*/
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) {
* @see org.eclipse.core.runtime.Plugin#shutdown()
*/
public void shutdown() throws CoreException {
+ if (!sysClip.isDisposed()) {
+ sysClip.dispose();
+ }
super.shutdown();
- sysClip.dispose();
}
/**
}
}
- /**
- * 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);
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
com.quantum.properties.ColumnPropertyPage.column6 = Remarks
com.quantum.properties.ColumnPropertyPage.true = Yes
com.quantum.properties.ColumnPropertyPage.false = No
+
+com.quantum.actions.BaseExecuteAction.execute1=Executing Query...
+com.quantum.actions.BaseExecuteAction.execute2=Executing Query..
+com.quantum.actions.BaseExecuteAction.done=Done ({0} queries executed, {1} rows updated, {2} result sets displayed, {3} errors, {4} seconds)
+com.quantum.actions.BaseExecuteAction.selectBookmark=Select a bookmark
+
+com.quantum.actions.ExecuteAction.parsing=Parsing sql script...
+com.quantum.actions.ExecuteAction.autocommitTitle=Autocommit changed
+com.quantum.actions.ExecuteAction.autocommitMessage=The autocommit setting of the bookmark, {0} has been changed.
\ No newline at end of file
--- /dev/null
+package com.quantum;
+
+import java.io.File;
+
+import com.quantum.model.BookmarkCollection;
+import com.quantum.view.subset.SubsetContentProvider;
+
+import org.eclipse.core.resources.ISaveContext;
+import org.eclipse.core.resources.ISaveParticipant;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+
+
+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;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.quantum.actions;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+import com.quantum.ImageStore;
+import com.quantum.Messages;
+import com.quantum.model.Bookmark;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.sql.MultiSQLServer;
+import com.quantum.sql.SQLResults;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.ui.dialog.SimpleSelectionDialog;
+import com.quantum.util.connection.ConnectionUtil;
+import com.quantum.view.LogProxy;
+import com.quantum.view.tableview.DefaultSizes;
+import com.quantum.view.tableview.TableView;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @author BC
+ */
+public abstract class BaseExecuteAction extends Action {
+
+ class Metrics {
+ int resultCount = 0;
+ int resultUpdateCount = 0;
+ int errorCount = 0;
+ int resultsDisplayed = 0;
+ double queryDuration= 0.0;
+
+ public void measure(SQLResults results) {
+ if (results == null) {
+ errorCount++;
+ } else {
+ queryDuration += results.getTime()/1000.0; // calculate the execution time (in seconds)
+ resultCount++;
+ if (results.isResultSet()) {
+ resultsDisplayed++;
+ } else {
+ resultUpdateCount += results.getUpdateCount();
+ }
+ }
+ }
+
+ public boolean hasErrors() {
+ return this.errorCount > 0;
+ }
+
+ Object[] getResults() {
+ return new Object[] {
+ new Integer(this.resultCount),
+ new Integer(this.resultUpdateCount),
+ new Integer(this.resultsDisplayed),
+ new Integer(this.errorCount),
+ new Double(this.queryDuration),
+ };
+ }
+ }
+
+ private ConnectionUtil connectionUtil = new ConnectionUtil();
+
+ protected abstract Shell getShell();
+
+ protected Connection getConnection(Bookmark bookmark) {
+ return this.connectionUtil.getConnection(bookmark, getShell());
+ }
+
+ String execute1 = Messages.getString(BaseExecuteAction.class, "execute1");
+ String execute2 = Messages.getString(BaseExecuteAction.class, "execute2");
+
+ public void run() {
+ Bookmark bookmark = getBookmark();
+ if (bookmark != null) {
+ execute(bookmark);
+ }
+ }
+
+ /**
+ * @param bookmark
+ */
+ protected void execute(Bookmark bookmark) {
+ if (bookmark != null) {
+ try {
+ getStatusLineManager().setErrorMessage(null);
+ Connection connection = getConnection(bookmark);
+ if (connection != null) {
+ execute(bookmark, connection);
+ }
+ } catch (IOException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ } catch (SQLException e) {
+ ExceptionDisplayDialog.openError(getShell(), null, null, e);
+ } catch (CoreException e) {
+ ErrorDialog.openError(getShell(), null, null, e.getStatus());
+ }
+ }
+ }
+
+ /**
+ * @param bookmark
+ * @param connection
+ * @throws IOException
+ * @throws CoreException
+ */
+ protected void execute(Bookmark bookmark, Connection connection)
+ throws IOException, CoreException, SQLException {
+ getStatusLineManager().setMessage(execute1);
+ MultiSQLServer server = MultiSQLServer.getInstance();
+
+ Metrics metrics = new Metrics();
+
+ List queries = getQueries();
+ IProgressMonitor progressBar = getStatusLineManager().getProgressMonitor();
+ progressBar.beginTask("queries", queries.size());
+ for (int i = 0; i < queries.size(); i++) {
+ getStatusLineManager().setMessage((i % 2 == 0) ? execute1 : execute2);
+
+ String query = (String) queries.get(i);
+ System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (query != null && query.trim().length() > 0) {
+ SQLResults results = getSQLResults(connection, server, query);
+ metrics.measure(results);
+ if (results != null) {
+ bookmark.addQuery(query);
+ if (results.isResultSet()) {
+ TableView.getInstance().loadQuery(bookmark, results);
+ }
+ }
+ }
+ progressBar.worked(i);
+ }
+ progressBar.done();
+ displayFinalStatusMessage(metrics);
+ }
+
+ /**
+ * @return
+ * @throws CoreException
+ * @throws IOException
+ */
+ protected abstract List getQueries() throws IOException, CoreException;
+
+ /**
+ * @return
+ */
+ protected abstract IStatusLineManager getStatusLineManager();
+
+ /**
+ * @param metrics
+ */
+ private void displayFinalStatusMessage(Metrics metrics) {
+ String message = Messages.getString(
+ BaseExecuteAction.class,
+ "done", //$NON-NLS-1$ //$NON-NLS-2$
+ metrics.getResults());
+ if (metrics.hasErrors()) {
+ getStatusLineManager().setErrorMessage(
+ ImageStore.getImage(ImageStore.STOP), message);
+ } else {
+ getStatusLineManager().setMessage(
+ ImageStore.getImage(ImageStore.SUCCESS), message);
+ }
+ }
+
+ /**
+ * @param connection
+ * @param server
+ * @param query
+ * @return
+ */
+ private SQLResults getSQLResults(Connection connection, MultiSQLServer server, String query) {
+ SQLResults results = null;
+ try {
+ results = server.execute(connection, query, 1,
+ DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+ } catch (SQLException e) {
+ LogProxy log = LogProxy.getInstance();
+ log.addText(LogProxy.ERROR,
+ "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.openConfirm(getShell(),
+ "Database returned error",
+ e.getLocalizedMessage()); //$NON-NLS-1$
+ }
+ return results;
+ }
+
+ protected Bookmark getBookmark() {
+ Bookmark bookmark = null;
+ SimpleSelectionDialog dialog = new SimpleSelectionDialog(
+ getShell(),
+ Messages.getString(BaseExecuteAction.class, "selectBookmark"),
+ BookmarkCollection.getInstance().getBookmarks(),
+ ImageStore.getImage(ImageStore.BOOKMARK));
+ if (SimpleSelectionDialog.OK == dialog.open()) {
+ IStructuredSelection selection = dialog.getSelection();
+
+ bookmark = (Bookmark) selection.getFirstElement();
+ }
+ return bookmark;
+ }
+}
import java.sql.Connection;
import java.util.Iterator;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.util.connection.ConnectionUtil;
import com.quantum.view.bookmark.BookmarkNode;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.SelectionListenerAction;
super(Messages.getString(ConnectAction.class.getName() + ".text"));
this.view = view;
setImageDescriptor(
- QuantumPlugin.getImageDescriptor("connect.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.CONNECT));
}
private IViewPart view;
import java.util.Iterator;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.BookmarkCollection;
import com.quantum.view.bookmark.BookmarkNode;
public DeleteBookmarkAction(IViewPart view) {
super(Messages.getString(DeleteBookmarkAction.class.getName() + ".text"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("delete.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE));
this.view = view;
}
import java.util.List;
import java.util.Vector;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.ConnectionException;
import com.quantum.view.bookmark.BookmarkNode;
super(Messages.getString(DisconnectAction.class.getName() + ".text"));
this.view = view;
setImageDescriptor(
- QuantumPlugin.getImageDescriptor("disconnect.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.DISCONNECT));
}
package com.quantum.actions;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.List;
import java.util.Vector;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
-import com.quantum.sql.MultiSQLServer;
+import com.quantum.model.BookmarkCollection;
import com.quantum.sql.SQLParser;
-import com.quantum.sql.SQLResults;
-import com.quantum.view.LogProxy;
import com.quantum.view.SQLQueryView;
-import com.quantum.view.bookmark.BookmarkNode;
-import com.quantum.view.bookmark.BookmarkView;
-import com.quantum.view.tableview.DefaultSizes;
-import com.quantum.view.tableview.TableView;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.action.IAction;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
/**
* Executes a query from the QueryView
*
* @author panic
*/
-public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate {
- SQLQueryView view;
- String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
- String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
-
- public ExecuteAction() {
+public class ExecuteAction extends BaseExecuteAction implements IMenuCreator {
+ private SQLQueryView view;
+
+ public ExecuteAction(SQLQueryView view) {
+ this.view = view;
setActionDefinitionId("com.quantum.actions.ExecuteAction");
- setImageDescriptor(QuantumPlugin.getImageDescriptor("play.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PLAY));
setText(Messages.getString("sqlqueryview.executeQuery"));
setToolTipText(Messages.getString("sqlqueryview.executeQuery"));
- }
-
- public void init(IViewPart view) {
- this.view = (SQLQueryView) view;
+ setMenuCreator(this);
}
- public void run(IAction action) {
- run();
- }
-
- public void run() {
- BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
- if (current == null)
- {
- MessageDialog.openInformation(
- view.getSite().getShell(),"Sorry","Please select a bookmark to use as connection.");
- return;
- }
- getStatusLineManager().setErrorMessage(null);
- Connection con = getConnection();
- getStatusLineManager().setMessage(execute1);
- MultiSQLServer server = MultiSQLServer.getInstance();
- getStatusLineManager().setMessage(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
- Vector queries = new Vector();
- String viewQuery = view.getQuery();
- // We parse the executable units to send to the JDBC driver
- queries = SQLParser.parse(viewQuery);
- for (int i = 0; i < queries.size(); i++) {
- String query = (String) queries.elementAt(i);
- System.out.println(query);
- }
- int resultCount = 0;
- int resultUpdateCount = 0;
- int errorCount = 0;
- int resultsDisplayed = 0;
- double startTime = 0.0; // stores the time when query is started
- double queryDuration= 0.0; // stores query's execution time
-
- IProgressMonitor progressBar = getStatusLineManager().getProgressMonitor();
- progressBar.beginTask("queries", queries.size());
- for (int i = 0; i < queries.size(); i++) {
- if (i % 2 == 0) {
- getStatusLineManager().setMessage(execute1);
- } else {
- getStatusLineManager().setMessage(execute2);
- }
-
- String query = (String) queries.elementAt(i);
- System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
- if (con != null && !query.equals("")) { //$NON-NLS-1$
- SQLResults results;
- try {
- startTime = System.currentTimeMillis(); // Start the measure of execution time
- results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
- queryDuration = (System.currentTimeMillis() - startTime)/1000; // calculate the execution time (in seconds)
- current.getBookmark().addQuery(query);
- } catch (SQLException e) {
- errorCount++;
- LogProxy log = LogProxy.getInstance();
- log.addText(
- LogProxy.ERROR,
- "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.openConfirm(view.getSite().getShell(), "Database returned error", e.getLocalizedMessage()); //$NON-NLS-1$
- continue;
- }
- resultCount++;
- if (results.isResultSet()) {
- TableView.getInstance().loadQuery(current.getBookmark(), results);
- resultsDisplayed++;
- } else {
- int count = results.getUpdateCount();
- if (count > 0) {
- resultUpdateCount += results.getUpdateCount();
- }
- }
- }
-System.out.println(getStatusLineManager().getProgressMonitor() == null ? "not found" : "found!");
- progressBar.worked(i);
-// view.setProgress(i + 1, queries.size());
+
+ protected void execute(Bookmark bookmark, Connection connection)
+ throws IOException, CoreException, SQLException {
+
+ boolean autoCommitPreference = this.view.isAutoCommitPreference();
+ boolean changed = false;
+ if (connection.getAutoCommit() != autoCommitPreference) {
+ connection.setAutoCommit(autoCommitPreference);
+ changed = true;
}
- progressBar.done();
- String message = Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
- resultCount + Messages.getString("ExecuteAction.QueriesExecuted") + //$NON-NLS-1$
- resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") + //$NON-NLS-1$
- resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") + //$NON-NLS-1$
- errorCount + Messages.getString("ExecuteAction.Errors") + //$NON-NLS-1$
- queryDuration + Messages.getString("ExecutAction.TimeExec") + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- if (errorCount > 0) {
- getStatusLineManager().setErrorMessage(
- QuantumPlugin.getImage("stop.gif"), message);
- } else {
- getStatusLineManager().setMessage(
- QuantumPlugin.getImage("success.gif"), message);
+
+ super.execute(bookmark, connection);
+
+ if (changed) {
+ MessageDialog.openInformation(getShell(),
+ Messages.getString(ExecuteAction.class, "autocommitTitle"),
+ Messages.getString(ExecuteAction.class, "autocommitMessage",
+ new Object[] { bookmark.getName() }));
}
}
+ /**
+ * @return
+ */
+ protected List getQueries() {
+ getStatusLineManager().setMessage(
+ Messages.getString(ExecuteAction.class, "parsing")); //$NON-NLS-1$
+ Vector queries = SQLParser.parse(view.getQuery());
+ return queries;
+ }
/**
* @return
*/
- private IStatusLineManager getStatusLineManager() {
+ protected IStatusLineManager getStatusLineManager() {
return this.view.getViewSite().getActionBars().getStatusLineManager();
}
- public void selectionChanged(IAction action, ISelection selection) {
+ protected Shell getShell() {
+ return this.view.getViewSite().getShell();
}
- protected Bookmark getBookmark() {
- BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
- return current.getBookmark();
+
+ public void dispose() {
}
- /* (non-Javadoc)
- * @see com.quantum.actions.BaseSQLAction#getShell()
- */
- protected Shell getShell() {
- return this.view.getViewSite().getShell();
+ public Menu getMenu(Control parent) {
+ Menu menu = new Menu(parent);
+ /**
+ * Add listener to repopulate the menu each time
+ * it is shown because the list of bookmarks may have changed.
+ */
+ menu.addMenuListener(new MenuAdapter() {
+ public void menuShown(MenuEvent e) {
+ Menu menu = (Menu)e.widget;
+ MenuItem[] items = menu.getItems();
+ for (int i=0; i < items.length; i++) {
+ items[i].dispose();
+ }
+ fillMenu(menu);
+ }
+ });
+ return menu;
+ }
+
+ public Menu getMenu(Menu parent) {
+ // never called...
+ return null;
+ }
+
+ protected void fillMenu(Menu menu) {
+ Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
+ for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; i < length; i++) {
+ final Bookmark bookmark = bookmarks[i];
+ Action action = new Action() {
+ public void run() {
+ ExecuteAction.this.execute(bookmark);
+ }
+ };
+ action.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.BOOKMARK));
+ action.setText(bookmark.getName());
+ ActionContributionItem item = new ActionContributionItem(action);
+ item.fill(menu, -1);
+ }
}
}
package com.quantum.actions;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkCollection;
-import com.quantum.model.ConnectionException;
-import com.quantum.sql.MultiSQLServer;
import com.quantum.sql.SQLParser;
-import com.quantum.sql.SQLResults;
-import com.quantum.ui.dialog.BookmarkSelectionDialog;
-import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.ui.dialog.SimpleSelectionDialog;
import com.quantum.util.io.InputStreamHelper;
-import com.quantum.view.tableview.DefaultSizes;
-import com.quantum.view.tableview.TableView;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
/**
* This action can be executed against any .sql file, regardless of
* whether or not the Quantum perspective is open.
*
- * @author BC
+ * @author BC Holmes
*/
-public class ExecuteAgainstAction extends BaseSQLAction
- implements IObjectActionDelegate, PropertyChangeListener {
+public class ExecuteAgainstAction extends BaseExecuteAction
+ implements IObjectActionDelegate {
- private String selectedBookmark = null;
private IFile[] files = null;
private IWorkbenchPart workbenchPart;
+
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
}
/**
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- */
- public void run(IAction action) {
-
- BookmarkSelectionDialog dialog = new BookmarkSelectionDialog(getShell());
- dialog.addPropertyChangeListener(this);
- int result = dialog.open();
-
- if (result == Window.OK) {
- try {
- executeAgainstBookmark();
- } catch (SQLException e) {
- ExceptionDisplayDialog.openError(getShell(),
- null,
- null, e);
- } catch (IOException e) {
- ExceptionDisplayDialog.openError(getShell(),
- Messages.getString("ExecuteAgainstAction.title"),
- Messages.getString("ExecuteAgainstAction.IOException"), e);
- } catch (ConnectionException e) {
- ExceptionDisplayDialog.openError(getShell(),
- null,
- null, e);
- } catch (CoreException e) {
- ErrorDialog.openError(getShell(), null, null, e.getStatus());
- }
- }
- }
-
- protected Bookmark getBookmark() {
- return BookmarkCollection.getInstance().find(this.selectedBookmark);
- }
-
- private void executeAgainstBookmark()
- throws SQLException, IOException, CoreException, ConnectionException {
- Bookmark bookmark = getBookmark();
- if (bookmark != null) {
- boolean alreadyConnected = bookmark.isConnected();
- Connection connection = getConnection();
- try {
- for (int i = 0,
- length = (this.files == null) ? 0 : this.files.length;
- connection != null && i < length;
- i++) {
- executeAgainstBookmark(bookmark, connection, this.files[i]);
- }
- } finally {
- if (!alreadyConnected && connection != null) {
- bookmark.disconnect();
- }
- }
- }
- }
-
- private void executeAgainstBookmark(
- Bookmark bookmark,
- Connection connection,
- IFile file)
- throws SQLException, IOException, CoreException {
- executeAgainstBookmark(
- bookmark,
- connection,
- InputStreamHelper.readIntoString(file.getContents()));
- }
-
- private void executeAgainstBookmark(
- Bookmark bookmark,
- Connection connection,
- String queries)
- throws SQLException {
- List queryList = SQLParser.parse(queries);
- MultiSQLServer server = MultiSQLServer.getInstance();
-
- for (Iterator i = queryList.iterator(); i.hasNext();) {
- String query = (String) i.next();
- SQLResults results =
- server.execute(
- connection,
- query,
- 1,
- DefaultSizes.PAGE_SIZE,
- DefaultSizes.MAX_COLUMN_SIZE);
- if (results.isResultSet()) {
- TableView view = TableView.getInstance();
- if (view != null) {
- view.loadQuery(bookmark, results);
- }
- }
- }
- }
-
- /**
- * This method is called with a new selection has been made on one
+ * This method is called when a new selection has been made on one
* of the views.
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
for (Iterator i = structuredSelection.iterator(); i.hasNext();) {
Object temp = i.next();
if (temp != null && temp instanceof IFile) {
- System.out.println(((IFile) temp).getName());
list.add(temp);
}
}
}
}
- /**
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- if ("selection".equals(event.getPropertyName())) {
- this.selectedBookmark = (String) event.getNewValue();
- }
- }
+ /* (non-Javadoc)
+ * @see com.quantum.actions.BaseSQLAction#getQueries()
+ */
+ protected List getQueries() throws IOException, CoreException {
+ List list = new ArrayList();
+ for (int i = 0, length = this.files == null ? 0 : this.files.length; i < length; i++) {
+ String fileContents = InputStreamHelper.readIntoString(this.files[i].getContents());
+ List queryList = SQLParser.parse(fileContents);
+ list.addAll(queryList);
+ }
+ return list;
+ }
+
+ protected IStatusLineManager getStatusLineManager() {
+ if (this.workbenchPart instanceof IViewPart) {
+ return ((IViewPart) this.workbenchPart).getViewSite().getActionBars().getStatusLineManager();
+ } else {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ run();
+ }
}
import java.io.PrintWriter;
import java.util.StringTokenizer;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.util.StringUtil;
import com.quantum.view.LogProxy;
import com.quantum.view.SQLLogView;
SQLQueryView view;
public ExportQueryAction() {
- setImageDescriptor(QuantumPlugin.getImageDescriptor("export.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.EXPORT));
setText(Messages.getString("sqlqueryview.exportQuery"));
setToolTipText(Messages.getString("sqlqueryview.exportQuery"));
}
import java.io.FileReader;
import java.io.IOException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
import com.quantum.view.LogProxy;
public ImportQueryAction() {
setText(Messages.getString("sqlqueryview.importQuery"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("import.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.IMPORT));
setToolTipText(Messages.getString("sqlqueryview.importQuery"));
}
package com.quantum.actions;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.wizards.BookmarkWizard;
import org.eclipse.jface.action.Action;
public NewBookmarkAction(IViewPart view) {
this.view = view;
- setText(Messages.getString(getClass().getName() + ".text")); //$NON-NLS-1$
- setToolTipText(Messages.getString(getClass().getName() + ".text")); //$NON-NLS-1$
- setImageDescriptor(QuantumPlugin.getImageDescriptor("bookmarks.gif")); //$NON-NLS-1$
+ setText(Messages.getString(getClass(), "text")); //$NON-NLS-1$
+ setToolTipText(Messages.getString(getClass(), "text")); //$NON-NLS-1$
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.BOOKMARK));
}
public void run() {
package com.quantum.actions;
-import org.eclipse.ui.IViewPart;
-
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
import com.quantum.sql.SQLResults;
import com.quantum.view.bookmark.EntityNode;
import com.quantum.view.tableview.TableView;
+import org.eclipse.ui.IViewPart;
+
public class NextSequenceAction extends BaseSequenceAction {
/**
* @param view
*/
public NextSequenceAction(IViewPart view) {
- super(Messages.getString(NextSequenceAction.class.getName() + ".text"), view);
- setImageDescriptor(QuantumPlugin.getImageDescriptor("append.gif"));
+ super(Messages.getString(NextSequenceAction.class, "text"), view);
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.APPEND));
}
public void run() {
*/
package com.quantum.actions;
-import org.eclipse.ui.IViewPart;
-
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.adapters.DatabaseAdapter;
import com.quantum.model.Bookmark;
import com.quantum.sql.SQLResults;
import com.quantum.view.bookmark.EntityNode;
import com.quantum.view.tableview.TableView;
+import org.eclipse.ui.IViewPart;
+
public class PrevSequenceAction extends BaseSequenceAction {
/**
* @param text
*/
public PrevSequenceAction(IViewPart view) {
super(Messages.getString(PrevSequenceAction.class.getName() + ".text"), view);
- setImageDescriptor(QuantumPlugin.getImageDescriptor("grid.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.GRID));
}
public void run() {
import java.util.Iterator;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.NotConnectedException;
import com.quantum.ui.dialog.ExceptionDisplayDialog;
import com.quantum.view.bookmark.TreeNode;
public class RefreshBookmarkAction extends SelectionListenerAction {
private IViewPart view;
public RefreshBookmarkAction(IViewPart view) {
- super(Messages.getString(RefreshBookmarkAction.class.getName() + ".text"));
+ super(Messages.getString(RefreshBookmarkAction.class, "text"));
this.view = view;
- setImageDescriptor(QuantumPlugin.getImageDescriptor("refresh.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.REFRESH));
}
public void run() {
package com.quantum.actions;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Entity;
import com.quantum.view.bookmark.EntityNode;
import com.quantum.view.tableview.TableView;
private Entity entity;
public ViewTableAction(IViewPart view) {
- super(Messages.getString(ViewTableAction.class.getName() + ".text"));
+ super(Messages.getString(ViewTableAction.class, "text"));
setImageDescriptor(
- QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
}
public void run() {
import java.sql.Connection;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.Entity;
import com.quantum.sql.SQLResults;
public ViewTableDetailsAction(IViewPart view) {
super(Messages.getString(ViewTableDetailsAction.class, "text"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
this.view = view;
}
public String getShowTableQuery(String qualifier) {
return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" +
qualifier.toUpperCase() +
- "' AND TABLE_TYPE IN ('T', 'P') AND SYSTEM_TABLE= 'N'"; //$NON-NLS-1$ //$NON-NLS-2$
+ "' AND TABLE_TYPE IN ('T', 'P')"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String getShowViewQuery(String qualifier) {
return "SELECT TABLE_NAME FROM QSYS2.SYSTABLES WHERE table_schema = '" +
qualifier.toUpperCase() +
- "' AND TABLE_TYPE IN ('V', 'L') AND SYSTEM_TABLE= 'N'"; //$NON-NLS-1$ //$NON-NLS-2$
+ "' AND TABLE_TYPE IN ('V', 'L')"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
ndr.setTextAttribute(attr);
}
}
+// public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+// ContentAssistant assistant = new ContentAssistant();
+// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("default"),
+// IDocument.DEFAULT_CONTENT_TYPE);
+// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("comment"),
+// SQLPartitionScanner.SQL_COMMENT);
+// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("keyword"),
+// SQLPartitionScanner.SQL_KEYWORD);
+// assistant.setContentAssistProcessor(new SQLContentAssistProcessor("identifier"),
+// SQLPartitionScanner.SQL_IDENTIFIER);
+//
+// // everybody else is doin' it...
+// assistant.enableAutoActivation(true);
+// assistant.setAutoActivationDelay(500);
+//
+// assistant.setProposalPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
+// assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
+// return assistant;
+// }
}
\ No newline at end of file
--- /dev/null
+package com.quantum.editors;
+
+import com.quantum.ImageStore;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+
+/**
+ * @author BC
+ */
+public class SQLContentAssistProcessor implements IContentAssistProcessor {
+
+ private String text;
+ /**
+ * @param string
+ */
+ public SQLContentAssistProcessor(String text) {
+ this.text = text;
+ }
+
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+
+ ICompletionProposal proposal = new CompletionProposal("select",
+ offset, 0, 6, ImageStore.getImage(ImageStore.TEMPLATE),
+ "select - select columns from a table or view", null, null);
+System.out.println(this.text);
+ // complete a key word
+
+ // complete a function
+
+ // provide a template
+
+ // TODO Auto-generated method stub
+ return new ICompletionProposal[] { proposal };
+ }
+
+ /**
+ * BCH: I have no idea what the difference is between context information and
+ * completion proposals.
+ */
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ /**
+ * Unless this method includes a space character, the standard Ctrl-Space key doesn't
+ * provide content assist.
+ */
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return new char[] { ' ' };
+ }
+
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ public String getErrorMessage() {
+ return null;
+ }
+
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+}
*
* @author root
*/
-public class Bookmark {
+public class Bookmark implements Displayable {
public static final int SCHEMA_RULE_USE_ALL = 1;
public static final int SCHEMA_RULE_USE_DEFAULT = 2;
this.propertyChangeSupport.firePropertyChange("schemas", null, null);
}
}
+
+ public String getDisplayName() {
+ return this.name;
+ }
}
--- /dev/null
+package com.quantum.model;
+
+
+/**
+ * @author BC
+ */
+public interface Displayable {
+ public String getDisplayName();
+}
/**
* @author BC
*/
-public class Schema implements Comparable {
+public class Schema implements Comparable, Displayable {
private String name;
private String displayName;
package com.quantum.properties;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Entity;
import com.quantum.model.EntityHolder;
protected void createErrorMessage(Composite composite, Exception e) {
Label icon = new Label(composite, SWT.NONE);
icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
- icon.setImage(QuantumPlugin.getImage("warning.gif"));
+ icon.setImage(ImageStore.getImage(ImageStore.WARNING));
Label error = new Label(composite, SWT.NONE);
error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
import java.sql.SQLException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Column;
import com.quantum.model.Entity;
import com.quantum.model.NotConnectedException;
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0 && element instanceof Column) {
return ((Column) element).isPrimaryKey()
- ? QuantumPlugin.getImage("keycolumn.gif")
- : QuantumPlugin.getImage("column.gif");
+ ? ImageStore.getImage(ImageStore.KEYCOLUMN)
+ : ImageStore.getImage(ImageStore.COLUMN);
} else {
return null;
}
import java.sql.SQLException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.DataType;
import com.quantum.model.NotConnectedException;
private void createErrorMessage(Composite composite, Exception e) {
Label icon = new Label(composite, SWT.NONE);
icon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
- icon.setImage(QuantumPlugin.getImage("warning.gif"));
+ icon.setImage(ImageStore.getImage(ImageStore.WARNING));
Label error = new Label(composite, SWT.NONE);
error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
import java.util.ArrayList;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Entity;
import com.quantum.model.Index;
import com.quantum.model.NotConnectedException;
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 1 && element instanceof IndexAdaptor) {
- return QuantumPlugin.getImage("column.gif");
+ return ImageStore.getImage(ImageStore.COLUMN);
} else {
return null;
}
import java.util.ArrayList;
import java.util.List;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Entity;
import com.quantum.model.ForeignKey;
import com.quantum.model.NotConnectedException;
public Image getColumnImage(Object element, int columnIndex) {
if ((columnIndex == 1 || columnIndex == 2)
&& element instanceof ColumnDetailsAdaptor) {
- return QuantumPlugin.getImage("column.gif");
+ return ImageStore.getImage(ImageStore.COLUMN);
} else if ((columnIndex == 1 || columnIndex == 2)
&& element instanceof TableDetailsAdaptor) {
- return QuantumPlugin.getImage("bigtable.gif");
+ return ImageStore.getImage(ImageStore.TABLE);
} else if ((columnIndex == 0)
&& element instanceof TableDetailsAdaptor) {
- return QuantumPlugin.getImage("foreignkey.gif");
+ return ImageStore.getImage(ImageStore.FOREIGNKEY);
} else {
return null;
}
SQLResults results = new SQLResults();
+ long startTime = System.currentTimeMillis();
System.out.println("Executing"); //$NON-NLS-1$
LogProxy log = LogProxy.getInstance();
log.addText(LogProxy.QUERY, "Executing Request [" + s + "]"); //$NON-NLS-1$ //$NON-NLS-2$
}
log.addText(LogProxy.RESULTS, "Success: result set displayed"); //$NON-NLS-1$
stmt.close();
+ results.setTime(System.currentTimeMillis() - startTime);
System.out.println("Executed"); //$NON-NLS-1$
System.out.println();
return results;
--- /dev/null
+package com.quantum.sql;
+
+/**
+ * @author BC
+ */
+public abstract class SQLGrammar {
+
+ public static String[] KEYWORDS = {
+ "ADD", "ALL", "ALTER", "AND", "ANY",
+ "AS", "ASC", "AUTOINCREMENT", "AVA", "BETWEEN",
+ "BINARY", "BIT", "BOOLEAN", "BY", "CREATE",
+ "BYTE", "CHAR", "CHARACTER", "COLUMN", "CONSTRAINT",
+ "COUNT", "COUNTER", "CURRENCY", "DATABASE", "DATE",
+ "DATETIME", "DELETE", "DESC", "DISALLOW", "DISTINCT",
+ "DISTINCTROW", "DOUBLE", "DROP", "EXISTS", "FROM",
+ "FLOAT", "FLOAT4", "FLOAT8", "FOREIGN", "GENERAL",
+ "GROUP", "GUID", "HAVING", "INNER", "INSERT",
+ "IGNORE", "IMP", "IN", "INDEX", "INT",
+ "INTEGER", "INTEGER1", "INTEGER2", "INTEGER4", "INTO",
+ "IS", "JOIN", "KEY", "LEFT", "LEVEL",
+ "LIKE", "LOGICAL", "LONG", "LONGBINARY", "LONGTEXT",
+ "MAX", "MEMO", "MIN", "MOD", "MONEY",
+ "NOT", "NULL", "NUMBER", "NUMERIC", "OLEOBJECT",
+ "ON", "PIVOT", "OPTION", "PRIMARY", "ORDER",
+ "OUTER", "OWNERACCESS", "PARAMETERS", "PERCENT", "REAL",
+ "REFERENCES", "RIGHT", "SELECT", "SET", "SHORT",
+ "SINGLE", "SMALLINT", "SOME", "STDEV", "STDEVP",
+ "STRING", "SUM", "TABLE", "TABLEID", "TEXT",
+ "TIME", "TIMESTAMP", "TOP", "TRANSFORM", "UNION",
+ "UNIQUE", "UPDATE", "VALUE", "VALUES", "VAR",
+ "VARBINARY", "VARCHAR", "VARP", "WHERE", "WITH",
+ "YESNO"
+ };
+
+ public static final String[] NON_RESERVED_WORDS = {
+ "ADA", "C", "CATALOG_NAME", "CHARACTER_SET_CATALOG", "CHARACTER_SET_NAME",
+ "CHARACTER_SET_SCHEMA", "CLASS_ORIGIN", "COBOL", "COLLATION_CATALOG",
+ "COLLATION_NAME", "COLLATION_SCHEMA", "COLUMN_NAME", "COMMAND_FUNCTION",
+ "COMMITTED", "CONDITION_NUMBER", "CONNECTION_NAME", "CONSTRAINT_CATALOG",
+ "CONSTRAINT_NAME", "CONSTRAINT_SCHEMA", "CURSOR_NAME", "DATA",
+ "DATETIME_INTERVAL_CODE", "DATETIME_INTERVAL_PRECISION", "DYNAMIC_FUNCTION",
+ "FORTRAN", "LENGTH", "MESSAGE_LENGTH", "MESSAGE_OCTET_LENGTH",
+ "MESSAGE_TEXT", "MORE", "MUMPS", "NAME", "NULLABLE", "NUMBER", "PASCAL",
+ "PLI", "REPEATABLE", "RETURNED_LENGTH", "RETURNED_OCTET_LENGTH",
+ "RETURNED_SQLSTATE", "ROW_COUNT", "SCALE", "SCHEMA_NAME",
+ "SERIALIZABLE", "SERVER_NAME", "SUBCLASS_ORIGIN", "TABLE_NAME",
+ "TYPE", "UNCOMMITTED", "UNNAMED"
+ };
+
+ public static final String[] COMMANDS = {
+ "select * from ${tablename} where ${columnname} = ${value}",
+ "update ${tablename} set ${columnname} = ${value} where ${column2name} = ${value2}"
+ };
+}
private boolean hasMore = false;
private boolean isError = false;
private int maxSize = -1;
+ private long time;
public void setColumnNames(Vector columns) {
this.columns = columns;
return rows.toArray();
}
+ public long getTime() {
+ return this.time;
+ }
+ public void setTime(long time) {
+ this.time = time;
+ }
}
import java.util.Vector;
+/**
+ * <p>An SQL Lexer. From
+ * <a href="http://www.dictionary.com/">dictionary.com</a>:
+ *
+ * <blockquote>
+ * <p><b>lexer</b>
+ *
+ * <p>/lek'sr/ n. Common hacker shorthand for 'lexical
+ * analyzer', the input-tokenizing stage in the parser for a language
+ * (the part that breaks it into word-like pieces).
+ * </blockquote>
+ *
+ * <p>Note that this class has nothing to do with the Sci-fi channel's
+ * <a href="http://www.scifi.com/lexx/">Lexx</a> TV series.
+ */
public class SQLLexx {
private static String endline = ";"; //$NON-NLS-1$
private static String dash = "-"; //$NON-NLS-1$
composite,
SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
- text.setText(this.throwable.getMessage());
+ text.setText(this.throwable.getLocalizedMessage());
GridData data =
new GridData(
import java.util.Iterator;
import java.util.List;
+import com.quantum.model.Displayable;
+
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ILabelProviderListener;
}
public String getColumnText(Object element, int columnIndex) {
- return element.toString();
+ if (element instanceof Displayable) {
+ return ((Displayable) element).getDisplayName();
+ } else {
+ return element.toString();
+ }
}
public void addListener(ILabelProviderListener listener) {
package com.quantum.util.versioning;
+import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.FontDialog;
+import org.eclipse.ui.IKeyBindingService;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ExportResourcesAction;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.part.WorkbenchPart;
*/
public class VersioningHelper {
+ public static final int ECLIPSE_VERSION_2_0_1 = 2049;
public static final int ECLIPSE_VERSION_2_1_1 = 2135;
public static final int ECLIPSE_VERSION_3_0_RC1 = 3054;
public static final int ECLIPSE_VERSION_3_0_RC3 = 3061;
}
}
+ public static ExportResourcesAction createExportResourcesAction(IWorkbenchWindow window) {
+ ExportResourcesAction action = null;
+
+ try {
+ if (isEclipse21OrHigher()) {
+ Constructor constructor = ExportResourcesAction.class.getConstructor(
+ new Class[] { IWorkbenchWindow.class });
+ action = (ExportResourcesAction) constructor.newInstance(
+ new Object[] { window });
+ } else {
+ Constructor constructor = ExportResourcesAction.class.getConstructor(
+ new Class[] { IWorkbench.class });
+ action = (ExportResourcesAction) constructor.newInstance(
+ new Object[] { window.getWorkbench() });
+ }
+ } catch (NoSuchMethodException e) {
+ // should not happen
+ } catch (IllegalArgumentException e) {
+ // should not happen
+ } catch (IllegalAccessException e) {
+ // should not happen
+ } catch (InvocationTargetException e) {
+ // should not happen
+ } catch (InstantiationException e) {
+ // should not happen
+ }
+ return action;
+ }
+
+ public static void registerActionToKeyBindingService(
+ IWorkbenchPartSite site, String[] scopes, IAction action) {
+
+ try {
+ if (isEclipse21OrHigher()) {
+ Method method = IWorkbenchPartSite.class.getMethod(
+ "getKeyBindingService", new Class[0]);
+ IKeyBindingService service = (IKeyBindingService) method.invoke(site, null);
+
+ method = IKeyBindingService.class.getMethod(
+ "setScopes", new Class[] { String[].class });
+ method.invoke(service, new Object[] { scopes});
+
+ service.registerAction(action);
+ }
+ } catch (NoSuchMethodException e) {
+ // should not happen
+ } catch (IllegalArgumentException e) {
+ // should not happen
+ } catch (IllegalAccessException e) {
+ // should not happen
+ } catch (InvocationTargetException e) {
+ // should not happen
+ }
+ }
+
public static void main(String[] args) {
System.out.println(SWT.getVersion());
}
+
+ /**
+ * @return
+ */
+ public static boolean isEclipse30() {
+ return SWT.getVersion() >= 3000;
+ }
+
+ /**
+ * @return
+ */
+ public static boolean isEclipse21OrHigher() {
+ return SWT.getVersion() >= 2100;
+ }
+ /**
+ * Method getDescriptor.
+ * @param registry
+ * @param imageName
+ * @return ImageDescriptor
+ */
+ public static ImageDescriptor getDescriptor(
+ ImageRegistry registry,
+ String imageName) {
+ ImageDescriptor descriptor = null;
+ try {
+ if (isEclipse21OrHigher()) {
+ Method method = ImageRegistry.class.getMethod(
+ "getDescriptor", new Class[] { String.class });
+ descriptor = (ImageDescriptor) method.invoke(registry, new Object[] {imageName});
+ }
+ } catch (NoSuchMethodException e) {
+ // should not happen
+ } catch (IllegalArgumentException e) {
+ // should not happen
+ } catch (IllegalAccessException e) {
+ // should not happen
+ } catch (InvocationTargetException e) {
+ // should not happen
+ }
+ return descriptor;
+ }
+
}
+++ /dev/null
-package com.quantum.view;
-
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.swt.graphics.Image;
-
-import com.quantum.QuantumPlugin;
-import com.quantum.model.JDBCDriver;
-
-
-/**
- * @author BC
- */
-public class JDBCDriverLabelProvider implements ITableLabelProvider {
-
- public Image getColumnImage(Object element, int columnIndex) {
- if (columnIndex == 0) {
- return QuantumPlugin.getImage("driver.gif");
- } else {
- return null;
- }
- }
-
- public String getColumnText(Object element, int columnIndex) {
- switch (columnIndex) {
- case 0:
- return ((JDBCDriver) element).getName();
- case 1:
- return ((JDBCDriver) element).getClassName();
- case 2:
- return ((JDBCDriver) element).getVersion();
- case 3:
- return ((JDBCDriver) element).getJarFileName();
- }
- return null;
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
-
-}
import java.util.Iterator;
import java.util.List;
+import com.quantum.ImageStore;
+import com.quantum.Messages;
+import com.quantum.adapters.AdapterFactory;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.model.JDBCDriver;
+
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.adapters.AdapterFactory;
-import com.quantum.model.BookmarkCollection;
-import com.quantum.model.JDBCDriver;
-
/**
* @author BC
public class LabelProviderImpl implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0) {
- return QuantumPlugin.getImage("driver.gif");
+ return ImageStore.getImage(ImageStore.DRIVER);
} else {
return null;
}
package com.quantum.view;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction);
IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
- clearAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("clear.gif")); //$NON-NLS-1$
+ clearAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLEAR));
clearAction.setToolTipText(Messages.getString("SQLLogView.ClearLog")); //$NON-NLS-1$
toolBar.add(clearAction);
package com.quantum.view;
-import java.sql.Connection;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Vector;
+import com.quantum.ImageStore;
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.actions.ExecuteAction;
+import com.quantum.actions.ExportQueryAction;
+import com.quantum.actions.ImportQueryAction;
+import com.quantum.model.Bookmark;
+import com.quantum.model.BookmarkCollection;
+import com.quantum.model.NotConnectedException;
+import com.quantum.sql.MultiSQLServer;
+import com.quantum.sql.SQLGrammar;
+import com.quantum.sql.parser.SQLLexx;
+import com.quantum.sql.parser.Token;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.util.versioning.VersioningHelper;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ExtendedModifyEvent;
import org.eclipse.swt.custom.ExtendedModifyListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IKeyBindingService;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.actions.ExecuteAction;
-import com.quantum.actions.ExportQueryAction;
-import com.quantum.actions.ImportQueryAction;
-import com.quantum.model.Bookmark;
-import com.quantum.model.NotConnectedException;
-import com.quantum.sql.MultiSQLServer;
-import com.quantum.sql.parser.SQLLexx;
-import com.quantum.sql.parser.Token;
-import com.quantum.util.versioning.VersioningHelper;
-import com.quantum.view.bookmark.BookmarkNode;
-import com.quantum.view.bookmark.BookmarkView;
-
public class SQLQueryView extends ViewPart {
private class ClearAction extends Action {
public ClearAction() {
- setImageDescriptor(QuantumPlugin.getImageDescriptor("clear.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.CLEAR));
setToolTipText(Messages.getString("sqlqueryview.clear"));
}
private class AutoCommitPreferenceAction extends Action {
public AutoCommitPreferenceAction() {
- super(Messages.getString("SQLQueryView.AutoCommit"), SWT.CHECK);
+ super(Messages.getString("SQLQueryView.AutoCommit"));
setToolTipText(Messages.getString("SQLQueryView.AutoCommit"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("autocommit.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.AUTOCOMMIT));
}
public void run() {
- Connection connection = null;
- try {
- // Get the connection
- connection = getBookmark().getConnection();
- // If connected (else will throw exception and jump out) switchs the state of the
- // autoCommit option of the JDBC driver
- MultiSQLServer.getInstance().setAutoCommit( connection, isChecked());
- } catch (NotConnectedException e) {
- //Doesn't matter
- }
- // Update the bookmark and the buttons
- updateAutoCommitState(getBookmark(), connection);
+ setAutoCommitPreference(isChecked());
}
}
+ private class RollbackAction extends Action {
+ public RollbackAction() {
+ setText(Messages.getString("SQLQueryView.RollBack"));
+ setToolTipText(Messages.getString("SQLQueryView.RollBack"));
+ }
+
+ public void run() {
+ Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
+ for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; i < length; i++) {
+ try {
+ if (bookmarks[i].isConnected() && !bookmarks[i].getConnection().getAutoCommit()) {
+ MultiSQLServer.getInstance().rollback(bookmarks[i].getConnection());
+ }
+ } catch (SQLException e) {
+ ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ } catch (NotConnectedException e) {
+ ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ }
+ }
+ }
+ }
+
+
+ private class CommitAction extends Action {
+ public CommitAction() {
+ setText(Messages.getString("SQLQueryView.Commit"));
+ setToolTipText(Messages.getString("SQLQueryView.Commit"));
+ }
+
+ public void run() {
+ Bookmark[] bookmarks = BookmarkCollection.getInstance().getBookmarks();
+ for (int i = 0, length = bookmarks == null ? 0 : bookmarks.length; i < length; i++) {
+ try {
+ if (bookmarks[i].isConnected() && !bookmarks[i].getConnection().getAutoCommit()) {
+ MultiSQLServer.getInstance().commit(bookmarks[i].getConnection());
+ }
+ } catch (SQLException e) {
+ ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ } catch (NotConnectedException e) {
+ ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ }
+ }
+ }
+ }
+
+
+ public class LabelProviderImpl implements ILabelProvider {
+ public Image getImage(Object element) {
+ return ImageStore.getImage(ImageStore.BOOKMARK);
+ }
+ public String getText(Object element) {
+ if (element instanceof Bookmark) {
+ return ((Bookmark) element).getName();
+ } else {
+ return null;
+ }
+ }
+ public void addListener(ILabelProviderListener listener) {
+ }
+ public void dispose() {
+ }
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+ public class ContentProviderImpl implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof BookmarkCollection) {
+ return ((BookmarkCollection) inputElement).getBookmarks();
+ } else {
+ return null;
+ }
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
private ExecuteAction executeAction;
private ImportQueryAction importQueryAction;
private ExportQueryAction exportQueryAction;
private StyledText widget;
- private ToolItem autoCommitItem;
- private ToolItem commitItem;
- private ToolItem rollbackItem;
private Color STRING_LITERAL;
private Color KEYWORD;
private Color COMMENT;
private Color NUMERIC;
private Color DEFAULT;
private AutoCommitPreferenceAction autoCommitPreferenceAction;
+ private RollbackAction rollbackAction;
+ private CommitAction commitAction;
+ private boolean autoCommitPreference = true;
public SQLQueryView() {
super();
- }
- public void setFocus() {
-
- String title = "Quantum SQL Query Editor";
- Bookmark bookmark = null;
- Connection con = null;
- if (BookmarkView.getInstance() != null ) {
- bookmark = getBookmark();
- }
- if (bookmark != null) {
- title = bookmark.getName() + " (" + title + ")";
- VersioningHelper.setPartName(this, title);
-// setPartName("fred");
- try {
- con = bookmark.getConnection();
- } catch (NotConnectedException e) {
- // Doesn't matter, "con" remains null
+ IPropertyChangeListener listener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ setFont();
}
- }
-
- updateAutoCommitState(bookmark, con);
-
- widget.setFocus();
-
- }
- /**
- * @return
- */
- private Bookmark getBookmark() {
- if (BookmarkView.getInstance() != null ) {
- BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
- return node == null ? null : node.getBookmark();
- } else {
- return null;
- }
+ };
+ QuantumPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(listener);
}
public static SQLQueryView getInstance() {
return (SQLQueryView) QuantumPlugin.getDefault().getView("com.quantum.view.sqlqueryview");
public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
initActions();
- KEYWORD = new Color(parent.getShell().getDisplay(), 126, 0, 75);
- STRING_LITERAL = new Color(parent.getShell().getDisplay(), 0, 0, 255);
- COMMENT = new Color(parent.getShell().getDisplay(), 88, 148, 64);
- NUMERIC = new Color(parent.getShell().getDisplay(), 255, 0, 0);
- DEFAULT = new Color(parent.getShell().getDisplay(), 0, 0, 0);
- Composite main = new Composite(parent, SWT.NONE);
+ initializeColours(parent);
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
- main.setLayout(layout);
- ToolBar toolbar = new ToolBar(main, SWT.HORIZONTAL);
-
- commitItem = new ToolItem(toolbar, SWT.PUSH);
- commitItem.setImage(QuantumPlugin.getImage("commit.gif")); //$NON-NLS-1$
- commitItem.setToolTipText(Messages.getString("SQLQueryView.Commit")); //$NON-NLS-1$
- commitItem.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent event) {
- try {
- BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
- if (node != null) MultiSQLServer.getInstance().commit(
- node.getBookmark().getConnection());
- } catch (NotConnectedException e) {
- e.printStackTrace();
- }
- }
- });
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ parent.setLayout(layout);
+ parent.setLayoutData(new GridData(GridData.FILL_BOTH));
- rollbackItem = new ToolItem(toolbar, SWT.PUSH);
- rollbackItem.setImage(QuantumPlugin.getImage("rollback.gif")); //$NON-NLS-1$
- rollbackItem.setToolTipText(Messages.getString("SQLQueryView.RollBack")); //$NON-NLS-1$
- rollbackItem.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- }
- public void widgetSelected(SelectionEvent event) {
- try {
- BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
- if (node != null) MultiSQLServer.getInstance().rollback(
- node.getBookmark().getConnection());
- } catch (NotConnectedException e) {
- e.printStackTrace();
- }
- }
- });
-
- autoCommitItem = new ToolItem(toolbar, SWT.CHECK);
- autoCommitItem.setImage(QuantumPlugin.getImage("autocommit.gif")); //$NON-NLS-1$
- autoCommitItem.setToolTipText(Messages.getString("SQLQueryView.AutoCommit")); //$NON-NLS-1$
- autoCommitItem.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent event) {
- BookmarkNode node = BookmarkView.getInstance().getCurrentBookmark();
- if (node == null) return;
- Connection con = null;
- try {
- // Get the connection
- con = node.getBookmark().getConnection();
- // If connected (else will throw exception and jump out) switchs the state of the
- // autoCommit option of the JDBC driver
- MultiSQLServer.getInstance().setAutoCommit( con, autoCommitItem.getSelection());
- } catch (NotConnectedException e) {
- //Doesn't matter
- }
- // Update the bookmark and the buttons
- updateAutoCommitState(node.getBookmark(), con);
-
- }
- });
-
- // TODO: BCH -- this is causing some problems during start-up
- Bookmark bookmark = null;
- try {
- bookmark = getBookmark();
- } catch (NullPointerException e) {
- }
+ widget = new StyledText(parent, SWT.H_SCROLL | SWT.V_SCROLL);
- if (bookmark == null) {
- autoCommitItem.setSelection(true);
- } else {
- autoCommitItem.setSelection(bookmark.isAutoCommit());
- }
- if (autoCommitItem.getSelection()) {
- commitItem.setEnabled(false);
- rollbackItem.setEnabled(false);
- } else {
- commitItem.setEnabled(true);
- rollbackItem.setEnabled(true);
- }
- widget = new StyledText(main, SWT.H_SCROLL | SWT.V_SCROLL);
+ setFont();
IActionBars bars = this.getViewSite().getActionBars();
bars.setGlobalActionHandler(IWorkbenchActionConstants.CUT, cutAction);
widget.setEditable(true);
widget.addExtendedModifyListener(modifyListener);
- GridData gridData = new GridData();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- widget.setLayoutData(gridData);
+ widget.setLayoutData(new GridData(GridData.FILL_BOTH));
- IKeyBindingService keyBindingService = getSite().getKeyBindingService();
- // TODO: check the version numbers for this method
- keyBindingService.setScopes(new String[] {
- "org.eclipse.ui.globalScope",
- "com.quantum.view.sql"
- });
- keyBindingService.registerAction(this.executeAction);
+ VersioningHelper.registerActionToKeyBindingService(getSite(),
+ new String[] { "org.eclipse.ui.globalScope", "com.quantum.view.sql" },
+ this.executeAction);
}
/**
- * Sets the state of the "Commit", "Rollback" and "autoCommit" buttons
- * to reflect the situation in the connection
+ * @param widget2
*/
- protected void updateAutoCommitState(Bookmark bookmark, Connection connection) {
- boolean autoCommit = true;
- // Calculate the state of the autoCommit option
- if (connection != null)
- {
- // If we have a connection, the autoCommit state is that of the connection
- try {
- autoCommit = connection.getAutoCommit();
- } catch (SQLException e) {
- // Doesn't matter, we take default
- }
- } else {
- // if no connection, we try the autoCommit of the bookmark, or else the default
- if (bookmark != null) autoCommit = bookmark.isAutoCommit();
- }
- // Set the autoCommit state of the bookmark to the calculated
- if (bookmark != null) bookmark.setAutoCommit(autoCommit);
- // Set the state of the buttons to the correct autoCommit state
- autoCommitItem.setSelection(autoCommit);
- this.autoCommitPreferenceAction.setChecked(autoCommit);
- if (autoCommitItem.getSelection()) {
- commitItem.setEnabled(false);
- rollbackItem.setEnabled(false);
- } else {
- commitItem.setEnabled(true);
- rollbackItem.setEnabled(true);
+ private void setFont() {
+ FontData font = PreferenceConverter.getFontData(
+ QuantumPlugin.getDefault().getPreferenceStore(),
+ "quantum.font"); //$NON-NLS-1$
+ if (font != null && this.widget != null) {
+ this.widget.setFont(new Font(Display.getCurrent(), font));
}
}
+ /**
+ * @param parent
+ */
+ private void initializeColours(org.eclipse.swt.widgets.Composite parent) {
+ KEYWORD = new Color(parent.getShell().getDisplay(), 126, 0, 75);
+ STRING_LITERAL = new Color(parent.getShell().getDisplay(), 0, 0, 255);
+ COMMENT = new Color(parent.getShell().getDisplay(), 88, 148, 64);
+ NUMERIC = new Color(parent.getShell().getDisplay(), 255, 0, 0);
+ DEFAULT = new Color(parent.getShell().getDisplay(), 0, 0, 0);
+ }
+
private void initActions() {
- executeAction = new ExecuteAction();
- executeAction.init(this);
-
IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+
+ executeAction = new ExecuteAction(this);
toolBar.add(this.executeAction);
-// toolBar.add(this.importQueryAction);
-// toolBar.add(this.exportQueryAction);
-
toolBar.add(new ClearAction());
IActionBars actionBars = getViewSite().getActionBars();
actionBars.getMenuManager().add(this.exportQueryAction);
actionBars.getMenuManager().add(new Separator());
this.autoCommitPreferenceAction = new AutoCommitPreferenceAction();
+ this.autoCommitPreferenceAction.setChecked(this.autoCommitPreference);
actionBars.getMenuManager().add(this.autoCommitPreferenceAction);
- }
+
+ this.rollbackAction = new RollbackAction();
+ actionBars.getMenuManager().add(this.rollbackAction);
+
+ this.commitAction = new CommitAction();
+ actionBars.getMenuManager().add(this.commitAction);
+}
public String getQuery() {
return widget.getText();
widget.setText(text);
}
- private String[] keywords = {
- "ADD", "ALL", "ALTER", "AND", "ANY",
- "AS", "ASC", "AUTOINCREMENT", "AVA", "BETWEEN",
- "BINARY", "BIT", "BOOLEAN", "BY", "CREATE",
- "BYTE", "CHAR", "CHARACTER", "COLUMN", "CONSTRAINT",
- "COUNT", "COUNTER", "CURRENCY", "DATABASE", "DATE",
- "DATETIME", "DELETE", "DESC", "DISALLOW", "DISTINCT",
- "DISTINCTROW", "DOUBLE", "DROP", "EXISTS", "FROM",
- "FLOAT", "FLOAT4", "FLOAT8", "FOREIGN", "GENERAL",
- "GROUP", "GUID", "HAVING", "INNER", "INSERT",
- "IGNORE", "IMP", "IN", "INDEX", "INT",
- "INTEGER", "INTEGER1", "INTEGER2", "INTEGER4", "INTO",
- "IS", "JOIN", "KEY", "LEFT", "LEVEL",
- "LIKE", "LOGICAL", "LONG", "LONGBINARY", "LONGTEXT",
- "MAX", "MEMO", "MIN", "MOD", "MONEY",
- "NOT", "NULL", "NUMBER", "NUMERIC", "OLEOBJECT",
- "ON", "PIVOT", "OPTION", "PRIMARY", "ORDER",
- "OUTER", "OWNERACCESS", "PARAMETERS", "PERCENT", "REAL",
- "REFERENCES", "RIGHT", "SELECT", "SET", "SHORT",
- "SINGLE", "SMALLINT", "SOME", "STDEV", "STDEVP",
- "STRING", "SUM", "TABLE", "TABLEID", "TEXT",
- "TIME", "TIMESTAMP", "TOP", "TRANSFORM", "UNION",
- "UNIQUE", "UPDATE", "VALUE", "VALUES", "VAR",
- "VARBINARY", "VARCHAR", "VARP", "WHERE", "WITH",
- "YESNO" };
-
SyntaxHighlighter textUpdater = new SyntaxHighlighter();
private class UpdateRequest {
max = Math.max(max, start + length);
if (t.getType() == Token.IDENTIFIER) {
boolean keyword = false;
- for (int index = 0; index < keywords.length; index++) {
- if (value.equals(keywords[index])) {
+ for (int index = 0; index < SQLGrammar.KEYWORDS.length; index++) {
+ if (value.equals(SQLGrammar.KEYWORDS[index])) {
keyword = true;
}
}
widget.selectAll();
}
};
+
+ public void setFocus() {
+ }
+ public boolean isAutoCommitPreference() {
+ return this.autoCommitPreference;
+ }
+ public void setAutoCommitPreference(boolean autoCommitPreference) {
+ this.autoCommitPreference = autoCommitPreference;
+ }
}
import java.util.List;
import java.util.Set;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.ConnectionException;
import com.quantum.model.NotConnectedException;
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0) {
- return QuantumPlugin.getImage("schema.gif");
+ return ImageStore.getImage(ImageStore.SCHEMA);
} else {
return null;
}
SimpleSelectionDialog dialog = new SimpleSelectionDialog(
getShell(), Messages.getString(getClass(), "addSchemaDialog"),
schemaList.toArray(),
- QuantumPlugin.getImage("schema.gif"), true);
+ ImageStore.getImage(ImageStore.SCHEMA), true);
int result = dialog.open();
if (result == SimpleSelectionDialog.OK
&& !dialog.getSelection().isEmpty()) {
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.part.ViewPart;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
import com.quantum.actions.CustomCopyAction;
this.customCopyAction1 = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined
this.customCopyAction1.setText(text1); //$NON-NLS-1$
this.customCopyAction1.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$
}
String text2 = store.getString("customCopyName2");
if (text2 != null && text1.trim().length() > 0) {
this.customCopyAction2 = new CustomCopyAction(this,2); // 1 is unused, just in case more custom copies are defined
this.customCopyAction2.setText(text2); //$NON-NLS-1$
this.customCopyAction2.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$
}
String text3 = store.getString("customCopyName3");
if (text3 != null && text1.trim().length() > 0) {
this.customCopyAction3 = new CustomCopyAction(this,3); // 1 is unused, just in case more custom copies are defined
this.customCopyAction3.setText(text3); //$NON-NLS-1$
this.customCopyAction3.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.COPY)); //$NON-NLS-1$
}
}
public void dispose(){
import java.util.Iterator;
-import com.quantum.QuantumPlugin;
+import com.quantum.ImageStore;
import com.quantum.actions.AddToQuickListAction;
import com.quantum.actions.ConnectAction;
import com.quantum.actions.DeleteAllRowsAction;
import com.quantum.actions.ViewTableAction;
import com.quantum.actions.ViewTableDetailsAction;
import com.quantum.model.Bookmark;
+import com.quantum.util.versioning.VersioningHelper;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
this.renameAction = new RenameAction(this.viewPart);
this.copyAction = new CopyAction(this.viewPart, this, selectionProvider);
this.pasteAction = new PasteAction(this.viewPart, this, selectionProvider);
- this.exportAction = new ExportResourcesAction(
- this.viewPart.getViewSite().getWorkbenchWindow());
- this.exportAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("export.gif"));
+ this.exportAction = VersioningHelper.createExportResourcesAction(
+ this.viewPart.getViewSite().getWorkbenchWindow());
+ this.exportAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.EXPORT));
this.propertiesAction = new PropertyDialogAction(
this.viewPart.getSite().getShell(), selectionProvider);
// NOTE: In Eclipse 3.0.0 M6, Export is no longer a sub-class of
// SelectionListenerAction.
- this.exportAction.selectionChanged(getStructuredSelection());
- menu.add(this.exportAction);
+ if (this.exportAction != null) {
+ this.exportAction.selectionChanged(getStructuredSelection());
+ menu.add(this.exportAction);
+ }
if (getStructuredSelection().size() == 1 &&
isEverySelectionInstanceof(BookmarkNode.class)) {
import javax.xml.parsers.ParserConfigurationException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
public CopyAction(IViewPart view, BookmarkClipboard bookmarkClipboard,
ISelectionProvider selectionProvider) {
super(Messages.getString(CopyAction.class.getName() + ".text"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("copy.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.COPY));
this.bookmarkClipboard = bookmarkClipboard;
selectionProvider.addSelectionChangedListener(this);
}
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.SelectionListenerAction;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkCollection;
public PasteAction(IViewPart view, BookmarkClipboard bookmarkClipboard,
ISelectionProvider selectionProvider) {
super(Messages.getString(PasteAction.class.getName() + ".text"));
- setImageDescriptor(QuantumPlugin.getImageDescriptor("paste.gif"));
+ setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PASTE));
selectionProvider.addSelectionChangedListener(this);
this.bookmarkClipboard = bookmarkClipboard;
}
import java.util.Iterator;
import java.util.Vector;
-import com.quantum.QuantumPlugin;
+import com.quantum.ImageStore;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkHolder;
import com.quantum.model.NotConnectedException;
* @return an Image object to appear in the view, null if not found
*/
public Image getImage() {
- return QuantumPlugin.getImage(getImageName());
+ return ImageStore.getImage(getImageName());
}
/**
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
import com.quantum.actions.CustomCopyAction;
private static SubsetNode getRoot(TreeNode node){
while (!( node instanceof SubsetNode))
{
- node = (TreeNode) node.getParent();
+ node = node.getParent();
}
return (SubsetNode) node;
mgr.add(deleteSubsetAction);
deleteSubsetAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
deleteSubsetAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.DELETE));
mgr.add(pasteAction);
pasteAction.setText(Messages.getString("SubsetView.Paste")); //$NON-NLS-1$
- pasteAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("paste.gif")); //$NON-NLS-1$
+ pasteAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PASTE));
mgr.add(exportXMLAction);
exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
- exportXMLAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("xml.gif")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.XML));
} else if (sel instanceof ObjectNode) {
mgr.add(deleteObjectAction);
deleteObjectAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
- deleteObjectAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteObjectAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE));
mgr.add(viewTableAction);
viewTableAction.setText(Messages.getString("bookmarkview.viewTable")); //$NON-NLS-1$
- viewTableAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ viewTableAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
mgr.add(exportXMLAction);
exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
- exportXMLAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("xml.gif")); //$NON-NLS-1$
+ exportXMLAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.XML));
customCopyAction.selectionChanged(
(IStructuredSelection) treeViewer.getSelection());
mgr.add(customCopyAction);
} else if (sel instanceof ColumnNode){
mgr.add(deleteColumnAction);
deleteColumnAction.setText(Messages.getString("SubsetView.Delete")); //$NON-NLS-1$
- deleteColumnAction.setImageDescriptor(QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ deleteColumnAction.setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.DELETE));
customCopyAction.selectionChanged(
(IStructuredSelection) treeViewer.getSelection());
mgr.add(customCopyAction);
newSubsetAction.setText("New Subset"); //$NON-NLS-1$
newSubsetAction.setToolTipText(Messages.getString("SubsetView.CreatesANewEmptySubset")); //$NON-NLS-1$
newSubsetAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("subset.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.SUBSET));
newSubsetAction.init(this);
deleteColumnAction = new DeleteColumnAction();
deleteColumnAction.setText("Delete Column"); //$NON-NLS-1$
deleteColumnAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedColumns")); //$NON-NLS-1$
deleteColumnAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.DELETE));
deleteColumnAction.init(this);
deleteObjectAction = new DeleteObjectAction();
deleteObjectAction.setText("Delete Object"); //$NON-NLS-1$
deleteObjectAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedObject")); //$NON-NLS-1$
deleteObjectAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.DELETE));
deleteObjectAction.init(this);
deleteSubsetAction = new DeleteSubsetAction();
deleteSubsetAction.setText("Delete Subset"); //$NON-NLS-1$
deleteSubsetAction.setToolTipText(Messages.getString("SubsetView.DeletesTheSelectedSubset")); //$NON-NLS-1$
deleteSubsetAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("delete.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.DELETE));
deleteSubsetAction.init(this);
// viewTableAction = new ViewTableAction();
// viewTableAction.setText(Messages.getString("bookmarkview.viewTable")); //$NON-NLS-1$
exportXMLAction = new ExportXMLAction();
exportXMLAction.setText(Messages.getString("bookmarkview.exportXML")); //$NON-NLS-1$
exportXMLAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("table.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.XML));
exportXMLAction.init(this);
this.customCopyAction = new CustomCopyAction(this,1); // 1 is unused, just in case more custom copies are defined
this.customCopyAction.setText(Messages.getString("bookmarkview.customCopyAction")); //$NON-NLS-1$
this.customCopyAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("copy.gif")); //$NON-NLS-1$
+ ImageStore.getImageDescriptor(ImageStore.COPY));
}
}
- public TableViewer addTableViewer(Table table) {
- TableViewer tableViewer = new TableViewer(table);
- tableViewer.setUseHashlookup(true);
- String[] colNams = new String[columnNames.size()];
- for (int i = 0; i < columnNames.size(); i++) {
- colNams[i] = (String) columnNames.get(i);
- }
- tableViewer.setColumnProperties(colNams);
-
- // Create the cell editors
- CellEditor[] editors = new CellEditor[columnNames.size()];
- for (int i = 0; i < columnNames.size(); i++) {
- TextCellEditor textEditor = new TextCellEditor(table);
- ((Text) textEditor.getControl()).setTextLimit(60);
- editors[i] = textEditor;
- }
- // Assign the cell editors to the viewer
- tableViewer.setCellEditors(editors);
- // Set the cell modifier for the viewer
- //tableViewer.setCellModifier(new MetaDataModifier(this));
- // Set the default sorter for the viewer
- //tableViewer.setSorter(new ExampleTaskSorter(ExampleTaskSorter.DESCRIPTION));
-
- return tableViewer;
- }
+// public TableViewer addTableViewer(Table table) {
+// TableViewer tableViewer = new TableViewer(table);
+// tableViewer.setUseHashlookup(true);
+// String[] colNams = new String[columnNames.size()];
+// for (int i = 0; i < columnNames.size(); i++) {
+// colNams[i] = (String) columnNames.get(i);
+// }
+// tableViewer.setColumnProperties(colNams);
+//
+// // Create the cell editors
+// CellEditor[] editors = new CellEditor[columnNames.size()];
+// for (int i = 0; i < columnNames.size(); i++) {
+// TextCellEditor textEditor = new TextCellEditor(table);
+// ((Text) textEditor.getControl()).setTextLimit(60);
+// editors[i] = textEditor;
+// }
+// // Assign the cell editors to the viewer
+// tableViewer.setCellEditors(editors);
+// // Set the cell modifier for the viewer
+// //tableViewer.setCellModifier(new MetaDataModifier(this));
+// // Set the default sorter for the viewer
+// //tableViewer.setSorter(new ExampleTaskSorter(ExampleTaskSorter.DESCRIPTION));
+//
+// return tableViewer;
+// }
public int getPageSize() {
return pageSize;
import java.util.Vector;
+import com.quantum.Messages;
+import com.quantum.QuantumPlugin;
+import com.quantum.extensions.ProcessServiceMembers;
+import com.quantum.model.Bookmark;
+import com.quantum.model.Entity;
+import com.quantum.model.NotConnectedException;
+import com.quantum.sql.SQLResults;
+import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.view.LogProxy;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.part.ViewPart;
-import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
-import com.quantum.extensions.ProcessServiceMembers;
-import com.quantum.model.Bookmark;
-import com.quantum.model.Entity;
-import com.quantum.model.NotConnectedException;
-import com.quantum.sql.SQLResults;
-import com.quantum.ui.dialog.ExceptionDisplayDialog;
-import com.quantum.view.LogProxy;
-
/**
* The Table View. Displays tables and Queries.
*/
* Reload table or query data into the selected tab
*/
public void refreshCurrent() {
- TabItem item = tabs.getItem(tabs.getSelectionIndex());
- TableAdapter adapter = (TableAdapter) item.getData();
- Bookmark bookmark = adapter.getBookmark();
- String table = adapter.getTable();
- if (table == null) {
- loadTable(bookmark, item, null, null, true, true);
- } else {
- loadTable(bookmark, item, null, null, true, true);
+System.out.println("Refresh?");
+ if (tabs.getSelectionIndex() >= 0) {
+System.out.println("Refresh!");
+ TabItem item = tabs.getItem(tabs.getSelectionIndex());
+ TableAdapter adapter = (TableAdapter) item.getData();
+ Bookmark bookmark = adapter.getBookmark();
+ String table = adapter.getTable();
+ if (table == null) {
+ loadTable(bookmark, item, null, null, true, true);
+ } else {
+ loadTable(bookmark, item, null, null, true, true);
+ }
+ String title = Messages.getString("tableview.QuantumTableViewName"); //$NON-NLS-1$
+ if (bookmark != null)
+ title = bookmark.getName() + Messages.getString("tableview.ViewNameInitialDecoration") + title + Messages.getString("tableview.ViewNameFinalDecoration"); //$NON-NLS-1$ //$NON-NLS-2$
+ setTitle(title);
}
- String title = Messages.getString("tableview.QuantumTableViewName"); //$NON-NLS-1$
- if (bookmark != null)
- title = bookmark.getName() + Messages.getString("tableview.ViewNameInitialDecoration") + title + Messages.getString("tableview.ViewNameFinalDecoration"); //$NON-NLS-1$ //$NON-NLS-2$
- setTitle(title);
}
public void loadQuery(Bookmark bookmark, SQLResults results) {
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
-
}
}
\ No newline at end of file
*/
package com.quantum.view.tableview;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.actions.CloseTableAction;
import com.quantum.actions.RefreshTableAction;
import com.quantum.model.NotConnectedException;
public class TableViewToolBar {
private ToolBar toolBar;
- private RefreshTableAction refreshTableAction;
- private CloseTableAction closeTableAction;
private ToolItem previous;
private ToolItem next;
this.toolBar = toolBar;
- refreshTableAction = new RefreshTableAction();
- refreshTableAction.setText(Messages.getString("tableview.refresh")); //$NON-NLS-1$
- refreshTableAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("refresh.gif")); //$NON-NLS-1$
- refreshTableAction.init(view);
- closeTableAction = new CloseTableAction();
- closeTableAction.setText(Messages.getString("tableview.close")); //$NON-NLS-1$
- closeTableAction.setImageDescriptor(
- QuantumPlugin.getImageDescriptor("close.gif")); //$NON-NLS-1$
- closeTableAction.init(view);
-
- ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
- toolItem.setImage(QuantumPlugin.getImage("refresh.gif")); //$NON-NLS-1$
- toolItem.setToolTipText(Messages.getString("tableview.refresh")); //$NON-NLS-1$
- toolItem.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- refreshTableAction.run();
- }
- });
-
final Action copyAction = new CopyAction(view, table);
final Action selectAllAction = new Action() {
public void run() {
table.selectAll();
}
};
- toolItem = new ToolItem(toolBar, SWT.PUSH);
- toolItem.setImage(QuantumPlugin.getImage("copy.gif")); //$NON-NLS-1$
+ ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
+ toolItem.setImage(ImageStore.getImage(ImageStore.COPY));
toolItem.setToolTipText(Messages.getString("tableview.copy")); //$NON-NLS-1$
toolItem.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
toolItem = new ToolItem(toolBar, SWT.PUSH);
- toolItem.setImage(QuantumPlugin.getImage("table.gif")); //$NON-NLS-1$
+ toolItem.setImage(ImageStore.getImage(ImageStore.OPEN_TABLE)); //$NON-NLS-1$
toolItem.setToolTipText(Messages.getString("tableview.selectAll")); //$NON-NLS-1$
toolItem.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
});
filter = new ToolItem(toolBar, SWT.PUSH);
- filter.setImage(QuantumPlugin.getImage("filter.gif")); //$NON-NLS-1$
+ filter.setImage(ImageStore.getImage(ImageStore.FILTER));
filter.setToolTipText(Messages.getString("tableview.filterSort")); //$NON-NLS-1$
toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
previous = new ToolItem(toolBar, SWT.PUSH);
next = new ToolItem(toolBar, SWT.PUSH);
- fullMode.setImage(QuantumPlugin.getImage("fulldata.gif")); //$NON-NLS-1$
+ fullMode.setImage(ImageStore.getImage(ImageStore.FULLDATA));
fullMode.setToolTipText(Messages.getString("tableview.showAll")); //$NON-NLS-1$
fullMode.setSelection(false);
fullMode.addSelectionListener(new SelectionListener() {
}
}
});
- previous.setImage(QuantumPlugin.getImage("previous.gif")); //$NON-NLS-1$
+ previous.setImage(ImageStore.getImage(ImageStore.PREVIOUS));
previous.setToolTipText("Previous"); //$NON-NLS-1$
previous.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
}
});
- next.setImage(QuantumPlugin.getImage("next.gif")); //$NON-NLS-1$
+ next.setImage(ImageStore.getImage(ImageStore.NEXT));
next.setToolTipText("Next"); //$NON-NLS-1$
next.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
- toolItem = new ToolItem(toolBar, SWT.SEPARATOR);
-
- toolItem = new ToolItem(toolBar, SWT.PUSH);
- toolItem.setImage(QuantumPlugin.getImage("close.gif")); //$NON-NLS-1$
- toolItem.setToolTipText(Messages.getString("tableview.close")); //$NON-NLS-1$
- toolItem.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- closeTableAction.run();
- }
- });
-
}
public void setColumns( final TableView view, final TableAdapter ta, Table table) {
package com.quantum.wizards;
+import com.quantum.ImageStore;
import com.quantum.Messages;
import com.quantum.QuantumPlugin;
import com.quantum.adapters.AdapterFactory;
public void widgetSelected(SelectionEvent event) {
SimpleSelectionDialog dialog = new SimpleSelectionDialog(
getShell(), "Select a Driver", JarUtil.getAllDriverNames(
- getDriverFile()), QuantumPlugin.getImage("class.gif"));
+ getDriverFile()), ImageStore.getImage(ImageStore.CLASS));
if (dialog.open() == SimpleSelectionDialog.OK) {
IStructuredSelection selection = dialog.getSelection();
if (!selection.isEmpty()) {
import com.quantum.model.ConnectionException;
import com.quantum.model.Entity;
import com.quantum.model.NotConnectedException;
+import com.quantum.sql.SQLResults;
import com.quantum.sql.TableRow;
import com.quantum.view.ViewHelper;
import com.quantum.view.tableview.TableAdapter;
import org.eclipse.jface.wizard.WizardPage;
/**
- * @author BC
+ * @author BC Holmes
+ * @author Sirkware
*/
public abstract class BaseSQLPage extends WizardPage implements SQLPage {
super(pageName);
}
public boolean performFinish() {
- try {
- Bookmark bookmark = this.adapter.getBookmark();
- bookmark.addQuery(getQueryText());
- ViewHelper.tryGetResults(getShell(), bookmark.getConnection(), getQueryText());
- } catch (ConnectionException e) {
- e.printStackTrace();
- }
- return true;
- }
+ try {
+ Bookmark bookmark = this.adapter.getBookmark();
+ bookmark.addQuery(getQueryText());
+ SQLResults sqlResults = ViewHelper.tryGetResults(getShell(),
+ bookmark.getConnection(), getQueryText());
+ return sqlResults.isError() ? false : true;
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
protected abstract String getQueryText();
protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
import javax.xml.parsers.ParserConfigurationException;
+import com.quantum.ImageStore;
import com.quantum.Messages;
-import com.quantum.QuantumPlugin;
import com.quantum.model.Bookmark;
import com.quantum.model.BookmarkCollection;
import com.quantum.model.xml.ModelToXMLConverter;
public Image getImage(Object element) {
if (element instanceof Bookmark) {
- return QuantumPlugin.getImage("bookmarks.gif");
+ return ImageStore.getImage(ImageStore.BOOKMARK);
} else {
return null;
}