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

decorator for TableCell

parent ffe45c1e
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package cz.it4i.fiji.haas.ui;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
......@@ -9,13 +10,48 @@ import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas.ui.JavaFXRoutines.TableCellAdapter.TableCellUpdater;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
public interface JavaFXRoutines {
static public class TableCellAdapter<S, T> extends TableCell<S, T> {
public interface TableCellUpdater<A, B> {
void accept(TableCell<?, ?> cell, B value, boolean empty);
}
private TableCellUpdater<S, T> updater;
public TableCellAdapter(TableCellUpdater<S, T> updater) {
this.updater = updater;
}
@Override
protected void updateItem(T item, boolean empty) {
updater.accept(this, item, empty);
}
}
static public class FutureValueUpdater<S, T, U extends CompletableFuture<T>> implements TableCellUpdater<S, U> {
private TableCellUpdater<S, T> inner;
public FutureValueUpdater(TableCellUpdater<S, T> inner) {
this.inner = inner;
}
@Override
public void accept(TableCell<?, ?> cell, U value, boolean empty) {
value.thenAccept(val->inner.accept(cell, val, empty));
}
}
static void initRootAndController(String string, Object parent) {
initRootAndController(string, parent, false);
......
......@@ -4,7 +4,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas.ui.CloseableControl;
import cz.it4i.fiji.haas.ui.FXFrameNative;
import cz.it4i.fiji.haas.ui.JavaFXRoutines;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
......
......@@ -22,13 +22,12 @@ 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.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{
public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl {
private static final String EMPTY_VALUE = "\u2007\u2007\u2007";
......@@ -75,9 +74,9 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
public SPIMPipelineProgressViewController() {
executorServiceWS = Executors.newSingleThreadExecutor();
init();
}
public SPIMPipelineProgressViewController(BenchmarkJob job) {
executorServiceWS = Executors.newSingleThreadExecutor();
init();
......@@ -85,7 +84,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
}
public void setJob(BenchmarkJob job) {
if(this.job != null) {
if (this.job != null) {
throw new IllegalStateException("Job already set");
}
this.job = job;
......@@ -93,7 +92,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
fillTable();
});
}
public void close() {
timer.cancel();
executorServiceWS.shutdown();
......@@ -104,7 +103,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
tasks.setPrefWidth(PREFERRED_WIDTH);
timer = new Timer();
registry = new ObservableTaskRegistry(task -> tasks.getItems().remove(registry.get(task)));
}
private void fillTable() {
......@@ -157,18 +156,15 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
}
});
((TableColumn<ObservableValue<Task>, TaskComputation>) this.tasks.getColumns().get(index))
.setCellFactory(column -> new TableCell<ObservableValue<Task>, TaskComputation>() {
@Override
protected void updateItem(TaskComputation computation, boolean empty) {
if (computation == null || empty) {
setText(EMPTY_VALUE);
setStyle("");
} else {
setText(EMPTY_VALUE);
setStyle("-fx-background-color: " + getColorTaskExecState(computation.getState()));
}
.setCellFactory(column -> new JavaFXRoutines.TableCellAdapter<>((cell, val, empty) -> {
if (val == null || empty) {
cell.setText(EMPTY_VALUE);
cell.setStyle("");
} else {
cell.setText(EMPTY_VALUE);
cell.setStyle("-fx-background-color: " + getColorTaskExecState(val.getState()));
}
});
}));
}
private void updateTable() {
......@@ -176,6 +172,6 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
}
private void fixNotVisibleColumn() {
//this.tasks.getColumns().add(new TableColumn<>(" "));
// this.tasks.getColumns().add(new TableColumn<>(" "));
}
}
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