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

refactor: change name ObservableBenchmarkJob

parent 0675d0da
Branches
Tags
No related merge requests found
...@@ -12,10 +12,10 @@ import cz.it4i.fiji.haas.ui.UpdatableObservableValue; ...@@ -12,10 +12,10 @@ import cz.it4i.fiji.haas.ui.UpdatableObservableValue;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob;
import net.imagej.updater.util.Progress; import net.imagej.updater.util.Progress;
public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob> { public class ObservableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob> {
public static final Logger log = LoggerFactory public static final Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.class); .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.ObservableBenchmarkJob.class);
private P_TransferProgress downloadProgress = new P_TransferProgress(val -> getValue().setDownloaded(val), private P_TransferProgress downloadProgress = new P_TransferProgress(val -> getValue().setDownloaded(val),
() -> getValue().isDownloaded(), () -> getValue().needsDownload()); () -> getValue().isDownloaded(), () -> getValue().needsDownload());
...@@ -34,7 +34,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -34,7 +34,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
public Float getRemainingPercents(); public Float getRemainingPercents();
} }
public UpdatableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction, public ObservableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction,
Function<BenchmarkJob, Object> stateProvider, Executor executorUI) { Function<BenchmarkJob, Object> stateProvider, Executor executorUI) {
super(wrapped, updateFunction, stateProvider); super(wrapped, updateFunction, stateProvider);
this.executor = executorUI; this.executor = executorUI;
......
...@@ -34,8 +34,8 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager; ...@@ -34,8 +34,8 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants; import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService; import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService;
import cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.ObservableBenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.TransferProgress; import cz.it4i.fiji.haas_spim_benchmark.core.ObservableBenchmarkJob.TransferProgress;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
...@@ -47,7 +47,7 @@ import net.imagej.updater.util.Progress; ...@@ -47,7 +47,7 @@ import net.imagej.updater.util.Progress;
public class BenchmarkSPIMController extends BorderPane implements CloseableControl, InitiableControl { public class BenchmarkSPIMController extends BorderPane implements CloseableControl, InitiableControl {
@FXML @FXML
private TableView<UpdatableBenchmarkJob> jobs; private TableView<ObservableBenchmarkJob> jobs;
private BenchmarkJobManager manager; private BenchmarkJobManager manager;
...@@ -99,17 +99,17 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont ...@@ -99,17 +99,17 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
} }
private void initMenu() { private void initMenu() {
TableViewContextMenu<UpdatableBenchmarkJob> menu = new TableViewContextMenu<>(jobs); TableViewContextMenu<ObservableBenchmarkJob> menu = new TableViewContextMenu<>(jobs);
menu.addItem("Create job", x -> executeWSCallAsync("Creating job", p -> manager.createJob()), j -> true); menu.addItem("Create job", x -> executeWSCallAsync("Creating job", p -> manager.createJob()), j -> true);
menu.addItem("Start job", job -> executeWSCallAsync("Starting job", p -> { menu.addItem("Start job", job -> executeWSCallAsync("Starting job", p -> {
job.getValue().startJob(p); job.getValue().startJob(p);
registry.get(job.getValue()).update(); job.getValue().update();
}), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Configuring }), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Configuring
|| j.getState() == JobState.Finished || j.getState() == JobState.Failed)); || j.getState() == JobState.Finished || j.getState() == JobState.Failed));
menu.addItem("Cancel job", job -> executeWSCallAsync("Canceling job", p -> { menu.addItem("Cancel job", job -> executeWSCallAsync("Canceling job", p -> {
job.getValue().cancelJob(); job.getValue().cancelJob();
registry.get(job.getValue()).update(); job.getValue().update();
}), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Running)); }), job -> JavaFXRoutines.notNullValue(job, j -> j.getState() == JobState.Running));
menu.addItem("Execution details", job -> { menu.addItem("Execution details", job -> {
...@@ -194,13 +194,14 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont ...@@ -194,13 +194,14 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
try { try {
List<BenchmarkJob> jobs = new LinkedList<>(manager.getJobs()); List<BenchmarkJob> jobs = new LinkedList<>(manager.getJobs());
jobs.sort((bj1, bj2) -> (int) (bj1.getId() - bj2.getId())); jobs.sort((bj1, bj2) -> (int) (bj1.getId() - bj2.getId()));
Set<ObservableValue<BenchmarkJob>> actual = new HashSet<>(this.jobs.getItems());
for (BenchmarkJob bj : jobs) { for (BenchmarkJob bj : jobs) {
registry.addIfAbsent(bj); registry.addIfAbsent(bj);
} }
registry.update(); registry.update();
Set<ObservableValue<BenchmarkJob>> actual = new HashSet<>(this.jobs.getItems());
executorServiceFX.execute(() -> { executorServiceFX.execute(() -> {
for (UpdatableBenchmarkJob value : registry.getAllItems()) { for (ObservableBenchmarkJob value : registry.getAllItems()) {
if (!actual.contains(value)) { if (!actual.contains(value)) {
this.jobs.getItems().add(value); this.jobs.getItems().add(value);
} }
...@@ -249,11 +250,11 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont ...@@ -249,11 +250,11 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void setCellValueFactoryCompletable(int index, Function<BenchmarkJob, CompletableFuture<String>> mapper) { private void setCellValueFactoryCompletable(int index, Function<BenchmarkJob, CompletableFuture<String>> mapper) {
JavaFXRoutines.setCellValueFactory(jobs, index, mapper); JavaFXRoutines.setCellValueFactory(jobs, index, mapper);
((TableColumn<UpdatableBenchmarkJob, CompletableFuture<String>>) jobs.getColumns().get(index)) ((TableColumn<ObservableBenchmarkJob, CompletableFuture<String>>) jobs.getColumns().get(index))
.setCellFactory( .setCellFactory(
column -> new JavaFXRoutines.TableCellAdapter<UpdatableBenchmarkJob, CompletableFuture<String>>( column -> new JavaFXRoutines.TableCellAdapter<ObservableBenchmarkJob, CompletableFuture<String>>(
new JavaFXRoutines.FutureValueUpdater<UpdatableBenchmarkJob, String, CompletableFuture<String>>( new JavaFXRoutines.FutureValueUpdater<ObservableBenchmarkJob, String, CompletableFuture<String>>(
new JavaFXRoutines.StringValueUpdater<UpdatableBenchmarkJob>(), new JavaFXRoutines.StringValueUpdater<ObservableBenchmarkJob>(),
executorServiceFX))); executorServiceFX)));
} }
......
...@@ -12,10 +12,10 @@ import cz.it4i.fiji.haas.ui.ObservableValueRegistry; ...@@ -12,10 +12,10 @@ import cz.it4i.fiji.haas.ui.ObservableValueRegistry;
import cz.it4i.fiji.haas.ui.UpdatableObservableValue.UpdateStatus; import cz.it4i.fiji.haas.ui.UpdatableObservableValue.UpdateStatus;
import cz.it4i.fiji.haas_java_client.JobState; 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.BenchmarkJobManager.BenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.ObservableBenchmarkJob;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<BenchmarkJob,UpdatableBenchmarkJob> { public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<BenchmarkJob,ObservableBenchmarkJob> {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Logger log = LoggerFactory private static Logger log = LoggerFactory
...@@ -30,26 +30,26 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc ...@@ -30,26 +30,26 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc
} }
@Override @Override
public UpdatableBenchmarkJob addIfAbsent(BenchmarkJob value) { public ObservableBenchmarkJob addIfAbsent(BenchmarkJob value) {
return (UpdatableBenchmarkJob) super.addIfAbsent(value); return (ObservableBenchmarkJob) super.addIfAbsent(value);
} }
@Override @Override
public UpdatableBenchmarkJob get(BenchmarkJob value) { public ObservableBenchmarkJob get(BenchmarkJob value) {
return (UpdatableBenchmarkJob) super.get(value); return (ObservableBenchmarkJob) super.get(value);
} }
@Override @Override
protected ObservableValue<BenchmarkJob> remove(BenchmarkJob value) { protected ObservableValue<BenchmarkJob> remove(BenchmarkJob value) {
UpdatableBenchmarkJob result = (UpdatableBenchmarkJob) super.remove(value); ObservableBenchmarkJob result = (ObservableBenchmarkJob) super.remove(value);
result.removed(); result.removed();
return result; return result;
} }
@Override @Override
protected UpdatableBenchmarkJob constructObservableValue(BenchmarkJob v, protected ObservableBenchmarkJob constructObservableValue(BenchmarkJob v,
Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider) { Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider) {
return new UpdatableBenchmarkJob(v, updateFunction, stateProvider, executorUI); return new ObservableBenchmarkJob(v, updateFunction, stateProvider, executorUI);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment