forked from j62/ctbrec
1
0
Fork 0

Add tab to show the recorded models per site

Does more or less the same as RecordedModelsTab, but removes some buttons and adds a default filter of site.getName()
This commit is contained in:
0xb00bface 2021-12-04 15:12:55 +01:00
parent cad97492e4
commit 2e122fbfd1
2 changed files with 94 additions and 47 deletions

View File

@ -0,0 +1,60 @@
package ctbrec.ui.tabs.recorded;
import ctbrec.Model;
import ctbrec.recorder.Recorder;
import ctbrec.sites.Site;
import ctbrec.ui.action.PauseAction;
import ctbrec.ui.action.ResumeAction;
import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.tabs.TabSelectionListener;
import javafx.event.ActionEvent;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class RecordedModelsPerSiteTab extends RecordedModelsTab implements TabSelectionListener {
public RecordedModelsPerSiteTab(String title, Recorder recorder, Site site) {
super(title, recorder, List.of(site));
filter(site.getName());
}
@Override
protected void createGui() {
super.createGui();
addModelBox.getChildren().remove(toggleRecording);
addModelBox.getChildren().remove(checkModelAccountExistance);
restoreState();
}
@Override
protected void filter(String filter) {
super.filter(filter + " " + sites.get(0).getName());
}
@Override
protected void pauseAll(ActionEvent evt) {
boolean yes = Dialogs.showConfirmDialog("Pause all models", "", "Pause the recording of all models in this table?", getTabPane().getScene());
if (yes) {
List<Model> models = recorder.getModels().stream()
.filter(Predicate.not(Model::isMarkedForLaterRecording))
.filter(m -> Objects.equals(m.getSite(), sites.get(0)))
.collect(Collectors.toList());
new PauseAction(getTabPane(), models, recorder).execute();
}
}
@Override
protected void resumeAll(ActionEvent evt) {
boolean yes = Dialogs.showConfirmDialog("Resume all models", "", "Pause the recording of all models in this table?", getTabPane().getScene());
if (yes) {
List<Model> models = recorder.getModels().stream()
.filter(Predicate.not(Model::isMarkedForLaterRecording))
.filter(m -> Objects.equals(m.getSite(), sites.get(0)))
.collect(Collectors.toList());
new ResumeAction(getTabPane(), models, recorder).execute();
}
}
}

View File

@ -1,25 +1,5 @@
package ctbrec.ui.tabs.recorded; package ctbrec.ui.tabs.recorded;
import static ctbrec.Recording.State.*;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.Recording; import ctbrec.Recording;
@ -27,11 +7,7 @@ import ctbrec.recorder.Recorder;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import ctbrec.ui.JavaFxModel; import ctbrec.ui.JavaFxModel;
import ctbrec.ui.action.AbstractModelAction.Result; import ctbrec.ui.action.AbstractModelAction.Result;
import ctbrec.ui.action.CheckModelAccountAction; import ctbrec.ui.action.*;
import ctbrec.ui.action.PauseAction;
import ctbrec.ui.action.ResumeAction;
import ctbrec.ui.action.StopRecordingAction;
import ctbrec.ui.action.ToggleRecordingAction;
import ctbrec.ui.controls.DateTimeCellFactory; import ctbrec.ui.controls.DateTimeCellFactory;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.tabs.TabSelectionListener; import ctbrec.ui.tabs.TabSelectionListener;
@ -53,8 +29,25 @@ import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.Duration; import javafx.util.Duration;
import javafx.util.StringConverter;
import javafx.util.converter.NumberStringConverter; import javafx.util.converter.NumberStringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static ctbrec.Recording.State.RECORDING;
public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabSelectionListener { public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabSelectionListener {
private static final Logger LOG = LoggerFactory.getLogger(RecordedModelsTab.class); private static final Logger LOG = LoggerFactory.getLogger(RecordedModelsTab.class);
@ -65,6 +58,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
Button pauseAll = new Button("Pause All"); Button pauseAll = new Button("Pause All");
Button resumeAll = new Button("Resume All"); Button resumeAll = new Button("Resume All");
ToggleButton toggleRecording = new ToggleButton("Pause Recording"); ToggleButton toggleRecording = new ToggleButton("Pause Recording");
protected BorderPane root = new BorderPane();
public RecordedModelsTab(String title, Recorder recorder, List<Site> sites) { public RecordedModelsTab(String title, Recorder recorder, List<Site> sites) {
super(title, "recordedModelsTable"); super(title, "recordedModelsTable");
@ -167,7 +161,6 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
checkModelAccountExistance checkModelAccountExistance
.setOnAction(evt -> new CheckModelAccountAction(checkModelAccountExistance, recorder).execute(Predicate.not(Model::isMarkedForLaterRecording))); .setOnAction(evt -> new CheckModelAccountAction(checkModelAccountExistance, recorder).execute(Predicate.not(Model::isMarkedForLaterRecording)));
var root = new BorderPane();
root.setPadding(new Insets(5)); root.setPadding(new Insets(5));
root.setTop(addModelBox); root.setTop(addModelBox);
root.setCenter(scrollPane); root.setCenter(scrollPane);
@ -201,7 +194,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
} }
} }
private void pauseAll(ActionEvent evt) { protected void pauseAll(ActionEvent evt) {
boolean yes = Dialogs.showConfirmDialog("Pause all models", "", "Pause the recording of all models?", getTabPane().getScene()); boolean yes = Dialogs.showConfirmDialog("Pause all models", "", "Pause the recording of all models?", getTabPane().getScene());
if (yes) { if (yes) {
List<Model> models = recorder.getModels().stream().filter(Predicate.not(Model::isMarkedForLaterRecording)).collect(Collectors.toList()); List<Model> models = recorder.getModels().stream().filter(Predicate.not(Model::isMarkedForLaterRecording)).collect(Collectors.toList());
@ -209,7 +202,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
} }
} }
private void resumeAll(ActionEvent evt) { protected void resumeAll(ActionEvent evt) {
boolean yes = Dialogs.showConfirmDialog("Resume all models", "", "Resume the recording of all models?", getTabPane().getScene()); boolean yes = Dialogs.showConfirmDialog("Resume all models", "", "Resume the recording of all models?", getTabPane().getScene());
if (yes) { if (yes) {
List<Model> models = recorder.getModels().stream().filter(Predicate.not(Model::isMarkedForLaterRecording)).collect(Collectors.toList()); List<Model> models = recorder.getModels().stream().filter(Predicate.not(Model::isMarkedForLaterRecording)).collect(Collectors.toList());
@ -243,12 +236,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
addOrUpdateModels(updatedModels); addOrUpdateModels(updatedModels);
// remove old ones, which are not in the list of updated models // remove old ones, which are not in the list of updated models
for (Iterator<JavaFxModel> iterator = observableModels.iterator(); iterator.hasNext();) { observableModels.removeIf(Predicate.not(updatedModels::contains));
Model oldModel = iterator.next();
if (!updatedModels.contains(oldModel)) {
iterator.remove();
}
}
} finally { } finally {
lock.unlock(); lock.unlock();
} }
@ -281,7 +269,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
private ChangeListener<Boolean> createPauseListener(JavaFxModel updatedModel) { private ChangeListener<Boolean> createPauseListener(JavaFxModel updatedModel) {
return (obs, oldV, newV) -> { return (obs, oldV, newV) -> {
if (newV.booleanValue()) { if (Boolean.TRUE.equals(newV)) {
if (!recorder.isSuspended(updatedModel)) { if (!recorder.isSuspended(updatedModel)) {
pauseRecording(Collections.singletonList(updatedModel)); pauseRecording(Collections.singletonList(updatedModel));
} }
@ -294,10 +282,10 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
} }
private ScheduledService<List<JavaFxModel>> createUpdateService() { private ScheduledService<List<JavaFxModel>> createUpdateService() {
ScheduledService<List<JavaFxModel>> modelUpdateService = new ScheduledService<List<JavaFxModel>>() { ScheduledService<List<JavaFxModel>> modelUpdateService = new ScheduledService<>() {
@Override @Override
protected Task<List<JavaFxModel>> createTask() { protected Task<List<JavaFxModel>> createTask() {
return new Task<List<JavaFxModel>>() { return new Task<>() {
@Override @Override
public List<JavaFxModel> call() throws InvalidKeyException, NoSuchAlgorithmException, IOException { public List<JavaFxModel> call() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
LOG.trace("Updating recorded models"); LOG.trace("Updating recorded models");
@ -358,12 +346,12 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
} }
if (confirmed) { if (confirmed) {
List<Model> models = selectedModels.stream().map(JavaFxModel::getDelegate).collect(Collectors.toList()); List<Model> models = selectedModels.stream().map(JavaFxModel::getDelegate).collect(Collectors.toList());
new StopRecordingAction(getTabPane(), models, recorder).execute().whenComplete((r, ex) -> { new StopRecordingAction(getTabPane(), models, recorder).execute().whenComplete((r, ex) ->
r.stream().map(Result::getModel).forEach(m -> Platform.runLater(() -> { r.stream().map(Result::getModel).forEach(m -> Platform.runLater(() -> {
table.getSelectionModel().clearSelection(table.getItems().indexOf(m)); table.getSelectionModel().clearSelection(table.getItems().indexOf(m));
table.getItems().remove(m); table.getItems().remove(m);
})); }))
}); );
portraitCache.invalidateAll(models); portraitCache.invalidateAll(models);
} }
} }
@ -381,8 +369,7 @@ public class RecordedModelsTab extends AbstractRecordedModelsTab implements TabS
private class PriorityCellFactory implements Callback<TableColumn<JavaFxModel, Number>, TableCell<JavaFxModel, Number>> { private class PriorityCellFactory implements Callback<TableColumn<JavaFxModel, Number>, TableCell<JavaFxModel, Number>> {
@Override @Override
public TableCell<JavaFxModel, Number> call(TableColumn<JavaFxModel, Number> param) { public TableCell<JavaFxModel, Number> call(TableColumn<JavaFxModel, Number> param) {
Callback<TableColumn<JavaFxModel, Number>, TableCell<JavaFxModel, Number>> callback = TextFieldTableCell Callback<TableColumn<JavaFxModel, Number>, TableCell<JavaFxModel, Number>> callback = TextFieldTableCell.forTableColumn(new NumberStringConverter());
.<JavaFxModel, Number> forTableColumn((StringConverter<Number>) new NumberStringConverter());
TableCell<JavaFxModel, Number> tableCell = callback.call(param); TableCell<JavaFxModel, Number> tableCell = callback.call(param);
tableCell.setOnScroll(event -> { tableCell.setOnScroll(event -> {