package com.quantum.view;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.LinkedList;
+import java.util.List;
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.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
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.Display;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
+import com.quantum.ImageStore;
+import com.quantum.Messages;
+import com.quantum.PluginPreferences;
+import com.quantum.QuantumPlugin;
+import com.quantum.actions.ExecuteAction;
+import com.quantum.actions.ExportQueryAction;
+import com.quantum.actions.ImportQueryAction;
+import com.quantum.editors.ColorManager;
+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.ui.dialog.SQLExceptionDialog;
+import com.quantum.util.versioning.VersioningHelper;
+
public class SQLQueryView extends ViewPart {
private class ClearAction extends Action {
MultiSQLServer.getInstance().rollback(bookmarks[i].getConnection());
}
} catch (SQLException e) {
- ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ SQLExceptionDialog.openException(getSite().getShell(), bookmarks[i], e);
} catch (NotConnectedException e) {
ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
}
MultiSQLServer.getInstance().commit(bookmarks[i].getConnection());
}
} catch (SQLException e) {
- ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
+ SQLExceptionDialog.openException(getSite().getShell(), bookmarks[i], e);
} catch (NotConnectedException e) {
ExceptionDisplayDialog.openError(getSite().getShell(), null, null, e);
}
private ImportQueryAction importQueryAction;
private ExportQueryAction exportQueryAction;
private StyledText widget;
- 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;
+ private IPropertyChangeListener listener;
+ private ColorManager colorManager = new ColorManager();
+
+ private SyntaxHighlighter textUpdater = new SyntaxHighlighter(this.colorManager);
+
public SQLQueryView() {
super();
- IPropertyChangeListener listener = new IPropertyChangeListener() {
+ this.listener = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
setFont();
}
};
QuantumPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(listener);
}
+
+ public void dispose() {
+ QuantumPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this.listener);
+ this.colorManager.dispose();
+ super.dispose();
+ }
+
public static SQLQueryView getInstance() {
return (SQLQueryView) QuantumPlugin.getDefault().getView("com.quantum.view.sqlqueryview");
this.executeAction);
}
- /**
- * @param widget2
- */
private void setFont() {
FontData font = PreferenceConverter.getFontData(
QuantumPlugin.getDefault().getPreferenceStore(),
/**
* @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 initializeColours(Composite parent) {
+ IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
+
+ parent.setBackground(this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.BACKGROUND_COLOR)));
+ this.textUpdater.initializeColours();
}
private void initActions() {
actionBars.getMenuManager().add(this.commitAction);
}
+ /**
+ * Returns the query to be executed. The query is either 1) the
+ * text currently highlighted/selected in the editor or 2) all of
+ * the text in the editor.
+ * @return query string to be executed
+ */
public String getQuery() {
- return widget.getText();
+ String query;
+
+ if (widget.getSelectionText().length() > 0)
+ query = widget.getSelectionText();
+ else
+ query = widget.getText();
+
+ return query;
}
public void setQuery(String text) {
widget.setText(text);
}
- SyntaxHighlighter textUpdater = new SyntaxHighlighter();
-
private class UpdateRequest {
public UpdateRequest(String text, int start, int length) {
this.text = text;
}
private class SyntaxHighlighter extends Thread {
+
+ private Color STRING_LITERAL;
+ private Color KEYWORD;
+ private Color COMMENT;
+ private Color NUMERIC;
+ private Color DEFAULT;
+
private boolean running = true;
private LinkedList requests = new LinkedList();
- public SyntaxHighlighter() {
+ private final ColorManager colorManager;
+ public SyntaxHighlighter(ColorManager colorManager) {
super();
+ this.colorManager = colorManager;
+
setPriority(Thread.MIN_PRIORITY);
start();
}
+ public void initializeColours() {
+ IPreferenceStore store = QuantumPlugin.getDefault().getPreferenceStore();
+
+ this.DEFAULT = this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.TEXT_COLOR));
+ this.KEYWORD = this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.KEYWORD_COLOR));
+ this.STRING_LITERAL = this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.STRING_COLOR));
+ this.COMMENT = this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.COMMENT_COLOR));
+ this.NUMERIC = this.colorManager.getColor(
+ PreferenceConverter.getColor(store, PluginPreferences.NUMERIC_COLOR));
+
+ }
public synchronized void updateText(String text, int start, int length) {
requests.add(new UpdateRequest(text, start, length));
notify();
}
- public synchronized void shutdown() {
- running = false;
- interrupt();
- }
public void run() {
while (running) {
try {
//int dirtyStart = request.start;
//int dirtyEnd = request.start + request.length;
StyleRange styleRange;
- Vector tokens = SQLLexx.parse(text);
- Vector styles = new Vector();
+ List tokens = SQLLexx.parse(text);
+ List styles = new ArrayList();
int min = Integer.MAX_VALUE;
int max = 0;
for (int i = 0; i < tokens.size(); i++) {
- Token t = (Token) tokens.elementAt(i);
+ Token t = (Token) tokens.get(i);
String value = t.getValue();
int start = t.getStart();
int length = t.getEnd() - t.getStart();
} else {
styleRange.foreground = DEFAULT;
}
- styles.addElement(styleRange);
+ styles.add(styleRange);
} else if (t.getType() == Token.COMMENT) {
styleRange.foreground = COMMENT;
- styles.addElement(styleRange);
+ styles.add(styleRange);
} else if (t.getType() == Token.LITERAL) {
styleRange.foreground = STRING_LITERAL;
- styles.addElement(styleRange);
+ styles.add(styleRange);
} else if (t.getType() == Token.NUMERIC) {
styleRange.foreground = NUMERIC;
- styles.addElement(styleRange);
+ styles.add(styleRange);
} else {
- styles.addElement(styleRange);
+ styles.add(styleRange);
}
}
}
- StyleRange[] ranges = new StyleRange[styles.size()];
- for (int k = 0; k < ranges.length; k++) {
- ranges[k] = (StyleRange) styles.elementAt(k);
- }
+ StyleRange[] ranges =
+ (StyleRange[]) styles.toArray(new StyleRange[styles.size()]);
if (max >= 0 && ranges.length > 0) {
setStyles(ranges, min, max - min);
}