Changes:
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ExecuteAction.java
index 9b1b0e2..9e1294b 100644 (file)
@@ -1,9 +1,8 @@
 package net.sourceforge.phpdt.sql.actions;
 
+import java.sql.Connection;
 import java.util.Vector;
 
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
@@ -11,19 +10,28 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.IViewActionDelegate;
 import org.eclipse.ui.IViewPart;
 
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
 import net.sourceforge.phpdt.sql.sql.SQLParser;
 import net.sourceforge.phpdt.sql.sql.SQLResults;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
 import net.sourceforge.phpdt.sql.view.QueryHistoryView;
 import net.sourceforge.phpdt.sql.view.SQLQueryView;
 import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
 import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
 
+/**
+ * @author panic
+ *
+ *     Executes a query from the QueryView
+ */
 public class ExecuteAction extends Action implements IViewActionDelegate {
        SQLQueryView view;
        boolean flag = false;
-       String execute1 = "Executing Query...";
-       String execute2 = "Executing Query..";
+       String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
+       String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
        public void init(IViewPart view) {
                this.view = (SQLQueryView) view;
        }
@@ -35,7 +43,7 @@ public class ExecuteAction extends Action implements IViewActionDelegate {
        public void run() {
                view.setStatus(execute1);
                MultiSQLServer server = MultiSQLServer.getInstance();
-           view.setStatus("Parsing sql script...");
+           view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
            Vector queries = new Vector();
            String viewQuery = view.getQuery();
                queries = SQLParser.parse(viewQuery);
@@ -53,13 +61,18 @@ public class ExecuteAction extends Action implements IViewActionDelegate {
                        } else {
                                view.setStatus(execute2);
                        }
+                  BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
+                  Connection con = current.getConnection();
+                  
                   String query = (String) queries.elementAt(i);
-                  System.out.println(">" + query + "<");
-                  if (!query.equals("")) {
-                          SQLResults results = server.execute(query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+                  System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
+                  if (con != null && !query.equals("")) { //$NON-NLS-1$
+                          SQLResults results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
                           resultCount++;
                           if (results.isResultSet()) {
-                                TableView.getInstance().loadQuery(results);
+                                PHPEclipseSQLPlugin phpesqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
+                                phpesqlPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+                                TableView.getInstance().loadQuery(current, results);
                                 resultsDisplayed++;
                           } else {
                                 int count = results.getUpdateCount();
@@ -74,16 +87,15 @@ public class ExecuteAction extends Action implements IViewActionDelegate {
                   flag = !flag;
                   view.setProgress(i + 1, queries.size());
            }
-           if (errorCount > 0) {
-               Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
-                   view.setStatus(error, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
-           } else {
-               Image success = PHPEclipseSQLPlugin.getImage("success.gif");
-                   view.setStatus(success, "Done (" + resultCount + " queries executed, " + resultUpdateCount + " rows updated, " + resultsDisplayed + " results displayed, " + errorCount + " errors)");
-           }
+               Image statImage = PHPEclipseSQLPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+               view.setStatus(statImage, 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$ //$NON-NLS-2$
                view.setProgress(0, 1);
                QueryHistoryView history = QueryHistoryView.getInstance();
-               history.addQuery(viewQuery);
+               if (history != null) history.addQuery(viewQuery);
        }
 
        public void selectionChanged(IAction action, ISelection selection) {