You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2023/03/29 10:43:44 UTC

[hop] branch master updated: do not show progress dialog in hop web. fixes #2736

This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 11ef3cba3b do not show progress dialog in hop web. fixes #2736
     new 8a74796291 Merge pull request #2775 from bamaer/2736
11ef3cba3b is described below

commit 11ef3cba3b5f996d6de68db774e8da8a11bfce24
Author: Bart Maertens <ba...@know.bi>
AuthorDate: Fri Mar 24 11:23:39 2023 +0100

    do not show progress dialog in hop web. fixes #2736
---
 .../dialog/GetPreviewTableProgressDialog.java      | 137 +++++++++++++--------
 .../dialog/PipelinePreviewProgressDialog.java      | 127 +++++++++++--------
 2 files changed, 156 insertions(+), 108 deletions(-)

diff --git a/ui/src/main/java/org/apache/hop/ui/core/database/dialog/GetPreviewTableProgressDialog.java b/ui/src/main/java/org/apache/hop/ui/core/database/dialog/GetPreviewTableProgressDialog.java
index 4c7a924025..aa247e362c 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/database/dialog/GetPreviewTableProgressDialog.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/database/dialog/GetPreviewTableProgressDialog.java
@@ -22,6 +22,7 @@ import org.apache.hop.core.IRunnableWithProgress;
 import org.apache.hop.core.ProgressMonitorAdapter;
 import org.apache.hop.core.database.Database;
 import org.apache.hop.core.database.DatabaseMeta;
+import org.apache.hop.core.exception.HopDatabaseException;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.row.IRowMeta;
 import org.apache.hop.core.variables.IVariables;
@@ -29,6 +30,9 @@ import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.ui.core.dialog.ErrorDialog;
 import org.apache.hop.ui.core.dialog.ProgressMonitorDialog;
 import org.apache.hop.ui.hopgui.HopGui;
+import org.apache.hop.ui.util.EnvironmentUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Cursor;
 import org.eclipse.swt.widgets.Shell;
 
 import java.lang.reflect.InvocationTargetException;
@@ -67,62 +71,86 @@ public class GetPreviewTableProgressDialog {
   }
 
   public List<Object[]> open() {
-    IRunnableWithProgress op =
-        monitor -> {
-          db = new Database(HopGui.getInstance().getLoggingObject(), variables, dbMeta);
-          try {
-            db.connect();
-
-            if (limit > 0) {
-              db.setQueryLimit(limit);
-            }
-
-            rows = db.getFirstRows(tableName, limit, new ProgressMonitorAdapter(monitor));
-            rowMeta = db.getReturnRowMeta();
-          } catch (HopException e) {
-            throw new InvocationTargetException(
-                e, "Couldn't find any rows because of an error :" + e.toString());
-          } finally {
-            db.disconnect();
-          }
-        };
-
-    try {
-      final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
-      // Run something in the background to cancel active database queries, forecably if needed!
-      Runnable run =
-          () -> {
-            IProgressMonitor monitor = pmd.getProgressMonitor();
-            while (pmd.getShell() == null
-                || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
-              try {
-                Thread.sleep(100);
-              } catch (InterruptedException e) {
-                // Ignore
-              }
-            }
-
-            if (monitor.isCanceled()) { // Disconnect and see what happens!
-
-              try {
-                db.cancelQuery();
-              } catch (Exception e) {
-                // Ignore
-              }
-            }
-          };
-      // Start the cancel tracker in the background!
-      new Thread(run).start();
-
-      pmd.run(true, op);
-    } catch (InvocationTargetException e) {
-      showErrorDialog(e);
-      return null;
-    } catch (InterruptedException e) {
-      showErrorDialog(e);
-      return null;
+    if(!EnvironmentUtils.getInstance().isWeb()){
+      IRunnableWithProgress op =
+              monitor -> {
+                db = new Database(HopGui.getInstance().getLoggingObject(), variables, dbMeta);
+                try {
+                  db.connect();
+
+                  if (limit > 0) {
+                    db.setQueryLimit(limit);
+                  }
+
+                  rows = db.getFirstRows(tableName, limit, new ProgressMonitorAdapter(monitor));
+                  rowMeta = db.getReturnRowMeta();
+                } catch (HopException e) {
+                  throw new InvocationTargetException(
+                          e, "Couldn't find any rows because of an error :" + e.toString());
+                } finally {
+                  db.disconnect();
+                }
+              };
+      try {
+        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
+        // Run something in the background to cancel active database queries, forecably if needed!
+        Runnable run =
+                () -> {
+                  IProgressMonitor monitor = pmd.getProgressMonitor();
+                  while (pmd.getShell() == null
+                          || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
+                    try {
+                      Thread.sleep(100);
+                    } catch (InterruptedException e) {
+                      // Ignore
+                    }
+                  }
+
+                  if (monitor.isCanceled()) { // Disconnect and see what happens!
+
+                    try {
+                      db.cancelQuery();
+                    } catch (Exception e) {
+                      // Ignore
+                    }
+                  }
+                };
+        // Start the cancel tracker in the background!
+        new Thread(run).start();
+
+        pmd.run(true, op);
+      } catch (InvocationTargetException e) {
+        showErrorDialog(e);
+        return null;
+      } catch (InterruptedException e) {
+        showErrorDialog(e);
+        return null;
+      }
+    }else{
+      try{
+        Cursor cursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
+        shell.setCursor(cursor);
+
+        db = new Database(HopGui.getInstance().getLoggingObject(), variables, dbMeta);
+        db.connect();
+
+        if (limit > 0) {
+          db.setQueryLimit(limit);
+        }
+
+        rows = db.getFirstRows(tableName, limit, null);
+        rowMeta = db.getReturnRowMeta();
+
+      }catch(HopDatabaseException e){
+        showErrorDialog(e);
+        return null;
+      }finally{
+        db.disconnect();
+      }
+
     }
 
+
     return rows;
   }
 
@@ -143,4 +171,5 @@ public class GetPreviewTableProgressDialog {
   public IRowMeta getRowMeta() {
     return rowMeta;
   }
+
 }
diff --git a/ui/src/main/java/org/apache/hop/ui/pipeline/dialog/PipelinePreviewProgressDialog.java b/ui/src/main/java/org/apache/hop/ui/pipeline/dialog/PipelinePreviewProgressDialog.java
index 688504ecdf..c9aa00fd85 100644
--- a/ui/src/main/java/org/apache/hop/ui/pipeline/dialog/PipelinePreviewProgressDialog.java
+++ b/ui/src/main/java/org/apache/hop/ui/pipeline/dialog/PipelinePreviewProgressDialog.java
@@ -19,6 +19,7 @@ package org.apache.hop.ui.pipeline.dialog;
 
 import org.apache.hop.core.IProgressMonitor;
 import org.apache.hop.core.IRunnableWithProgress;
+import org.apache.hop.core.exception.HopDatabaseException;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.core.logging.HopLogStore;
 import org.apache.hop.core.row.IRowMeta;
@@ -33,6 +34,9 @@ import org.apache.hop.pipeline.transform.TransformMeta;
 import org.apache.hop.ui.core.dialog.ErrorDialog;
 import org.apache.hop.ui.core.dialog.ProgressMonitorDialog;
 import org.apache.hop.ui.hopgui.HopGui;
+import org.apache.hop.ui.util.EnvironmentUtils;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Cursor;
 import org.eclipse.swt.widgets.Shell;
 
 import java.lang.reflect.InvocationTargetException;
@@ -84,49 +88,55 @@ public class PipelinePreviewProgressDialog {
   public PipelineMeta open(final boolean showErrorDialogs) {
     final HopGui hopGui = HopGui.getInstance();
 
-    IRunnableWithProgress op = monitor -> doPreview(hopGui, monitor, showErrorDialogs);
+    if(!EnvironmentUtils.getInstance().isWeb()){
+      IRunnableWithProgress op = monitor -> doPreview(hopGui, monitor, showErrorDialogs);
 
-    try {
-      final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
-
-      // Run something in the background to cancel active database queries, force this if needed!
-      Runnable run =
-          () -> {
-            IProgressMonitor monitor = pmd.getProgressMonitor();
-            while (pmd.getShell() == null
-                || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
-              try {
-                Thread.sleep(100);
-              } catch (InterruptedException e) {
-                // Ignore
-              }
-            }
-
-            if (monitor.isCanceled()) { // Disconnect and see what happens!
-
-              try {
-                pipeline.stopAll();
-              } catch (Exception e) {
-                /* Ignore */
-              }
-            }
-          };
-
-      // Start the cancel tracker in the background!
-      new Thread(run).start();
-
-      pmd.run(true, op);
-    } catch (InvocationTargetException | InterruptedException e) {
-      if (showErrorDialogs) {
-        new ErrorDialog(
-            shell,
-            BaseMessages.getString(
-                PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogTitle"),
-            BaseMessages.getString(
-                PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogMessage"),
-            e);
+      try {
+        final ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
+
+        // Run something in the background to cancel active database queries, force this if needed!
+        Runnable run =
+                () -> {
+                  IProgressMonitor monitor = pmd.getProgressMonitor();
+                  while (pmd.getShell() == null
+                          || (!pmd.getShell().isDisposed() && !monitor.isCanceled())) {
+                    try {
+                      Thread.sleep(100);
+                    } catch (InterruptedException e) {
+                      // Ignore
+                    }
+                  }
+
+                  if (monitor.isCanceled()) { // Disconnect and see what happens!
+
+                    try {
+                      pipeline.stopAll();
+                    } catch (Exception e) {
+                      /* Ignore */
+                    }
+                  }
+                };
+
+        // Start the cancel tracker in the background!
+        new Thread(run).start();
+
+        pmd.run(true, op);
+      } catch (InvocationTargetException | InterruptedException e) {
+        if (showErrorDialogs) {
+          new ErrorDialog(
+                  shell,
+                  BaseMessages.getString(
+                          PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogTitle"),
+                  BaseMessages.getString(
+                          PKG, "PipelinePreviewProgressDialog.ErrorLoadingPipeline.DialogMessage"),
+                  e);
+        }
+        pipelineMeta = null;
       }
-      pipelineMeta = null;
+    }else{
+        Cursor cursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
+        shell.setCursor(cursor);
+        doPreview(hopGui, null, showErrorDialogs);
     }
 
     return pipelineMeta;
@@ -134,8 +144,10 @@ public class PipelinePreviewProgressDialog {
 
   private void doPreview(
       final HopGui hopGui, final IProgressMonitor progressMonitor, final boolean showErrorDialogs) {
-    progressMonitor.beginTask(
-        BaseMessages.getString(PKG, "PipelinePreviewProgressDialog.Monitor.BeginTask.Title"), 100);
+    if(progressMonitor != null){
+      progressMonitor.beginTask(
+              BaseMessages.getString(PKG, "PipelinePreviewProgressDialog.Monitor.BeginTask.Title"), 100);
+    }
 
     // This pipeline is ready to run in preview!
     //
@@ -163,7 +175,7 @@ public class PipelinePreviewProgressDialog {
 
       // It makes no sense to continue, so just stop running...
       //
-      if (!progressMonitor.isCanceled()) {
+      if (progressMonitor != null && !progressMonitor.isCanceled()) {
           progressMonitor.done();
         }
       return;
@@ -190,11 +202,13 @@ public class PipelinePreviewProgressDialog {
         (pipelineDebugMeta, transformDebugMeta, rowBufferMeta, rowBuffer) -> {
           String transformName = transformDebugMeta.getTransformMeta().getName();
           previewComplete.add(transformName);
-          progressMonitor.subTask(
-              BaseMessages.getString(
-                  PKG,
-                  "PipelinePreviewProgressDialog.SubTask.TransformPreviewFinished",
-                  transformName));
+          if(progressMonitor != null){
+            progressMonitor.subTask(
+                    BaseMessages.getString(
+                            PKG,
+                            "PipelinePreviewProgressDialog.SubTask.TransformPreviewFinished",
+                            transformName));
+          }
         });
     // set the appropriate listeners on the pipeline...
     //
@@ -223,7 +237,7 @@ public class PipelinePreviewProgressDialog {
 
     while (previewComplete.size() < previewTransformNames.length
         && !pipeline.isFinished()
-        && !progressMonitor.isCanceled()) {
+        && (progressMonitor == null || !progressMonitor.isCanceled())) {
 
       // How many rows are done?
       int nrDone = 0;
@@ -238,8 +252,11 @@ public class PipelinePreviewProgressDialog {
 
       int worked = pct - previousPct;
 
-      if (worked > 0) {
-        progressMonitor.worked(worked);
+      if(progressMonitor != null){
+        if (worked > 0) {
+          progressMonitor.worked(worked);
+        }
+
       }
       previousPct = pct;
 
@@ -250,7 +267,7 @@ public class PipelinePreviewProgressDialog {
         // Ignore errors
       }
 
-      if (progressMonitor.isCanceled()) {
+      if (progressMonitor != null && progressMonitor.isCanceled()) {
         cancelled = true;
         pipeline.stopAll();
       }
@@ -264,7 +281,9 @@ public class PipelinePreviewProgressDialog {
             .getBuffer(pipeline.getLogChannel().getLogChannelId(), true)
             .toString();
 
-    progressMonitor.done();
+    if(progressMonitor != null){
+      progressMonitor.done();
+    }
   }
 
   /**