Skip to content
Snippets Groups Projects
Commit 694dd1a0 authored by Petr Bainar's avatar Petr Bainar
Browse files

miscStuff: updating SPIMPipelineProgressViewController (WIP WIP WIP)

parent 7c0caa7a
Branches
No related tags found
2 merge requests!31Misc stuff extended,!30Create SimpleObservableList and use it for SPIMPipelineProgressViewController
...@@ -21,6 +21,7 @@ import javafx.scene.control.TableColumn; ...@@ -21,6 +21,7 @@ import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow; import javafx.scene.control.TableRow;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.util.Callback;
public interface JavaFXRoutines { public interface JavaFXRoutines {
...@@ -62,7 +63,15 @@ public interface JavaFXRoutines { ...@@ -62,7 +63,15 @@ public interface JavaFXRoutines {
Function<U, V> mapper) { Function<U, V> mapper) {
((TableColumn<T, V>) tableView.getColumns().get(index)) ((TableColumn<T, V>) tableView.getColumns().get(index))
.setCellValueFactory(f -> new ObservableValueAdapter<>(f.getValue(), mapper)); .setCellValueFactory(f -> new ObservableValueAdapter<>(f.getValue(), mapper));
}
@SuppressWarnings("unchecked")
static public <T, V> void setCellValueFactoryForList(TableView<T> tableView,
int index,
Callback<TableColumn.CellDataFeatures<T, V>, ObservableValue<V>> callback)
{
((TableColumn<T, V>) tableView.getColumns().get(index)).setCellValueFactory(
callback);
} }
static public RunnableFuture<Void> runOnFxThread(Runnable runnable) { static public RunnableFuture<Void> runOnFxThread(Runnable runnable) {
......
...@@ -9,7 +9,6 @@ import java.util.Optional; ...@@ -9,7 +9,6 @@ import java.util.Optional;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
...@@ -34,7 +33,6 @@ import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableList; ...@@ -34,7 +33,6 @@ import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableList;
import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableValue; import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableValue;
import cz.it4i.fiji.haas_spim_benchmark.core.Task; import cz.it4i.fiji.haas_spim_benchmark.core.Task;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation; import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
...@@ -74,7 +72,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl ...@@ -74,7 +72,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
} }
@FXML @FXML
private TableView<ObservableValue<Task>> tasks; private TableView<Task> tasks;
private SimpleObservableList<Task> observedValue; private SimpleObservableList<Task> observedValue;
...@@ -134,54 +132,52 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl ...@@ -134,54 +132,52 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this); JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this);
tasks.setPrefWidth(PREFERRED_WIDTH); tasks.setPrefWidth(PREFERRED_WIDTH);
TableViewContextMenu<ObservableValue<Task>> menu = TableViewContextMenu<Task> menu = new TableViewContextMenu<>(this.tasks);
new TableViewContextMenu<>(this.tasks);
menu.addItem("Open view", (task, columnIndex) -> proof(task, columnIndex), ( menu.addItem("Open view", (task, columnIndex) -> proof(task, columnIndex), (
x, columnIndex) -> check(x, columnIndex)); x, columnIndex) -> check(x, columnIndex));
} }
private boolean check(ObservableValue<Task> x, Integer columnIndex) { private boolean check(Task x, Integer columnIndex) {
boolean result = x != null && 0 < columnIndex &&columnIndex - 1 < x.getValue().getComputations().size(); boolean result = x != null && 0 < columnIndex && columnIndex - 1 < x
.getComputations().size();
return result; return result;
} }
private void proof(ObservableValue<Task> task, int columnIndex) { private void proof(Task task, int columnIndex) {
ModalDialogs.doModal(new TaskComputationWindow(root, task.getValue().getComputations().get(columnIndex - 1)), ModalDialogs.doModal(new TaskComputationWindow(root, task.getComputations()
WindowConstants.DISPOSE_ON_CLOSE); .get(columnIndex - 1)), WindowConstants.DISPOSE_ON_CLOSE);
} }
private synchronized void fillTable() { private synchronized void fillTable() {
if (closed) { if (closed) {
return; return;
} }
final List<Task> processedTasks = observedValue;
final Optional<List<TaskComputation>> optional = processedTasks.stream() final Optional<List<TaskComputation>> optional = observedValue.stream().map(
.map(task -> task.getComputations()).collect(Collectors task -> task.getComputations()).collect(Collectors
.<List<TaskComputation>> maxBy((a, b) -> a.size() - b.size())); .<List<TaskComputation>> maxBy((a, b) -> a.size() - b.size()));
if (!optional.isPresent()) { if (!optional.isPresent()) {
return; return;
} }
final List<TaskComputation> computations = optional.get(); final List<TaskComputation> computations = optional.get();
final List<ObservableValue<Task>> taskList = (processedTasks.stream().map(
task -> new SimpleObservableValue<>(task)).collect(Collectors.toList()));
executorFx.execute(() -> { executorFx.execute(() -> {
int i = 0; int i = 0;
JavaFXRoutines.setCellValueFactory(this.tasks, i++, JavaFXRoutines.setCellValueFactoryForList(this.tasks, i++,
(Function<Task, String>) v -> Constants.BENCHMARK_TASK_NAME_MAP.get(v f -> new SimpleObservableValue<>(Constants.BENCHMARK_TASK_NAME_MAP.get(f
.getDescription())); .getValue().getDescription())));
double tableColumnWidth = computeTableColumnWidth(computations); double tableColumnWidth = computeTableColumnWidth(computations);
for (TaskComputation tc : computations) { for (TaskComputation tc : computations) {
TableColumn<ObservableValue<Task>, String> tableCol; TableColumn<Task, String> tableCol;
this.tasks.getColumns().add(tableCol = new TableColumn<>(columnHeader( this.tasks.getColumns().add(tableCol = new TableColumn<>(columnHeader(
tc))); tc)));
int index = i++; int index = i++;
tableCol.setPrefWidth(tableColumnWidth); tableCol.setPrefWidth(tableColumnWidth);
constructCellFactory(index); constructCellFactory(index);
} }
this.tasks.getItems().addAll(taskList); this.tasks.setItems(observedValue);
}); });
} }
...@@ -204,13 +200,14 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl ...@@ -204,13 +200,14 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void constructCellFactory(int index) { private void constructCellFactory(int index) {
JavaFXRoutines.setCellValueFactory(this.tasks, index, (Function<Task, TaskComputation>) v -> { JavaFXRoutines.setCellValueFactoryForList(this.tasks, index, f -> {
if (v.getComputations().size() >= index) { if (f.getValue().getComputations().size() >= index) {
return v.getComputations().get(index - 1); return new SimpleObservableValue<>(f.getValue().getComputations().get(
} index - 1));
}
return null; return null;
}); });
((TableColumn<ObservableValue<Task>, TaskComputation>) this.tasks.getColumns().get(index)) ((TableColumn<Task, TaskComputation>) this.tasks.getColumns().get(index))
.setCellFactory(column -> new TableCellAdapter<>((cell, val, empty) -> { .setCellFactory(column -> new TableCellAdapter<>((cell, val, empty) -> {
if (val == null || empty) { if (val == null || empty) {
cell.setText(EMPTY_VALUE); cell.setText(EMPTY_VALUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment