Add online state column. Fix capitalization

This commit is contained in:
reusedname 2025-02-24 22:22:34 +05:00
parent 3b545d12b2
commit 4419a8d723
4 changed files with 45 additions and 18 deletions

View File

@ -31,6 +31,7 @@ public class JavaFxModel implements Model {
private final transient SimpleIntegerProperty priorityProperty = new SimpleIntegerProperty();
private final transient SimpleObjectProperty<Instant> lastSeenProperty = new SimpleObjectProperty<>();
private final transient SimpleObjectProperty<Instant> lastRecordedProperty = new SimpleObjectProperty<>();
private final transient SimpleObjectProperty<State> onlineStateProperty = new SimpleObjectProperty<>();
private final Model delegate;
@ -39,6 +40,21 @@ public class JavaFxModel implements Model {
setPriority(delegate.getPriority());
setLastSeen(delegate.getLastSeen());
setLastRecorded(delegate.getLastRecorded());
try { // TODO: split online state updates and reading from cache, so that we don't need try-catch
onlineStateProperty.setValue(delegate.getOnlineState(true));
} catch (Exception e) {}
}
public void updateFrom(JavaFxModel other) {
this.setSuspended(other.isSuspended());
this.setForcePriority(other.isForcePriority());
this.getOnlineProperty().set(other.getOnlineProperty().get());
this.getRecordingProperty().set(other.getRecordingProperty().get());
this.lastRecordedProperty().set(other.lastRecordedProperty().get());
this.lastSeenProperty().set(other.lastSeenProperty().get());
this.setRecordUntil(other.getRecordUntil());
this.setRecordUntilSubsequentAction(other.getRecordUntilSubsequentAction());
this.onlineStateProperty().set(other.onlineStateProperty().get());
}
@Override
@ -142,6 +158,10 @@ public class JavaFxModel implements Model {
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
return delegate.isOnline(ignoreCache);
}
public void setOnlineStateProperty(State state) throws IOException, ExecutionException {
onlineStateProperty.set(state);
}
@Override
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
@ -294,6 +314,10 @@ public class JavaFxModel implements Model {
return lastRecordedProperty;
}
public SimpleObjectProperty<State> onlineStateProperty() {
return onlineStateProperty;
}
@Override
public void setLastRecorded(Instant timestamp) {
delegate.setLastRecorded(timestamp);

View File

@ -327,7 +327,7 @@ public abstract class AbstractRecordedModelsTab extends Tab implements TabSelect
}
protected void addAddedTimestampColumn(int columnIdx) {
TableColumn<JavaFxModel, Instant> tc = addTableColumn("addedTimestamp", "added at", columnIdx, 400);
TableColumn<JavaFxModel, Instant> tc = addTableColumn("addedTimestamp", "Added at", columnIdx, 400);
tc.setCellFactory(new DateTimeCellFactory<>(config.getDateTimeFormatter()));
tc.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAddedTimestamp()));
tc.setPrefWidth(150);

View File

@ -106,11 +106,7 @@ public class RecordLaterTab extends AbstractRecordedModelsTab implements TabSele
} else {
// make sure to update the JavaFX online property, so that the table cell is updated
JavaFxModel oldModel = observableModels.get(index);
oldModel.setSuspended(updatedModel.isSuspended());
oldModel.getOnlineProperty().set(updatedModel.getOnlineProperty().get());
oldModel.getRecordingProperty().set(updatedModel.getRecordingProperty().get());
oldModel.lastRecordedProperty().set(updatedModel.lastRecordedProperty().get());
oldModel.lastSeenProperty().set(updatedModel.lastSeenProperty().get());
oldModel.updateFrom(updatedModel);
}
}
}

View File

@ -121,7 +121,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
priority.setUserData(idx++);
columns.add(priority);
table.getColumns().add(priority);
TableColumn<JavaFxModel, Instant> lastSeen = new TableColumn<>("last seen");
TableColumn<JavaFxModel, Instant> lastSeen = new TableColumn<>("Last seen");
lastSeen.setCellValueFactory(cdf -> cdf.getValue().lastSeenProperty());
lastSeen.setCellFactory(new DateTimeCellFactory<>(config.getDateTimeFormatter()));
lastSeen.setPrefWidth(150);
@ -131,7 +131,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
lastSeen.setStyle(STYLE_ALIGN_CENTER);
columns.add(lastSeen);
table.getColumns().add(lastSeen);
TableColumn<JavaFxModel, Instant> lastRecorded = new TableColumn<>("last recorded");
TableColumn<JavaFxModel, Instant> lastRecorded = new TableColumn<>("Last recorded");
lastRecorded.setCellValueFactory(cdf -> cdf.getValue().lastRecordedProperty());
lastRecorded.setCellFactory(new DateTimeCellFactory<>(config.getDateTimeFormatter()));
lastRecorded.setPrefWidth(150);
@ -140,8 +140,19 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
lastRecorded.setUserData(idx++);
lastRecorded.setStyle(STYLE_ALIGN_CENTER);
columns.add(lastRecorded);
table.getColumns().add(lastRecorded);
table.getColumns().add(lastRecorded);
TableColumn<JavaFxModel, Model.State> onlineState = new TableColumn<>("State");
onlineState.setCellValueFactory(cdf -> cdf.getValue().onlineStateProperty());
onlineState.setCellFactory(new ClickableCellFactory<>());
onlineState.setPrefWidth(150);
onlineState.setEditable(false);
onlineState.setId("onlineState");
onlineState.setUserData(idx++);
onlineState.setStyle(STYLE_ALIGN_CENTER);
onlineState.setVisible(false);
columns.add(onlineState);
table.getColumns().add(onlineState);
addAddedTimestampColumn(idx++);
addNotesColumn(idx);
@ -261,14 +272,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
} else {
// make sure to update the JavaFX online property, so that the table cell is updated
JavaFxModel oldModel = observableModels.get(index);
oldModel.setSuspended(updatedModel.isSuspended());
oldModel.setForcePriority(updatedModel.isForcePriority());
oldModel.getOnlineProperty().set(updatedModel.getOnlineProperty().get());
oldModel.getRecordingProperty().set(updatedModel.getRecordingProperty().get());
oldModel.lastRecordedProperty().set(updatedModel.lastRecordedProperty().get());
oldModel.lastSeenProperty().set(updatedModel.lastSeenProperty().get());
oldModel.setRecordUntil(updatedModel.getRecordUntil());
oldModel.setRecordUntilSubsequentAction(updatedModel.getRecordUntilSubsequentAction());
oldModel.updateFrom(updatedModel);
}
}
}
@ -322,6 +326,9 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
for (Model onlineModel : onlineModels) {
if (Objects.equals(onlineModel, fxm)) {
fxm.setOnlineProperty(true);
try {
fxm.setOnlineStateProperty(onlineModel.getOnlineState(true));
} catch (Exception e) {}
break;
}
}