mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-03 03:01:13 +12:00
Rework shell choice comp
This commit is contained in:
parent
b647c24821
commit
c4e0932d9e
2 changed files with 32 additions and 38 deletions
|
@ -1,33 +0,0 @@
|
||||||
package io.xpipe.extension.fxcomps.impl;
|
|
||||||
|
|
||||||
import io.xpipe.core.store.ShellStore;
|
|
||||||
import io.xpipe.extension.fxcomps.SimpleComp;
|
|
||||||
import io.xpipe.extension.util.SimpleValidator;
|
|
||||||
import io.xpipe.extension.util.Validatable;
|
|
||||||
import io.xpipe.extension.util.Validator;
|
|
||||||
import javafx.beans.property.Property;
|
|
||||||
import javafx.scene.layout.Region;
|
|
||||||
|
|
||||||
public class ProxyChoiceComp extends SimpleComp implements Validatable {
|
|
||||||
|
|
||||||
private final Property<ShellStore> selected;
|
|
||||||
private final Validator validator = new SimpleValidator();
|
|
||||||
// private final Check check;
|
|
||||||
|
|
||||||
public ProxyChoiceComp(Property<ShellStore> selected) {
|
|
||||||
this.selected = selected;
|
|
||||||
// check = Validator.exceptionWrapper(validator, selected, () -> XPipeProxy.checkSupport(selected.getValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Region createSimple() {
|
|
||||||
var choice = new ShellStoreChoiceComp<>(null, selected, ShellStore.class, shellStore -> true);
|
|
||||||
// choice.apply(struc -> check.decorates(struc.get()));
|
|
||||||
return choice.createRegion();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Validator getValidator() {
|
|
||||||
return validator;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,20 +14,41 @@ import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.Region;
|
import javafx.scene.layout.Region;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: Integrate store validation more into this comp.
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
||||||
|
|
||||||
|
public static ShellStoreChoiceComp<ShellStore> proxy(Property<ShellStore> selected) {
|
||||||
|
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, null, selected, ShellStore.class, shellStore -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ShellStoreChoiceComp<ShellStore> host(Property<ShellStore> selected) {
|
||||||
|
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, null, selected, ShellStore.class, shellStore -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ShellStoreChoiceComp<ShellStore> proxy(ShellStore self, Property<ShellStore> selected) {
|
||||||
|
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, self, selected, ShellStore.class, shellStore -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ShellStoreChoiceComp<ShellStore> host(ShellStore self, Property<ShellStore> selected) {
|
||||||
|
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, self, selected, ShellStore.class, shellStore -> true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum Mode {
|
||||||
|
HOST_CHOICE,
|
||||||
|
PROXY_CHOICE
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Mode mode;
|
||||||
private final T self;
|
private final T self;
|
||||||
private final Property<T> selected;
|
private final Property<T> selected;
|
||||||
private final Class<T> storeClass;
|
private final Class<T> storeClass;
|
||||||
private final Predicate<T> applicableCheck;
|
private final Predicate<T> applicableCheck;
|
||||||
|
|
||||||
private Region createGraphic(T s) {
|
protected Region createGraphic(T s) {
|
||||||
var provider = DataStoreProviders.byStore(s);
|
var provider = DataStoreProviders.byStore(s);
|
||||||
var imgView =
|
var imgView =
|
||||||
new PrettyImageComp(new SimpleStringProperty(provider.getDisplayIconFileName()), 16, 16).createRegion();
|
new PrettyImageComp(new SimpleStringProperty(provider.getDisplayIconFileName()), 16, 16).createRegion();
|
||||||
|
@ -35,7 +56,13 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
|
||||||
var name = XPipeDaemon.getInstance().getNamedStores().stream()
|
var name = XPipeDaemon.getInstance().getNamedStores().stream()
|
||||||
.filter(e -> e.equals(s))
|
.filter(e -> e.equals(s))
|
||||||
.findAny()
|
.findAny()
|
||||||
.flatMap(store -> XPipeDaemon.getInstance().getStoreName(store))
|
.flatMap(store -> {
|
||||||
|
if (ShellStore.isLocal(store.asNeeded()) && mode == Mode.PROXY_CHOICE) {
|
||||||
|
return Optional.of(I18n.get("none"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return XPipeDaemon.getInstance().getStoreName(store);
|
||||||
|
})
|
||||||
.orElse(I18n.get("unknown"));
|
.orElse(I18n.get("unknown"));
|
||||||
|
|
||||||
return new Label(name, imgView);
|
return new Label(name, imgView);
|
||||||
|
|
Loading…
Reference in a new issue