Skip to content
Snippets Groups Projects
Commit fb05d762 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

feature: info about directories

feature and small refactoring
parent 9f4c0aa9
No related branches found
No related tags found
No related merge requests found
Showing
with 233 additions and 31 deletions
......@@ -398,6 +398,10 @@ public class Job {
return inputDirectory;
}
public Path getOutputDirectory() {
return outputDirectory;
}
private void storeInputOutputDirectory() {
if (inputDirectory == null) {
useDemoData = true;
......
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);
}
}
}
......@@ -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);
}
......
......@@ -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());
});
}
......
......@@ -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);
}
......
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();
}
}
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;
}
}
}
......@@ -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" />
......
......@@ -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>
<?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>
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment