Show unavailable scan targets

This commit is contained in:
crschnick 2023-12-10 13:44:19 +00:00
parent 575cea68e3
commit c40c9c1f84
6 changed files with 40 additions and 7 deletions

View file

@ -16,6 +16,7 @@ import lombok.Value;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
@Value
@EqualsAndHashCode(callSuper = true)
@ -24,6 +25,7 @@ public class ListSelectorComp<T> extends SimpleComp {
List<T> values;
Function<T, String> toString;
ListProperty<T> selected;
Predicate<T> disable;
boolean showAllSelector;
@Override
@ -34,6 +36,9 @@ public class ListSelectorComp<T> extends SimpleComp {
var cbs = new ArrayList<CheckBox>();
for (var v : values) {
var cb = new CheckBox(null);
if (disable.test(v)) {
cb.setDisable(true);
}
cbs.add(cb);
cb.setAccessibleText(toString.apply(v));
cb.setSelected(selected.contains(v));
@ -46,15 +51,29 @@ public class ListSelectorComp<T> extends SimpleComp {
});
var l = new Label(toString.apply(v), cb);
l.setGraphicTextGap(9);
l.setOnMouseClicked(event -> cb.setSelected(!cb.isSelected()));
l.setOnMouseClicked(event -> {
if (disable.test(v)) {
return;
}
cb.setSelected(!cb.isSelected());
event.consume();
});
l.opacityProperty().bind(cb.opacityProperty());
vbox.getChildren().add(l);
}
if (showAllSelector) {
var allSelector = new CheckBox(null);
allSelector.setSelected(values.size() == selected.size());
allSelector.setSelected(values.stream().filter(t -> !disable.test(t)).count() == selected.size());
allSelector.selectedProperty().addListener((observable, oldValue, newValue) -> {
cbs.forEach(checkBox -> checkBox.setSelected(newValue));
cbs.forEach(checkBox -> {
if (checkBox.isDisabled()) {
return;
}
checkBox.setSelected(newValue);
});
});
var l = new Label(null, allSelector);
l.textProperty().bind(AppI18n.observable("selectAll"));

View file

@ -17,6 +17,7 @@ public abstract class ScanProvider {
@Value
public static class ScanOperation {
String nameKey;
boolean disabled;
boolean defaultSelected;
FailableRunnable<Exception> scanner;
}

View file

@ -67,6 +67,7 @@ public class UserReportComp extends SimpleComp {
return file.getFileName().toString();
},
includedDiagnostics,
file -> false,
false)
.styleClass("attachment-list");
return new TitledPaneComp(AppI18n.observable("additionalErrorAttachments"), list, 100)

View file

@ -35,10 +35,12 @@ public class AskpassAlert {
var r = AppWindowHelper.showBlockingAlert(alert -> {
alert.setTitle(AppI18n.get("askpassAlertTitle"));
alert.setHeaderText(prompt);
// alert.getDialogPane().setHeader(
// AppWindowHelper.alertContentText(prompt));
alert.setAlertType(Alert.AlertType.CONFIRMATION);
// alert.getDialogPane().getScene().getWindow().setOnShown(event -> {
// ((Stage) alert.getDialogPane().getScene().getWindow()).setAlwaysOnTop(true);
// });
var text = new SecretFieldComp(prop).createRegion();
alert.getDialogPane().setContent(new StackPane(text));
})

View file

@ -114,8 +114,10 @@ public class ScanAlert {
return;
}
selected.setAll(a.stream().filter(scanOperation -> scanOperation.isDefaultSelected()).toList());
var r = new ListSelectorComp<>(a, scanOperation -> AppI18n.get(scanOperation.getNameKey()), selected,
selected.setAll(a.stream().filter(scanOperation -> scanOperation.isDefaultSelected() && !scanOperation.isDisabled()).toList());
var r = new ListSelectorComp<ScanProvider.ScanOperation>(a,
scanOperation -> AppI18n.get(scanOperation.getNameKey()),
selected,scanOperation -> scanOperation.isDisabled(),
a.size() > 3).createRegion();
stackPane.getChildren().add(r);
});

View file

@ -7,6 +7,7 @@ import lombok.NonNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
@ -108,6 +109,13 @@ public interface ShellControl extends ProcessControl {
}
}
default Optional<String> executeSimpleStringCommandAndCheck(String command) throws Exception {
try (CommandControl c = command(command).start()) {
var out = c.readStdoutDiscardErr();
return c.getExitCode() == 0 ? Optional.of(out) : Optional.empty();
}
}
default boolean executeSimpleBooleanCommand(String command) throws Exception {
try (CommandControl c = command(command).start()) {
return c.discardAndCheckExit();