From fb05d7626296041057a75d22da95b752a1acabc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ko=C5=BEusznik?= <jan@kozusznik.cz> Date: Tue, 12 Jun 2018 14:34:17 +0200 Subject: [PATCH] feature: info about directories feature and small refactoring --- .../src/main/java/cz/it4i/fiji/haas/Job.java | 4 + .../cz/it4i/fiji/haas/ui/ShellRoutines.java | 22 ++++ .../core/BenchmarkJobManager.java | 4 + ...troller.java => BenchmarkSPIMControl.java} | 18 +-- .../ui/BenchmarkSPIMWindow.java | 4 +- .../ui/JobDetailControl.java | 49 ++++++-- .../ui/JobPropertiesControl.java | 113 ++++++++++++++++++ .../haas_spim_benchmark/ui/BenchmarkSPIM.fxml | 4 +- .../haas_spim_benchmark/ui/JobDetail.fxml | 11 +- .../haas_spim_benchmark/ui/JobProperties.fxml | 27 +++++ .../test/java/cz/it4i/fiji/haas/TestFX.java | 8 +- 11 files changed, 233 insertions(+), 31 deletions(-) create mode 100644 haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ShellRoutines.java rename haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/{BenchmarkSPIMController.java => BenchmarkSPIMControl.java} (95%) create mode 100644 haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobPropertiesControl.java create mode 100644 haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobProperties.fxml diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java index 330bb892..64a16889 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java @@ -398,6 +398,10 @@ public class Job { return inputDirectory; } + public Path getOutputDirectory() { + return outputDirectory; + } + private void storeInputOutputDirectory() { if (inputDirectory == null) { useDemoData = true; diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ShellRoutines.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ShellRoutines.java new file mode 100644 index 00000000..6c4b0047 --- /dev/null +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ShellRoutines.java @@ -0,0 +1,22 @@ +package cz.it4i.fiji.haas.ui; + +import java.awt.Desktop; +import java.io.IOException; +import java.nio.file.Path; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public interface ShellRoutines { + + public static final Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.ui.ShellRoutines.class); + + public static void openDirectoryInBrowser(Path directory) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.open(directory.toFile()); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } +} diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java index e565d1d6..f79b9fe9 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java @@ -267,6 +267,10 @@ public class BenchmarkJobManager implements Closeable { return job.getInputDirectory(); } + public Path getOutputDirectory() { + return job.getOutputDirectory(); + } + private ProgressNotifier convertTo(Progress progress) { return progress == null ? null : new P_ProgressNotifierAdapter(progress); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMControl.java similarity index 95% rename from haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java rename to haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMControl.java index cf340231..dbe847aa 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMControl.java @@ -2,7 +2,6 @@ package cz.it4i.fiji.haas_spim_benchmark.ui; import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.CONFIG_YAML; -import java.awt.Desktop; import java.awt.Window; import java.io.IOException; import java.nio.file.Files; @@ -33,6 +32,7 @@ import cz.it4i.fiji.haas.ui.InitiableControl; import cz.it4i.fiji.haas.ui.JavaFXRoutines; import cz.it4i.fiji.haas.ui.ModalDialogs; import cz.it4i.fiji.haas.ui.ProgressDialog; +import cz.it4i.fiji.haas.ui.ShellRoutines; import cz.it4i.fiji.haas.ui.TableViewContextMenu; import cz.it4i.fiji.haas_java_client.JobState; import cz.it4i.fiji.haas_java_client.UploadingFile; @@ -54,7 +54,7 @@ import javafx.scene.layout.Region; import net.imagej.updater.util.Progress; //FIXME: fix Exception during context menu request on task with N/A state -public class BenchmarkSPIMController extends BorderPane implements CloseableControl, InitiableControl { +public class BenchmarkSPIMControl extends BorderPane implements CloseableControl, InitiableControl { @FXML private TableView<ObservableBenchmarkJob> jobs; @@ -76,9 +76,9 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont private ObservableBenchmarkJobRegistry registry; private static Logger log = LoggerFactory - .getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMController.class); + .getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMControl.class); - public BenchmarkSPIMController(BenchmarkJobManager manager) { + public BenchmarkSPIMControl(BenchmarkJobManager manager) { this.manager = manager; JavaFXRoutines.initRootAndController("BenchmarkSPIM.fxml", this); @@ -132,8 +132,7 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont log.error(e.getMessage(), e); } }, job -> JavaFXRoutines.notNullValue(job, - j -> j.getState() == JobState.Running || j.getState() == JobState.Finished - || j.getState() == JobState.Failed || j.getState() == JobState.Canceled)); + j -> true)); menu.addItem("Upload data", job -> executeWSCallAsync("Uploading data", p -> job.getValue().startUpload()), job -> executeWSCallAsync("Stop uploading data", p -> job.getValue().stopUpload()), @@ -226,12 +225,7 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont private void open(BenchmarkJob j) { executorServiceUI.execute(() -> { - Desktop desktop = Desktop.getDesktop(); - try { - desktop.open(j.getDirectory().toFile()); - } catch (IOException e) { - log.error(e.getMessage(), e); - } + ShellRoutines.openDirectoryInBrowser(j.getDirectory()); }); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java index d2a19cdb..840e058e 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java @@ -8,14 +8,14 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkSPIMParameters; -public class BenchmarkSPIMWindow extends FXFrame<BenchmarkSPIMController>{ +public class BenchmarkSPIMWindow extends FXFrame<BenchmarkSPIMControl>{ private static final long serialVersionUID = 1L; public BenchmarkSPIMWindow(Window parentWindow, BenchmarkSPIMParameters params) throws IOException { super(parentWindow,()->{ try { - return new BenchmarkSPIMController(new BenchmarkJobManager(params)); + return new BenchmarkSPIMControl(new BenchmarkJobManager(params)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetailControl.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetailControl.java index 4cad2bb6..2191ce83 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetailControl.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetailControl.java @@ -1,44 +1,75 @@ package cz.it4i.fiji.haas_spim_benchmark.ui; +import java.awt.Window; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import cz.it4i.fiji.haas.ui.CloseableControl; +import cz.it4i.fiji.haas.ui.InitiableControl; import cz.it4i.fiji.haas.ui.JavaFXRoutines; +import cz.it4i.fiji.haas_java_client.JobState; import cz.it4i.fiji.haas_java_client.SynchronizableFileType; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.Constants; import javafx.fxml.FXML; +import javafx.scene.control.Tab; import javafx.scene.control.TabPane; -public class JobDetailControl extends TabPane implements CloseableControl { +public class JobDetailControl extends TabPane implements CloseableControl, InitiableControl { @SuppressWarnings("unused") private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.JobDetailControl.class); - @FXML - private SPIMPipelineProgressViewController progressView; - - @FXML - private LogViewControl errorOutput; + @FXML private SPIMPipelineProgressViewController progressView; - @FXML - private LogViewControl standardOutput; + @FXML private LogViewControl errorOutput; + @FXML private LogViewControl standardOutput; + + @FXML private JobPropertiesControl jobProperties; + + @FXML private Tab jobPropertiesTab; + private final HaaSOutputObservableValueRegistry observableValueRegistry; + private final BenchmarkJob job; + + public JobDetailControl(BenchmarkJob job) { JavaFXRoutines.initRootAndController("JobDetail.fxml", this); progressView.setJob(job); observableValueRegistry = new HaaSOutputObservableValueRegistry(job, Constants.HAAS_UPDATE_TIMEOUT / Constants.UI_TO_HAAS_FREQUENCY_UPDATE_RATIO); errorOutput.setObservable(observableValueRegistry.createObservable(SynchronizableFileType.StandardErrorFile)); - standardOutput.setObservable(observableValueRegistry.createObservable(SynchronizableFileType.StandardOutputFile)); + standardOutput + .setObservable(observableValueRegistry.createObservable(SynchronizableFileType.StandardOutputFile)); + jobProperties.setJob(job); observableValueRegistry.start(); + this.job = job; + } + + @Override + public void init(Window parameter) { + if (!isExecutionDetailsAvailable(job)) { + enableOnlySpecificTab(jobPropertiesTab); + } + } + + + private void enableOnlySpecificTab(Tab tabToLeaveEnabled) { + getTabs().stream().filter(node -> node != jobPropertiesTab).forEach(node -> node.setDisable(true)); + getSelectionModel().select(jobPropertiesTab); + } + + private boolean isExecutionDetailsAvailable(BenchmarkJob job) { + return job.getState() == JobState.Running || job.getState() == JobState.Finished + || job.getState() == JobState.Failed || job.getState() == JobState.Canceled; } @Override public void close() { observableValueRegistry.close(); progressView.close(); + jobProperties.close(); } } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobPropertiesControl.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobPropertiesControl.java new file mode 100644 index 00000000..b26f0f3c --- /dev/null +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/JobPropertiesControl.java @@ -0,0 +1,113 @@ +package cz.it4i.fiji.haas_spim_benchmark.ui; + +import java.io.Closeable; +import java.nio.file.Path; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Consumer; +import java.util.function.Function; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import cz.it4i.fiji.haas.ui.JavaFXRoutines; +import cz.it4i.fiji.haas.ui.ShellRoutines; +import cz.it4i.fiji.haas.ui.UpdatableObservableValue; +import cz.it4i.fiji.haas.ui.UpdatableObservableValue.UpdateStatus; +import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.scene.control.TableRow; +import javafx.scene.control.TableView; +import javafx.scene.layout.BorderPane; + +public class JobPropertiesControl extends BorderPane implements Closeable{ + private static final String FXML_FILE_NAME = "JobProperties.fxml"; + public static final Logger log = LoggerFactory + .getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.JobPropertiesControl.class); + + @FXML + private TableView<ObservableValue<P_Value>> properties; + + private BenchmarkJob job; + + private final ExecutorService executorServiceUI; + + public JobPropertiesControl() { + JavaFXRoutines.initRootAndController(FXML_FILE_NAME, this); + executorServiceUI = Executors.newSingleThreadExecutor(); + initTable(); + } + + public void setJob(BenchmarkJob job) { + this.job = job; + fillTable(); + } + + @Override + public void close() { + executorServiceUI.shutdown(); + } + + private void initTable() { + setCellValueFactory(0, s -> s.getName()); + setCellValueFactory(1, s -> s.getValueAsString()); + setOnDoubleClickAction(rowData -> ShellRoutines.openDirectoryInBrowser(rowData.getPath())); + } + + private void setOnDoubleClickAction(Consumer<P_Value> r) { + properties.setRowFactory( tv -> { + TableRow<ObservableValue<P_Value>> row = new TableRow<>(); + row.setOnMouseClicked(event -> { + if (event.getClickCount() == 2 && (! row.isEmpty()) ) { + P_Value rowData = row.getItem().getValue(); + if(rowData.isOpenAllowed()) { + executorServiceUI.execute(()->r.accept(rowData)); + } + } + }); + return row ; + }); + } + + private void fillTable() { + properties.getItems().add(new UpdatableObservableValue<JobPropertiesControl.P_Value>( + new P_Value("Input", job.getInputDirectory(), "Demo data on server"), x->UpdateStatus.NotUpdated, x->x)); + properties.getItems().add(new UpdatableObservableValue<JobPropertiesControl.P_Value>( + new P_Value("Output", job.getOutputDirectory(), "N/A"), x->UpdateStatus.NotUpdated, x->x)); + + } + + private void setCellValueFactory(int i, Function<P_Value, String> mapper) { + JavaFXRoutines.setCellValueFactory(properties, i, mapper); + } + private class P_Value { + private final String name; + private final Path path; + private final String textIfNull; + + public P_Value(String name, Path path, String textIfNull) { + this.name = name; + this.path = path; + this.textIfNull = textIfNull; + } + + public String getName() { + return name; + } + + public String getValueAsString() { + return Optional.ofNullable(path).map(p->p.toString()).orElse(textIfNull); + } + + public boolean isOpenAllowed() { + return path != null; + } + + public Path getPath() { + return path; + } + } +} + diff --git a/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml index 95312b15..31729e32 100644 --- a/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml +++ b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml @@ -6,7 +6,7 @@ <?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.HBox?> -<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMController"> +<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMControl"> <center> <HBox> @@ -14,7 +14,7 @@ <TableView fx:id="jobs" prefHeight="400.0" prefWidth="1410.0" HBox.hgrow="ALWAYS"> <columns> - <TableColumn prefWidth="70.0" text="Job Id" /> + <TableColumn prefWidth="70.0" text="Job ID" /> <TableColumn prefWidth="149.0" text="Status" /> <TableColumn prefWidth="230.0" text="Creation time" /> <TableColumn prefWidth="230.0" text="Start time" /> diff --git a/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetail.fxml b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetail.fxml index cb3c9255..75ad019d 100644 --- a/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetail.fxml +++ b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobDetail.fxml @@ -6,6 +6,7 @@ <?import javafx.scene.control.TabPane?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> +<?import cz.it4i.fiji.haas_spim_benchmark.ui.JobPropertiesControl?> <fx:root type="TabPane" xmlns:fx="http://javafx.com/fxml/1" @@ -28,7 +29,7 @@ </HBox> </content> </Tab> - <Tab closable="false" text="Other output"> + <Tab closable="false" text="Other output" > <content> <HBox> <LogViewControl fx:id="standardOutput" HBox.hgrow="ALWAYS" /> @@ -36,5 +37,13 @@ </content> </Tab> + <Tab closable="false" text="Job directories" fx:id="jobPropertiesTab"> + <content> + <HBox> + <JobPropertiesControl fx:id="jobProperties" HBox.hgrow="ALWAYS" /> + </HBox> + </content> + + </Tab> </tabs> </fx:root> diff --git a/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobProperties.fxml b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobProperties.fxml new file mode 100644 index 00000000..dc683df8 --- /dev/null +++ b/haas-spim-benchmark/src/main/resources/cz/it4i/fiji/haas_spim_benchmark/ui/JobProperties.fxml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.TableColumn?> +<?import javafx.scene.control.TableView?> +<?import javafx.scene.layout.BorderPane?> +<?import javafx.scene.layout.HBox?> + +<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.JobPropertiesControl"> + <center> + <HBox> + <children> + + <TableView fx:id="properties" prefHeight="400.0" prefWidth="550.0" HBox.hgrow="ALWAYS"> + <columns> + <TableColumn prefWidth="150.0" text="Type of directory" /> + <TableColumn prefWidth="400.0" text="Location" /> + </columns> + </TableView> + </children> + <padding> + <Insets bottom="1.0" left="1.0" right="1.0" top="1.0" /> + </padding> + </HBox> + </center> + +</fx:root> diff --git a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/TestFX.java b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/TestFX.java index 207a4fb5..b094e17f 100644 --- a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/TestFX.java +++ b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/TestFX.java @@ -3,16 +3,15 @@ package cz.it4i.fiji.haas; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMController; +import cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMControl; public class TestFX { public static void main(String[] args) { @SuppressWarnings("serial") - class Window extends FXFrame<BenchmarkSPIMController>{ + class Window extends FXFrame<BenchmarkSPIMControl>{ public Window() { - super(()->new BenchmarkSPIMController(null)); - // TODO Auto-generated constructor stub + super(()->new BenchmarkSPIMControl(null)); } } @@ -22,7 +21,6 @@ public class TestFX { window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { - // TODO Auto-generated method stub super.windowClosed(e); System.exit(0); } -- GitLab