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

iss1026: fixes

initial size TaskComputationWindow
TaskComputationWindow modality
creation TaskComputationWindow on separate Thread
parent e4ed45c2
No related branches found
No related tags found
1 merge request!14Iss1026
Showing
with 90 additions and 174 deletions
......@@ -110,7 +110,7 @@ public class ProgressDialog extends JDialog implements Progress {
if (title != null)
setTitle(title);
pack();
//TASK: vyresit centrovani na predka
if (owner != null) {
final Dimension o = owner.getSize();
final Dimension size = getSize();
......
......@@ -2,6 +2,7 @@ package cz.it4i.fiji.haas_spim_benchmark.core;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -83,8 +84,8 @@ public class TaskComputation {
private int positionInOutput;
private Collection<String> inputs;
private Collection<String> outputs;
private Collection<String> logs;
private Collection<String> outputs = Collections.emptyList();
private Collection<String> logs = Collections.emptyList();
private Long id;
private final List<BenchmarkError> errors;
......
......@@ -21,18 +21,21 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr
@SuppressWarnings("unused")
private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.RemoteFilesInfoControl.class);
@SuppressWarnings("unused")
private Window root;
@FXML
private TableView<ObservableValue<RemoteFileInfo>> files;
public RemoteFilesInfoControl(List<ObservableValue< RemoteFileInfo>> files) {
public RemoteFilesInfoControl() {
JavaFXRoutines.initRootAndController("RemoteFilesInfo.fxml", this);
files.forEach(file->this.files.getItems().add(file));
}
public void setFiles(List<ObservableValue<RemoteFileInfo>> files) {
files.forEach(file -> this.files.getItems().add(file));
}
@Override
public void init(Window parameter) {
this.root = parameter;
......@@ -47,8 +50,9 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr
private void initTable() {
JavaFXRoutines.setCellValueFactory(files, 0, file -> file.getName());
JavaFXRoutines.setCellValueFactory(files, 1,
(Function<RemoteFileInfo, String>) file -> file.getSize() >= 0 ? formatSize(file.getSize()) : "Not exists");
(Function<RemoteFileInfo, String>) file -> file.getSize() >= 0 ? formatSize(file.getSize())
: "Not exists");
}
private String formatSize(long size) {
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Window;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
......@@ -13,8 +14,12 @@ import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.swing.WindowConstants;
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.ui.ModalDialogs;
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;
......@@ -30,7 +35,7 @@ import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl {
public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl,InitiableControl {
private static final String EMPTY_VALUE = "\u2007\u2007\u2007";
......@@ -68,6 +73,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
private ObservableTaskRegistry registry;
private ExecutorService executorServiceWS;
private Executor executorFx = new FXFrameExecutorService();
private Window root;
public SPIMPipelineProgressViewController() {
executorServiceWS = Executors.newSingleThreadExecutor();
......@@ -96,6 +102,11 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
executorServiceWS.shutdown();
}
@Override
public void init(Window parameter) {
this.root = parameter;
}
private void init() {
JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this);
tasks.setPrefWidth(PREFERRED_WIDTH);
......@@ -106,9 +117,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
}
private void proof(ObservableValue<Task> task) {
//executorServiceWS.execute(()-> {
new TaskComputationWindow(null, task.getValue().getComputations().get(0)).setVisible(true);
//});
ModalDialogs.doModal(new TaskComputationWindow(root, task.getValue().getComputations().get(0)),WindowConstants.DISPOSE_ON_CLOSE);
}
static void add(Collection<ObservableValue<RemoteFileInfo>> files, String name, long size) {
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Window;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.WindowConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -8,40 +15,59 @@ 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.ui.ModalDialogs;
import cz.it4i.fiji.haas.ui.ProgressDialog;
import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationAdapter.ObservableLog;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
//TASK: context menu udělat pro TaskComputation (buňku) nikoliv řádek
//TASK: TaskComputationWindow - vyřešit vlákna na kterých se to spouští
//TASK: dodělat progress dialog + modalita
//TASK: vyřešit problém při konkurentním scp
//TASK: TaskComputationWindow - iniciální velikost okna
public class TaskComputationControl extends TabPane implements CloseableControl, InitiableControl {
@SuppressWarnings("unused")
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl.class);
private final TaskComputationAdapter adapter;
private TaskComputationAdapter adapter;
private Executor uiExecutor = new FXFrameExecutorService();
private ExecutorService wsExecutorService = Executors.newSingleThreadExecutor();
@FXML
private RemoteFilesInfoControl remoteFilesInfo;
private TaskComputation computation;
public TaskComputationControl(TaskComputation computation) {
JavaFXRoutines.initRootAndController("TaskComputationView.fxml", this);
adapter = new TaskComputationAdapter(computation);
this.computation = computation;
}
@Override
public void init(Window parameter) {
RemoteFilesInfoControl infoControl= new RemoteFilesInfoControl(adapter.getOutputs());
infoControl.init(parameter);
addTab("Output files", infoControl);
for (ObservableLog log: adapter.getLogs()) {
LogViewControl logViewControl = new LogViewControl();
logViewControl.setObservable(log.getContent());
addTab(log.getName(), logViewControl);
}
wsExecutorService.execute(() -> {
ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(parameter, "Updating infos..."),
WindowConstants.DO_NOTHING_ON_CLOSE);
try {
adapter = new TaskComputationAdapter(computation);
} finally {
dialog.done();
}
remoteFilesInfo.setFiles(adapter.getOutputs());
remoteFilesInfo.init(parameter);
Collection<Runnable> runs = new LinkedList<>();
for (ObservableLog log : adapter.getLogs()) {
LogViewControl logViewControl = new LogViewControl();
logViewControl.setObservable(log.getContent());
runs.add(() -> addTab(log.getName(), logViewControl));
}
uiExecutor.execute(() -> runs.forEach(r -> r.run()));
});
}
private void addTab(String title, Node control) {
......@@ -56,6 +82,7 @@ public class TaskComputationControl extends TabPane implements CloseableControl,
@Override
public void close() {
adapter.close();
wsExecutorService.shutdown();
}
......
<?xml version="1.0" encoding="UTF-8"?>
<?import cz.it4i.fiji.haas_spim_benchmark.ui.LogViewControl?>
<?import cz.it4i.fiji.haas_spim_benchmark.ui.SPIMPipelineProgressViewController?>
<?import cz.it4i.fiji.haas_spim_benchmark.ui.RemoteFilesInfoControl?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
......@@ -10,4 +9,13 @@
<fx:root type="TabPane" xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/8.0.65" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl">
<Tab closable="false" text="Output files">
<content>
<HBox>
<RemoteFilesInfoControl fx:id="remoteFilesInfo"
HBox.hgrow="ALWAYS" />
</HBox>
</content>
</Tab>
</fx:root>
......@@ -19,7 +19,7 @@ public class RunRemoteFilesView {
@SuppressWarnings("serial")
class Window extends cz.it4i.fiji.haas.ui.FXFrame<RemoteFilesInfoControl>{
public Window() {
super(()-> new RemoteFilesInfoControl(files));
super(()-> new RemoteFilesInfoControl());
}
}
......
package cz.it4i.fiji.haas;
import cz.it4i.fiji.haas.ui.FXFrameNative;
public class RunSPIMPipelineView {
public static void main(String[] args) {
class Window extends FXFrameNative<SPIMPipelineProgressViewController>{
public Window() {
super(()-> new SPIMPipelineProgressViewController());
}
}
new Window().setVisible(true);
}
}
package cz.it4i.fiji.haas;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import cz.it4i.fiji.haas.ui.CloseableControl;
import cz.it4i.fiji.haas.ui.JavaFXRoutines;
import cz.it4i.fiji.haas.ui.ResizeableControl;
import cz.it4i.fiji.haas_java_client.JobState;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
import javafx.fxml.FXML;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl, ResizeableControl {
protected static final String RUNNING_STATE_COMPUTATION = Color.YELLOW.toString();
protected static final String FINISHED_STATE_COMPUTATION = null;
protected static final String UNKNOWN_STATE_COMPUTATION = Color.GRAY.toString();
private final Map<JobState, Color> taskExecutionState2Color = new HashMap<>();
{
taskExecutionState2Color.put(JobState.Running, Color.YELLOW);
taskExecutionState2Color.put(JobState.Finished, Color.GREEN);
taskExecutionState2Color.put(JobState.Failed, Color.RED);
taskExecutionState2Color.put(JobState.Unknown, Color.GRAY);
}
private String getColorTaskExecState(JobState jobState) {
Color result = null;
if (jobState == null) {
result = Color.GRAY;
} else {
result = taskExecutionState2Color.get(jobState);
}
return toCss(result != null ? result : Color.ORANGE);
}
private static String toCss(Color color) {
return "rgb(" + Math.round(color.getRed() * 255.0) + "," + Math.round(color.getGreen() * 255.0) + ","
+ Math.round(color.getBlue() * 255.0) + ")";
}
@FXML
public TableView<ObservableValue<String>> tasks;
public SPIMPipelineProgressViewController() {
init();
}
public void close() {
}
@Override
public void setSize(double width, double height) {
tasks.setPrefSize(width, height);
}
private void init() {
JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this);
fillTable();
}
private void fillTable() {
JavaFXRoutines.setCellValueFactory(this.tasks, 0, (Function<String, String>) v -> v);
for (int i = 1; i <= 91; i++) {
this.tasks.getColumns().add(new TableColumn<>(i + ""));
constructCellFactory(i);
}
for (int i = 0; i < 10; i++) {
tasks.getItems().add(new ObservableValueBase<String>() {
@Override
public String getValue() {
return "Value";
}
});
}
}
@SuppressWarnings("unchecked")
private void constructCellFactory(int index) {
JavaFXRoutines.setCellValueFactory(this.tasks, index, (Function<String, String>) v -> {
return v;
});
((TableColumn<ObservableValue<String>, String>) this.tasks.getColumns().get(index)).setCellFactory(column -> {
TableCell<ObservableValue<String>, String> result = new TableCell<ObservableValue<String>, String>() {
@Override
protected void updateItem(String computation, boolean empty) {
if (computation == null || empty) {
setText(null);
setStyle("");
} else {
setText("\u2007\u2007\u2007");
setStyle("-fx-background-color: " + getColorTaskExecState(JobState.Finished));
}
}
};
return result;
});
}
}
......@@ -23,6 +23,7 @@ import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.UserInfo;
public class ScpClient implements Closeable {
private String hostName;
private String username;
private JSch jsch = new JSch();
......@@ -314,6 +315,15 @@ public class ScpClient implements Closeable {
return null;
}
@Override
public void close() {
if (session != null && session.isConnected()) {
//log.info("disconnect");
session.disconnect();
session = null;
}
}
private int getBufferSize() {
return 1024 * 1024;
}
......@@ -327,6 +337,7 @@ public class ScpClient implements Closeable {
session.setUserInfo(ui);
}
if (!session.isConnected()) {
//log.info("connect");
session.connect();
}
return session;
......@@ -392,12 +403,4 @@ public class ScpClient implements Closeable {
}
return b;
}
@Override
public void close() {
if (session != null && session.isConnected()) {
session.disconnect();
session = null;
}
}
}
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