mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Various small improvements
This commit is contained in:
parent
18a8bc8dc5
commit
73f3521ee8
5 changed files with 19 additions and 34 deletions
|
@ -52,4 +52,8 @@ public interface DataStoreActionProvider<T extends DataStore> {
|
||||||
|
|
||||||
default void execute(T store) throws Exception {
|
default void execute(T store) throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean showIfDisabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public interface DataStoreProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
default GuiDialog guiDialog(Property<DataStore> store) {
|
default GuiDialog guiDialog(Property<DataStore> store) {
|
||||||
throw new ExtensionException("Gui Dialog is not implemented by provider " + getId());
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean init() throws Exception {
|
default boolean init() throws Exception {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package io.xpipe.extension.fxcomps.impl;
|
||||||
import io.xpipe.core.store.ShellStore;
|
import io.xpipe.core.store.ShellStore;
|
||||||
import io.xpipe.extension.DataStoreProviders;
|
import io.xpipe.extension.DataStoreProviders;
|
||||||
import io.xpipe.extension.I18n;
|
import io.xpipe.extension.I18n;
|
||||||
import io.xpipe.extension.event.ErrorEvent;
|
|
||||||
import io.xpipe.extension.fxcomps.SimpleComp;
|
import io.xpipe.extension.fxcomps.SimpleComp;
|
||||||
import io.xpipe.extension.util.CustomComboBoxBuilder;
|
import io.xpipe.extension.util.CustomComboBoxBuilder;
|
||||||
import io.xpipe.extension.util.XPipeDaemon;
|
import io.xpipe.extension.util.XPipeDaemon;
|
||||||
|
@ -37,7 +36,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
||||||
.filter(e -> e.equals(s))
|
.filter(e -> e.equals(s))
|
||||||
.findAny()
|
.findAny()
|
||||||
.flatMap(store -> XPipeDaemon.getInstance().getStoreName(store))
|
.flatMap(store -> XPipeDaemon.getInstance().getStoreName(store))
|
||||||
.orElse("?");
|
.orElse(I18n.get("unknown"));
|
||||||
|
|
||||||
return new Label(name, imgView);
|
return new Label(name, imgView);
|
||||||
}
|
}
|
||||||
|
@ -45,41 +44,15 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected Region createSimple() {
|
protected Region createSimple() {
|
||||||
var comboBox = new CustomComboBoxBuilder<T>(selected, this::createGraphic, null, n -> {
|
var comboBox = new CustomComboBoxBuilder<T>(selected, this::createGraphic, new Label(I18n.get("none")), n -> true);
|
||||||
if (n != null) {
|
comboBox.setUnknownNode(t -> createGraphic(t));
|
||||||
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 available = XPipeDaemon.getInstance().getNamedStores().stream()
|
var available = XPipeDaemon.getInstance().getNamedStores().stream()
|
||||||
.filter(s -> s != self)
|
.filter(s -> s != self)
|
||||||
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
|
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
|
||||||
.map(s -> (ShellStore) s)
|
.map(s -> (ShellStore) s)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
available.forEach(s -> comboBox.add((T) s));
|
available.forEach(s -> comboBox.add((T) s));
|
||||||
ComboBox<Node> cb = comboBox.build();
|
ComboBox<Node> cb = comboBox.build();
|
||||||
cb.getStyleClass().add("choice-comp");
|
cb.getStyleClass().add("choice-comp");
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class CustomComboBoxBuilder<T> {
|
||||||
private final List<T> filterable = new ArrayList<>();
|
private final List<T> filterable = new ArrayList<>();
|
||||||
private BiPredicate<T, String> filterPredicate;
|
private BiPredicate<T, String> filterPredicate;
|
||||||
private Node filterNode;
|
private Node filterNode;
|
||||||
|
private Function<T, Node> unknownNode;
|
||||||
|
|
||||||
public CustomComboBoxBuilder(
|
public CustomComboBoxBuilder(
|
||||||
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto
|
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto
|
||||||
|
@ -50,6 +51,10 @@ public class CustomComboBoxBuilder<T> {
|
||||||
actionsMap.put(node, run);
|
actionsMap.put(node, run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUnknownNode(Function<T, Node> node) {
|
||||||
|
unknownNode = node;
|
||||||
|
}
|
||||||
|
|
||||||
public Node add(T val) {
|
public Node add(T val) {
|
||||||
var node = nodeFunction.apply(val);
|
var node = nodeFunction.apply(val);
|
||||||
nodeMap.put(node, val);
|
nodeMap.put(node, val);
|
||||||
|
@ -101,8 +106,8 @@ public class CustomComboBoxBuilder<T> {
|
||||||
.filter(e -> Objects.equals(c, e.getValue()))
|
.filter(e -> Objects.equals(c, e.getValue()))
|
||||||
.map(e -> e.getKey())
|
.map(e -> e.getKey())
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElse(null);
|
.orElse(c == null || unknownNode == null? emptyNode : unknownNode.apply(c));
|
||||||
cb.setValue(Optional.ofNullable(item).orElse(emptyNode));
|
cb.setValue(item);
|
||||||
});
|
});
|
||||||
cb.valueProperty().addListener((c, o, n) -> {
|
cb.valueProperty().addListener((c, o, n) -> {
|
||||||
if (nodeMap.containsKey(n)) {
|
if (nodeMap.containsKey(n)) {
|
||||||
|
@ -161,7 +166,9 @@ public class CustomComboBoxBuilder<T> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Case for dynamically created unknown nodes
|
||||||
if (!nodeMap.containsKey(item)) {
|
if (!nodeMap.containsKey(item)) {
|
||||||
|
setGraphic(item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ mustNotBeEmpty=$NAME$ must not be empty
|
||||||
null=$VALUE$ must be not null
|
null=$VALUE$ must be not null
|
||||||
hostFeatureUnsupported=Host does not support the feature $FEATURE$
|
hostFeatureUnsupported=Host does not support the feature $FEATURE$
|
||||||
missingStore=$NAME$ does not exist
|
missingStore=$NAME$ does not exist
|
||||||
|
unknown=Unknown
|
||||||
namedHostFeatureUnsupported=$HOST$ does not support this feature
|
namedHostFeatureUnsupported=$HOST$ does not support this feature
|
||||||
namedHostNotActive=$HOST$ is not active
|
namedHostNotActive=$HOST$ is not active
|
||||||
noInformationAvailable=No information available
|
noInformationAvailable=No information available
|
||||||
|
|
Loading…
Reference in a new issue