Commit 37f883db authored by Petr Bainar's avatar Petr Bainar

miscStuffAgain: use SimpleObservableList also for FileTransferInfo

parent af8e752c
......@@ -2,8 +2,6 @@
package cz.it4i.fiji.haas_spim_benchmark.core;
import java.io.Closeable;
import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Function;
......@@ -15,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas.ui.UpdatableObservableValue;
import cz.it4i.fiji.haas_java_client.FileTransferInfo;
import cz.it4i.fiji.haas_java_client.SynchronizableFileType;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob;
......@@ -33,12 +32,12 @@ public class ObservableBenchmarkJob extends
() -> getValue().needsUpload());
private final Executor executor;
private final P_Observable fileTransferObservable = new P_Observable();
private final HaasOutputObservableValueRegistry haasOutputRegistry;
private final TaskObservableValueRegistry taskRegistry;
private final SimpleObservableList<FileTransferInfo> fileTransferList;
public interface TransferProgress {
public Long getRemainingMiliseconds();
......@@ -62,6 +61,8 @@ public class ObservableBenchmarkJob extends
haasOutputRegistry = new HaasOutputObservableValueRegistry(getValue());
taskRegistry = new TaskObservableValueRegistry(getValue());
fileTransferList = new SimpleObservableList<>(wrapped
.getFileTransferInfo());
}
public TransferProgress getDownloadProgress() {
......@@ -77,12 +78,8 @@ public class ObservableBenchmarkJob extends
getValue().setUploadNotifier(null);
}
public void startObservingFileTransfer(final Observer observer) {
fileTransferObservable.addObserver(observer);
}
public void stopObservingFileTransfer(final Observer observer) {
fileTransferObservable.deleteObserver(observer);
public SimpleObservableList<FileTransferInfo> getFileTransferList() {
return fileTransferList;
}
public SimpleObservableValue<String> getObservableSnakemakeOutput(
......@@ -108,21 +105,8 @@ public class ObservableBenchmarkJob extends
});
}
private void notifyFileTransferObservers() {
fileTransferObservable.setChanged();
fileTransferObservable.notifyObservers();
}
// -- Private classes --
private class P_Observable extends Observable {
@Override
public synchronized void setChanged() {
super.setChanged();
}
}
private class P_TransferProgress implements Progress, TransferProgress {
private final Supplier<Boolean> doneStatusSupplier;
......@@ -192,7 +176,7 @@ public class ObservableBenchmarkJob extends
@Override
public void itemDone(final Object item) {
notifyFileTransferObservers();
fileTransferList.setAll(getValue().getFileTransferInfo());
}
@Override
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -15,6 +10,7 @@ import cz.it4i.fiji.haas.ui.TableCellAdapter;
import cz.it4i.fiji.haas_java_client.FileTransferInfo;
import cz.it4i.fiji.haas_java_client.FileTransferState;
import cz.it4i.fiji.haas_spim_benchmark.core.ObservableBenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableList;
import cz.it4i.fiji.haas_spim_benchmark.core.SimpleObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
......@@ -34,82 +30,59 @@ public class DataTransferController extends BorderPane implements
cz.it4i.fiji.haas_spim_benchmark.ui.DataTransferController.class);
@FXML
private TableView<SimpleObservableValue<FileTransferInfo>> files;
private ObservableBenchmarkJob job;
private final Observer observer = new Observer() {
@Override
public void update(Observable o, Object arg) {
files.getItems().clear();
final List<SimpleObservableValue<FileTransferInfo>> tempList =
new LinkedList<>();
job.getValue().getFileTransferInfo().forEach(i -> {
tempList.add(new SimpleObservableValue<>(i));
});
files.getItems().addAll(tempList);
}
};
private TableView<FileTransferInfo> files;
public DataTransferController() {
JavaFXRoutines.initRootAndController(FXML_FILE_NAME, this);
initTable();
}
@SuppressWarnings("unchecked")
public void setJob(final ObservableBenchmarkJob job) {
this.job = job;
this.job.startObservingFileTransfer(observer);
observer.update(null, null); // Needs to be done in order to retrieve finished files
SimpleObservableList<FileTransferInfo> fileTransferList = job
.getFileTransferList();
if (fileTransferList != null && fileTransferList.size() != 0) {
final int columnIndexPath = 0;
final int columnIndexState = 1;
JavaFXRoutines.setCellValueFactoryForList(files, columnIndexPath,
f -> new SimpleObservableValue<>(f.getValue().getFileNameAsString()));
JavaFXRoutines.setCellValueFactoryForList(files, columnIndexState,
f -> new SimpleObservableValue<>(f.getValue().getState()));
final TableColumn<FileTransferInfo, FileTransferState> stateColumn =
(TableColumn<FileTransferInfo, FileTransferState>) files.getColumns()
.get(columnIndexState);
stateColumn.setCellFactory(column -> new TableCellAdapter<>((cell, val,
empty) -> {
if (val == null || empty) {
return;
}
final TableRow<FileTransferInfo> currentRow = cell.getTableRow();
cell.setText(val.toString());
if (val.equals(FileTransferState.Finished)) {
currentRow.setStyle("-fx-text-background-color: " + JavaFXRoutines
.toCss(Color.rgb(0x41, 0xB2, 0x80)));
}
else {
currentRow.setStyle("-fx-text-background-color: " + JavaFXRoutines
.toCss(Color.rgb(0x30, 0xA2, 0xCC)));
}
}));
files.setItems(fileTransferList);
}
}
// -- CloseableControl methods --
@Override
public void close() {
job.stopObservingFileTransfer(observer);
}
// -- Helper methods --
@SuppressWarnings("unchecked")
private void initTable() {
final int columnIndexPath = 0;
final int columnIndexState = 1;
JavaFXRoutines.setCellValueFactory(files, columnIndexPath, f -> f
.getFileNameAsString());
JavaFXRoutines.setCellValueFactory(files, columnIndexState, f -> f
.getState());
final TableColumn<SimpleObservableValue<FileTransferInfo>, FileTransferState> stateColumn =
(TableColumn<SimpleObservableValue<FileTransferInfo>, FileTransferState>) files
.getColumns().get(columnIndexState);
stateColumn.setCellFactory(column -> new TableCellAdapter<>((cell, val,
empty) -> {
if (val == null || empty) {
return;
}
final TableRow<SimpleObservableValue<FileTransferInfo>> currentRow = cell
.getTableRow();
cell.setText(val.toString());
if (val.equals(FileTransferState.Finished)) {
currentRow.setStyle("-fx-text-background-color: " + JavaFXRoutines
.toCss(Color.rgb(0x41, 0xB2, 0x80)));
}
else {
currentRow.setStyle("-fx-text-background-color: " + JavaFXRoutines
.toCss(Color.rgb(0x30, 0xA2, 0xCC)));
}
}));
// Do nothing
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment