misc
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / ExecuteAction.java
index f8c4418..295cfa3 100644 (file)
@@ -17,27 +17,30 @@ 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.jface.action.IStatusLineManager;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IViewActionDelegate;
 import org.eclipse.ui.IViewPart;
 
 /**
- * @author panic
+ * Executes a query from the QueryView
  *
- *     Executes a query from the QueryView
+ * @author panic
  */
 public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate {
        SQLQueryView view;
-       boolean flag = false;
        String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
        String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
     
        public ExecuteAction() {
                setActionDefinitionId("com.quantum.actions.ExecuteAction");
+               setImageDescriptor(QuantumPlugin.getImageDescriptor("play.gif"));
+               setText(Messages.getString("sqlqueryview.executeQuery"));
+               setToolTipText(Messages.getString("sqlqueryview.executeQuery"));
        }
     
        public void init(IViewPart view) {
@@ -56,10 +59,11 @@ public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate
                           view.getSite().getShell(),"Sorry","Please select a bookmark to use as connection.");
                         return;
                }                  
+               getStatusLineManager().setErrorMessage(null);
                Connection con = getConnection();
-               view.setStatus(execute1);
+               getStatusLineManager().setMessage(execute1);
                MultiSQLServer server = MultiSQLServer.getInstance();
-               view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
+               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
@@ -75,11 +79,13 @@ public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate
                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 (flag) {
-                               view.setStatus(execute1);
+                       if (i % 2 == 0) {
+                               getStatusLineManager().setMessage(execute1);
                        } else {
-                               view.setStatus(execute2);
+                               getStatusLineManager().setMessage(execute2);
                        }
                   
                   String query = (String) queries.elementAt(i);
@@ -111,19 +117,32 @@ public class ExecuteAction extends BaseSQLAction implements IViewActionDelegate
                                        resultUpdateCount += results.getUpdateCount();
                                 }
                           }
-                  }
-                  flag = !flag;
-                  view.setProgress(i + 1, queries.size());
+                   }
+System.out.println(getStatusLineManager().getProgressMonitor() == null ? "not found" : "found!");
+                       progressBar.worked(i);
+//                 view.setProgress(i + 1, queries.size());
                }
-               Image statImage = QuantumPlugin.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$
+               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$
+                                               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);
+               }
+       }
 
-               view.setProgress(0, 1);
+       /**
+        * @return
+        */
+       private IStatusLineManager getStatusLineManager() {
+               return this.view.getViewSite().getActionBars().getStatusLineManager();
        }
 
        public void selectionChanged(IAction action, ISelection selection) {