Various small improvements

This commit is contained in:
Christopher Schnick 2023-01-07 22:19:54 +01:00
parent a82717154d
commit 2f54a79407
5 changed files with 19 additions and 34 deletions

View file

@ -52,4 +52,8 @@ public interface DataStoreActionProvider<T extends DataStore> {
default void execute(T store) throws Exception {
}
default boolean showIfDisabled() {
return true;
}
}

View file

@ -40,7 +40,7 @@ public interface DataStoreProvider {
}
default GuiDialog guiDialog(Property<DataStore> store) {
throw new ExtensionException("Gui Dialog is not implemented by provider " + getId());
return null;
}
default boolean init() throws Exception {

View file

@ -3,7 +3,6 @@ package io.xpipe.extension.fxcomps.impl;
import io.xpipe.core.store.ShellStore;
import io.xpipe.extension.DataStoreProviders;
import io.xpipe.extension.I18n;
import io.xpipe.extension.event.ErrorEvent;
import io.xpipe.extension.fxcomps.SimpleComp;
import io.xpipe.extension.util.CustomComboBoxBuilder;
import io.xpipe.extension.util.XPipeDaemon;
@ -37,7 +36,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
.filter(e -> e.equals(s))
.findAny()
.flatMap(store -> XPipeDaemon.getInstance().getStoreName(store))
.orElse("?");
.orElse(I18n.get("unknown"));
return new Label(name, imgView);
}
@ -45,41 +44,15 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
@Override
@SuppressWarnings("unchecked")
protected Region createSimple() {
var comboBox = new CustomComboBoxBuilder<T>(selected, this::createGraphic, null, n -> {
if (n != null) {
try {
n.checkComplete();
// n.test();
} catch (Exception ex) {
var name = XPipeDaemon.getInstance().getNamedStores().stream()
.filter(e -> e.equals(n))
.findAny()
.flatMap(store -> XPipeDaemon.getInstance().getStoreName(store))
.orElse("?");
ErrorEvent.fromMessage(I18n.get("extension.namedHostNotActive", name))
.reportable(false)
.handle();
return false;
}
}
// if (n != null && !supportCheck.test(n)) {
// var name = XPipeDaemon.getInstance().getNamedStores().stream()
// .filter(e -> e.equals(n)).findAny()
// .flatMap(store ->
// XPipeDaemon.getInstance().getStoreName(store)).orElse(I18n.get("localMachine"));
// ErrorEvent.fromMessage(I18n.get("extension.namedHostFeatureUnsupported",
// name)).reportable(false).handle();
// return false;
// }
return true;
});
var comboBox = new CustomComboBoxBuilder<T>(selected, this::createGraphic, new Label(I18n.get("none")), n -> true);
comboBox.setUnknownNode(t -> createGraphic(t));
var available = XPipeDaemon.getInstance().getNamedStores().stream()
.filter(s -> s != self)
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
.map(s -> (ShellStore) s)
.toList();
available.forEach(s -> comboBox.add((T) s));
ComboBox<Node> cb = comboBox.build();
cb.getStyleClass().add("choice-comp");

View file

@ -35,6 +35,7 @@ public class CustomComboBoxBuilder<T> {
private final List<T> filterable = new ArrayList<>();
private BiPredicate<T, String> filterPredicate;
private Node filterNode;
private Function<T, Node> unknownNode;
public CustomComboBoxBuilder(
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto
@ -50,6 +51,10 @@ public class CustomComboBoxBuilder<T> {
actionsMap.put(node, run);
}
public void setUnknownNode(Function<T, Node> node) {
unknownNode = node;
}
public Node add(T val) {
var node = nodeFunction.apply(val);
nodeMap.put(node, val);
@ -101,8 +106,8 @@ public class CustomComboBoxBuilder<T> {
.filter(e -> Objects.equals(c, e.getValue()))
.map(e -> e.getKey())
.findAny()
.orElse(null);
cb.setValue(Optional.ofNullable(item).orElse(emptyNode));
.orElse(c == null || unknownNode == null? emptyNode : unknownNode.apply(c));
cb.setValue(item);
});
cb.valueProperty().addListener((c, o, n) -> {
if (nodeMap.containsKey(n)) {
@ -161,7 +166,9 @@ public class CustomComboBoxBuilder<T> {
return;
}
// Case for dynamically created unknown nodes
if (!nodeMap.containsKey(item)) {
setGraphic(item);
return;
}

View file

@ -10,6 +10,7 @@ mustNotBeEmpty=$NAME$ must not be empty
null=$VALUE$ must be not null
hostFeatureUnsupported=Host does not support the feature $FEATURE$
missingStore=$NAME$ does not exist
unknown=Unknown
namedHostFeatureUnsupported=$HOST$ does not support this feature
namedHostNotActive=$HOST$ is not active
noInformationAvailable=No information available