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

iss1026: connect RemoteFileInfo control to UI as testing

parent 06b02dab
No related branches found
No related tags found
1 merge request!14Iss1026
......@@ -6,6 +6,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -135,5 +136,13 @@ public interface JavaFXRoutines {
}
});
}
public static <T> boolean notNullValue(ObservableValue<T> j, Predicate<T> pred) {
if (j == null || j.getValue() == null) {
return false;
} else {
return pred.test(j.getValue());
}
}
}
......@@ -16,7 +16,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.swing.WindowConstants;
......@@ -44,15 +43,7 @@ import net.imagej.updater.util.Progress;
public class BenchmarkSPIMController extends BorderPane implements CloseableControl, InitiableControl {
private static boolean notNullValue(ObservableValue<BenchmarkJob> j, Predicate<BenchmarkJob> pred) {
if (j == null || j.getValue() == null) {
return false;
} else {
return pred.test(j.getValue());
}
}
@FXML
@FXML
private TableView<ObservableValue<BenchmarkJob>> jobs;
private BenchmarkJobManager manager;
......@@ -99,37 +90,36 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
menu.addItem("Start job", job -> executeWSCallAsync("Starting job", p -> {
job.getValue().startJob(p);
registry.get(job.getValue()).update();
}), job -> notNullValue(job, j -> j.getState() == JobState.Configuring || j.getState() == JobState.Finished
}), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Configuring || j.getState() == JobState.Finished
|| j.getState() == JobState.Failed));
menu.addItem("Cancel job", job -> executeWSCallAsync("Canceling job", p -> {
job.getValue().cancelJob();
registry.get(job.getValue()).update();
}), job -> notNullValue(job, j -> j.getState() == JobState.Running));
}), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Running));
menu.addItem("Execution details", job -> {
try {
new JobDetailWindow(root, job.getValue()).setVisible(true);
} catch (IOException e) {
// TODO Auto-generated catch block
log.error(e.getMessage(), e);
}
}, job -> notNullValue(job, j -> j.getState() == JobState.Running || j.getState() == JobState.Finished
}, job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Running || j.getState() == JobState.Finished
|| j.getState() == JobState.Failed || j.getState() == JobState.Canceled));
menu.addItem("Download result",
job -> executeWSCallAsync("Downloading data", p -> job.getValue().downloadData(p)),
job -> notNullValue(job,
job -> JavaFXRoutines.notNullValue(job,
j -> EnumSet.of(JobState.Failed, JobState.Finished, JobState.Canceled).contains(j.getState())
&& !j.downloaded()));
menu.addItem("Download statistics",
job -> executeWSCallAsync("Downloading data", p -> job.getValue().downloadStatistics(p)),
job -> notNullValue(job, j -> j.getState() == JobState.Finished));
job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Finished));
menu.addItem("Explore errors", job -> job.getValue().exploreErrors(),
job -> notNullValue(job, j -> j.getState().equals(JobState.Failed)));
job -> JavaFXRoutines.notNullValue(job, j -> j.getState().equals(JobState.Failed)));
menu.addItem("Open working directory", j -> open(j.getValue()), x -> notNullValue(x, j -> true));
menu.addItem("Open working directory", j -> open(j.getValue()), x -> JavaFXRoutines.notNullValue(x, j -> true));
}
private void open(BenchmarkJob j) {
......
......@@ -5,6 +5,8 @@ import java.util.List;
import java.util.function.Function;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas.ui.CloseableControl;
import cz.it4i.fiji.haas.ui.InitiableControl;
......@@ -16,6 +18,10 @@ import javafx.scene.layout.BorderPane;
public class RemoteFilesInfoControl extends BorderPane implements CloseableControl, InitiableControl {
@SuppressWarnings("unused")
private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.RemoteFilesInfoControl.class);
@SuppressWarnings("unused")
private Window root;
......@@ -25,7 +31,6 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr
public RemoteFilesInfoControl(List<ObservableValue< RemoteFileInfo>> files) {
JavaFXRoutines.initRootAndController("RemoteFilesInfo.fxml", this);
files.forEach(file->this.files.getItems().add(file));
}
@Override
......@@ -36,7 +41,6 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr
@Override
public void close() {
// TODO Auto-generated method stub
}
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -14,6 +17,7 @@ import java.util.stream.Collectors;
import cz.it4i.fiji.haas.ui.CloseableControl;
import cz.it4i.fiji.haas.ui.JavaFXRoutines;
import cz.it4i.fiji.haas.ui.TableViewContextMenu;
import cz.it4i.fiji.haas_java_client.JobState;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
......@@ -21,6 +25,7 @@ import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService;
import cz.it4i.fiji.haas_spim_benchmark.core.Task;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
......@@ -98,7 +103,56 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
tasks.setPrefWidth(PREFERRED_WIDTH);
timer = new Timer();
registry = new ObservableTaskRegistry(task -> tasks.getItems().remove(registry.get(task)));
TableViewContextMenu<ObservableValue<Task>> menu = new TableViewContextMenu<ObservableValue<Task>>(this.tasks);
menu.addItem("Open view", task->proof(task), x->x!=null);
}
private void proof(ObservableValue<Task> task) {
executorServiceWS.execute(()-> {
TaskComputationAdapter adapter = new TaskComputationAdapter(task.getValue().getComputations().get(0));
class Window extends cz.it4i.fiji.haas.ui.FXFrame<RemoteFilesInfoControl>{
private static final long serialVersionUID = 1L;
public Window() {
super(()-> new RemoteFilesInfoControl(adapter.getOutputs()));
}
}
Window w = new Window();
w.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
adapter.close();
}
});
w.setVisible(true);});
}
static void add(Collection<ObservableValue<RemoteFileInfo>> files, String name, long size) {
RemoteFileInfo file = new RemoteFileInfo() {
@Override
public Long getSize() {
return size;
}
@Override
public String getName() {
return name;
}
};
ObservableValue<RemoteFileInfo> value = new ObservableValueBase<RemoteFileInfo>() {
@Override
public RemoteFileInfo getValue() {
return file;
}
};
files.add(value);
}
private void fillTable() {
......
......@@ -11,6 +11,7 @@ import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
//TASK: Dodělat naplnění logs, aktualizace a getXXX
// Pokračovat zapojením do UI - akce v SPIMPipelineProgressViewWindow
// pro zobrazení TaskComputation
......@@ -18,8 +19,9 @@ public class TaskComputationAdapter implements Closeable {
private final TaskComputation computation;
private final List<ObservableOutputFile> outputs = new LinkedList<>();
private final List<ObservableValue<RemoteFileInfo>> outputs = new LinkedList<>();
@SuppressWarnings("unused")
private final List<ObservableValue<String>> logs = new LinkedList<>();
private final Timer timer;
......@@ -32,15 +34,19 @@ public class TaskComputationAdapter implements Closeable {
timer.scheduleAtFixedRate(new P_TimerTask(), Constants.HAAS_TIMEOUT, Constants.HAAS_TIMEOUT);
}
private void addOutputFile(String outputFile, Long size) {
outputs.add(new ObservableOutputFile(outputFile, size));
}
@Override
public void close() {
timer.cancel();
}
public List<ObservableValue<RemoteFileInfo>> getOutputs() {
return outputs;
}
private void addOutputFile(String outputFile, Long size) {
outputs.add(new ObservableOutputFile(outputFile, size));
}
public static class Log {
public String getName() {
return null;
......@@ -51,7 +57,7 @@ public class TaskComputationAdapter implements Closeable {
}
}
private class ObservableOutputFile extends ObservableValueBase<RemoteFileInfo> {
public class ObservableOutputFile extends ObservableValueBase<RemoteFileInfo> {
private final String name;
......@@ -94,7 +100,7 @@ public class TaskComputationAdapter implements Closeable {
@Override
public void run() {
Map<String, Long> sizes = computation.getOutFileSizes();
outputs.forEach(value -> value.setSize(sizes.get(value.getValue().getName())));
outputs.forEach(value -> ((ObservableOutputFile) value).setSize(sizes.get(value.getValue().getName())));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment