From eebc64f7ea9aa92883dd97bd6b0b9b54696c076f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Dr=C4=83ghici?= Date: Sat, 8 Apr 2023 03:26:10 +0300 Subject: [PATCH] [SNAP-1597](snap-sta): Improvements according the new operator UI API changes. --- .../operators/tooladapter/ToolAdapterOp.java | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/snap-sta/src/main/java/org/esa/snap/core/gpf/operators/tooladapter/ToolAdapterOp.java b/snap-sta/src/main/java/org/esa/snap/core/gpf/operators/tooladapter/ToolAdapterOp.java index f01eaa58b43..d4da6801fc1 100644 --- a/snap-sta/src/main/java/org/esa/snap/core/gpf/operators/tooladapter/ToolAdapterOp.java +++ b/snap-sta/src/main/java/org/esa/snap/core/gpf/operators/tooladapter/ToolAdapterOp.java @@ -180,35 +180,46 @@ public List getErrors() { } /** - * Initialise and run the defined tool. - *

- * This method will block until the tool finishes its execution. - *

+ * Initialise the defined tool. * - * @throws OperatorException + * @throws OperatorException when validation error occurs */ @Override public void initialize() throws OperatorException { + if (descriptor == null) { + descriptor = ((ToolAdapterOperatorDescriptor) getSpi().getOperatorDescriptor()); + } + if (errorMessages != null) { + errorMessages.clear(); + } + validateDescriptor(); + if (!isStopped) { + beforeExecute(); + } + setTargetProduct(new Product("STA empty product", "unknown", 0, 0)); + isInitialised = true; + } + + /** + * Executes the operator. + * + * @param pm A progress monitor to be notified for long-running tasks. + * @throws OperatorException If an error occurs during computation of the target raster. + */ + public void doExecute(ProgressMonitor pm) throws OperatorException { + if (this.progressMonitor == null) { + this.progressMonitor = SubProgressMonitor.create(pm, 1); + } + if (this.consumer == null) { + this.consumer = new DefaultOutputConsumer(descriptor.getProgressPattern(), descriptor.getErrorPattern(), descriptor.getStepPattern(), this.progressMonitor); + this.consumer.setLogger(getLogger()); + } Date currentTime = new Date(); int ret = -1; try { - if (descriptor == null) { - descriptor = ((ToolAdapterOperatorDescriptor) getSpi().getOperatorDescriptor()); - } if (this.progressMonitor != null) { this.progressMonitor.beginTask("Executing " + this.descriptor.getName(), 100); } - if (this.consumer == null) { - this.consumer = new DefaultOutputConsumer(descriptor.getProgressPattern(), descriptor.getErrorPattern(), descriptor.getStepPattern(), this.progressMonitor); - this.consumer.setLogger(getLogger()); - } - if (errorMessages != null) { - errorMessages.clear(); - } - validateDescriptor(); - if (!isStopped) { - beforeExecute(); - } if (!isStopped) { if ((ret = execute()) != 0) { this.consumer.consumeOutput(String.format("Process exited with value %d", ret)); @@ -221,9 +232,8 @@ public void initialize() throws OperatorException { } finally { try { if (!wasCancelled) { - isInitialised = (postExecute() == 0); - } else { - isInitialised = true; + ret = postExecute(); + this.consumer.consumeOutput(String.format("Load the result of the tool's execution exited with value %d", ret)); } } finally { if (this.progressMonitor != null) { @@ -239,7 +249,6 @@ public void initialize() throws OperatorException { } } } - public List getExecutionOutput() { return this.consumer.getProcessOutput(); }