new class to manage icons. Showing failures,etc on a test suite.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / SQLQueryView.java
index 0b14583..fd3348e 100644 (file)
@@ -1,16 +1,20 @@
 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.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;
@@ -19,11 +23,13 @@ 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;
 
 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;
@@ -36,12 +42,15 @@ 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.dnd.Clipboard;
+import org.eclipse.swt.dnd.TransferData;
 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.Display;
 import org.eclipse.ui.IActionBars;
 import org.eclipse.ui.IWorkbenchActionConstants;
@@ -87,7 +96,7 @@ public class SQLQueryView extends ViewPart {
                                                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);
                    }
@@ -110,7 +119,7 @@ public class SQLQueryView extends ViewPart {
                                                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);
                    }
@@ -158,25 +167,32 @@ public class SQLQueryView extends ViewPart {
        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");
 
@@ -228,12 +244,12 @@ public class SQLQueryView extends ViewPart {
        /**
         * @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() {
@@ -271,8 +287,6 @@ public class SQLQueryView extends ViewPart {
                widget.setText(text);
        }
        
-       SyntaxHighlighter textUpdater = new SyntaxHighlighter();
-       
        private class UpdateRequest {
                public UpdateRequest(String text, int start, int length) {
                        this.text = text;
@@ -285,21 +299,42 @@ public class SQLQueryView extends ViewPart {
        }
        
        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 {
@@ -315,12 +350,12 @@ public class SQLQueryView extends ViewPart {
                                        //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();
@@ -349,25 +384,23 @@ public class SQLQueryView extends ViewPart {
                                                                } 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);
                                        }