Implement CheckURL dialog from WinkRU
This commit is contained in:
parent
ae6f36ffda
commit
38e1d146ba
|
@ -1,15 +1,15 @@
|
||||||
package ctbrec.ui.action;
|
package ctbrec.ui.action;
|
||||||
|
|
||||||
|
import ctbrec.GlobalThreadPool;
|
||||||
|
import ctbrec.Model;
|
||||||
|
import ctbrec.recorder.Recorder;
|
||||||
|
import ctbrec.ui.action.StopRecordingAction;
|
||||||
|
import ctbrec.ui.controls.Dialogs;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import ctbrec.GlobalThreadPool;
|
|
||||||
import ctbrec.Model;
|
|
||||||
import ctbrec.recorder.Recorder;
|
|
||||||
import ctbrec.ui.controls.Dialogs;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -17,9 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CheckModelAccountAction {
|
public class CheckModelAccountAction {
|
||||||
private Button b;
|
private Button b;
|
||||||
|
|
||||||
private Recorder recorder;
|
private Recorder recorder;
|
||||||
|
|
||||||
private String buttonText;
|
private String buttonText;
|
||||||
|
|
||||||
public CheckModelAccountAction(Button b, Recorder recorder) {
|
public CheckModelAccountAction(Button b, Recorder recorder) {
|
||||||
|
@ -30,30 +28,30 @@ public class CheckModelAccountAction {
|
||||||
|
|
||||||
public void execute(Predicate<Model> filter) {
|
public void execute(Predicate<Model> filter) {
|
||||||
b.setDisable(true);
|
b.setDisable(true);
|
||||||
Runnable checker = (() -> {
|
Runnable checker = () -> {
|
||||||
List<Model> deletedAccounts = new ArrayList<>();
|
ArrayList<Model> deletedAccounts = new ArrayList<Model>();
|
||||||
try {
|
try {
|
||||||
checkModelAccounts(filter, deletedAccounts);
|
checkModelAccounts(filter, deletedAccounts);
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
showResult(deletedAccounts);
|
showResult(deletedAccounts);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
GlobalThreadPool.submit(checker);
|
GlobalThreadPool.submit((Runnable)checker);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showResult(List<Model> deletedAccounts) {
|
private void showResult(List<Model> deletedAccounts) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
b.setDisable(false);
|
b.setDisable(false);
|
||||||
b.setText(buttonText);
|
b.setText(this.buttonText);
|
||||||
if (!deletedAccounts.isEmpty()) {
|
if (!deletedAccounts.isEmpty()) {
|
||||||
var sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Model deletedModel : deletedAccounts) {
|
for (Model deletedModel : deletedAccounts) {
|
||||||
String name = deletedModel.getDisplayName() + " ".repeat(30);
|
Object name = deletedModel.getDisplayName() + " ".repeat(30);
|
||||||
name = name.substring(0, 30);
|
name = ((String)name).substring(0, 30);
|
||||||
sb.append(name).append(' ').append('(').append(deletedModel.getUrl()).append(')').append('\n');
|
sb.append((String)name).append(' ').append('(').append(deletedModel.getUrl()).append(')').append('\n');
|
||||||
}
|
}
|
||||||
boolean remove = Dialogs.showConfirmDialog("Deleted Accounts", sb.toString(),
|
boolean remove = Dialogs.showExpandedConfirmDialog("Deleted Accounts", "Accounts list:", sb.toString(), "The following accounts seem to have been deleted. Do you want to remove them?", b.getScene());
|
||||||
"The following accounts seem to have been deleted. Do you want to remove them?", b.getScene());
|
|
||||||
if (remove) {
|
if (remove) {
|
||||||
new StopRecordingAction(b, deletedAccounts, recorder).execute();
|
new StopRecordingAction(b, deletedAccounts, recorder).execute();
|
||||||
}
|
}
|
||||||
|
@ -62,21 +60,21 @@ public class CheckModelAccountAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkModelAccounts(Predicate<Model> filter, List<Model> deletedAccounts) {
|
private void checkModelAccounts(Predicate<Model> filter, List<Model> deletedAccounts) {
|
||||||
List<Model> models = recorder.getModels().stream() //
|
List models = recorder.getModels().stream().filter(filter).collect(Collectors.toList());
|
||||||
.filter(filter) //
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
int total = models.size();
|
int total = models.size();
|
||||||
for (var i = 0; i < total; i++) {
|
for (int i = 0; i < total; ++i) {
|
||||||
final int counter = i+1;
|
int counter = i + 1;
|
||||||
Platform.runLater(() -> b.setText(buttonText + ' ' + counter + '/' + total));
|
Platform.runLater(() -> b.setText(buttonText + " " + counter + "/" + total));
|
||||||
var modelToCheck = models.get(i);
|
Model modelToCheck = (Model)models.get(i);
|
||||||
try {
|
try {
|
||||||
if (!modelToCheck.exists()) {
|
if (modelToCheck.exists()) continue;
|
||||||
deletedAccounts.add(modelToCheck);
|
deletedAccounts.add(modelToCheck);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
catch (IOException e) {
|
||||||
log.warn("Couldn't check, if model account still exists", e);
|
log.warn("Couldn't check, if model account still exists", (Throwable)e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package ctbrec.ui.controls;
|
package ctbrec.ui.controls;
|
||||||
|
|
||||||
import ctbrec.ui.AutosizeAlert;
|
import ctbrec.ui.AutosizeAlert;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
@ -9,6 +15,7 @@ import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Alert.AlertType;
|
import javafx.scene.control.Alert.AlertType;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import javafx.stage.Modality;
|
import javafx.stage.Modality;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
@ -29,26 +36,68 @@ public class Dialogs {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showError(String header, String text, Throwable t) {
|
public static void showError(String header, String text, Throwable t) {
|
||||||
showError(scene, header, text, t);
|
if (Objects.nonNull(t)) {
|
||||||
|
Dialogs.showError(scene, header, text, t);
|
||||||
|
} else {
|
||||||
|
Dialogs.showError(scene, header, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showError(Scene parent, String header, String text, Throwable t) {
|
public static void showError(Scene parent, String header, String text) {
|
||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, parent);
|
AutosizeAlert alert = new AutosizeAlert(Alert.AlertType.ERROR, parent);
|
||||||
alert.setTitle("Error");
|
alert.setTitle("Error");
|
||||||
alert.setHeaderText(header);
|
alert.setHeaderText(header);
|
||||||
String content = text;
|
alert.setContentText(text);
|
||||||
if (t != null) {
|
|
||||||
content += " " + t.getLocalizedMessage();
|
|
||||||
}
|
|
||||||
alert.setContentText(content);
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
var stage = (Stage) alert.getDialogPane().getScene().getWindow();
|
Stage stage = (Stage)alert.getDialogPane().getScene().getWindow();
|
||||||
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
|
stage.getScene().getStylesheets().addAll((Collection<String>)parent.getStylesheets());
|
||||||
}
|
}
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
};
|
};
|
||||||
|
if (Platform.isFxApplicationThread()) {
|
||||||
|
r.run();
|
||||||
|
} else {
|
||||||
|
Platform.runLater(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showError(Scene parent, String header, String text, Throwable t) {
|
||||||
|
if (Objects.isNull(t)) {
|
||||||
|
Dialogs.showError(parent, header, text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Runnable r = () -> {
|
||||||
|
AutosizeAlert alert = new AutosizeAlert(Alert.AlertType.ERROR, parent);
|
||||||
|
alert.setTitle("Error");
|
||||||
|
alert.setHeaderText(header);
|
||||||
|
String content = text + "\n" + t.getLocalizedMessage();
|
||||||
|
alert.setContentText(content);
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
t.printStackTrace(pw);
|
||||||
|
String exceptionText = sw.toString();
|
||||||
|
Label label = new Label("The exception stacktrace was:");
|
||||||
|
TextArea textArea = new TextArea(exceptionText);
|
||||||
|
textArea.setEditable(false);
|
||||||
|
textArea.setWrapText(true);
|
||||||
|
textArea.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
textArea.setMaxHeight(Double.MAX_VALUE);
|
||||||
|
GridPane.setVgrow(textArea, Priority.ALWAYS);
|
||||||
|
GridPane.setHgrow(textArea, Priority.ALWAYS);
|
||||||
|
GridPane expContent = new GridPane();
|
||||||
|
expContent.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
expContent.add(label, 0, 0);
|
||||||
|
expContent.add(textArea, 0, 1);
|
||||||
|
alert.getDialogPane().setExpandableContent(expContent);
|
||||||
|
alert.getDialogPane().setMinHeight(Double.NEGATIVE_INFINITY);
|
||||||
|
alert.getDialogPane().setMinWidth(Double.NEGATIVE_INFINITY);
|
||||||
|
if (parent != null) {
|
||||||
|
Stage stage = (Stage)alert.getDialogPane().getScene().getWindow();
|
||||||
|
stage.getScene().getStylesheets().addAll((Collection<String>)parent.getStylesheets());
|
||||||
|
}
|
||||||
|
alert.showAndWait();
|
||||||
|
};
|
||||||
if (Platform.isFxApplicationThread()) {
|
if (Platform.isFxApplicationThread()) {
|
||||||
r.run();
|
r.run();
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,6 +170,24 @@ public class Dialogs {
|
||||||
return confirm.getResult() == YES;
|
return confirm.getResult() == YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean showExpandedConfirmDialog(String title, String message, String expandedText, String header, Scene parent) {
|
||||||
|
AutosizeAlert confirm = new AutosizeAlert(Alert.AlertType.CONFIRMATION, message, parent, ButtonType.YES, ButtonType.NO);
|
||||||
|
confirm.setTitle(title);
|
||||||
|
confirm.setHeaderText(header);
|
||||||
|
TextArea textArea = new TextArea(expandedText);
|
||||||
|
textArea.setEditable(false);
|
||||||
|
textArea.setWrapText(true);
|
||||||
|
textArea.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
textArea.setMaxHeight(Double.MAX_VALUE);
|
||||||
|
GridPane.setVgrow(textArea, Priority.ALWAYS);
|
||||||
|
GridPane.setHgrow(textArea, Priority.ALWAYS);
|
||||||
|
confirm.getDialogPane().setExpandableContent(textArea);
|
||||||
|
confirm.getDialogPane().setExpanded(true);
|
||||||
|
confirm.getDialogPane().setMinHeight(Double.NEGATIVE_INFINITY);
|
||||||
|
confirm.showAndWait();
|
||||||
|
return confirm.getResult() == ButtonType.YES;
|
||||||
|
}
|
||||||
|
|
||||||
public static ButtonType showShutdownDialog(Scene parent) {
|
public static ButtonType showShutdownDialog(Scene parent) {
|
||||||
var message = "There are recordings in progress";
|
var message = "There are recordings in progress";
|
||||||
var confirm = new AutosizeAlert(AlertType.CONFIRMATION, "", parent, YES, FINISH, NO);
|
var confirm = new AutosizeAlert(AlertType.CONFIRMATION, "", parent, YES, FINISH, NO);
|
||||||
|
|
Loading…
Reference in New Issue