mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-25 01:45:37 +00:00
Rework options builder validator
This commit is contained in:
@@ -5,6 +5,7 @@ import io.xpipe.app.comp.CompStructure;
|
||||
import io.xpipe.app.comp.SimpleCompStructure;
|
||||
import io.xpipe.app.core.AppFontSizes;
|
||||
import io.xpipe.app.platform.BindingsHelper;
|
||||
import io.xpipe.app.platform.Check;
|
||||
import io.xpipe.app.platform.Validator;
|
||||
import io.xpipe.app.util.Hyperlinks;
|
||||
|
||||
@@ -35,10 +36,12 @@ public class OptionsComp extends Comp<CompStructure<VBox>> {
|
||||
|
||||
private final List<Entry> entries;
|
||||
private final Validator validator;
|
||||
private final List<Check> checks;
|
||||
|
||||
public OptionsComp(List<Entry> entries, Validator validator) {
|
||||
public OptionsComp(List<Entry> entries, Validator validator, List<Check> checks) {
|
||||
this.entries = entries;
|
||||
this.validator = validator;
|
||||
this.checks = checks;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,7 +217,6 @@ public class OptionsComp extends Comp<CompStructure<VBox>> {
|
||||
return;
|
||||
}
|
||||
|
||||
var checks = validator.getActiveChecks();
|
||||
var failed = checks.stream()
|
||||
.filter(check -> check.getValidationResult().getMessages().size() > 0)
|
||||
.findFirst();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.xpipe.app.ext;
|
||||
|
||||
import io.xpipe.app.comp.Comp;
|
||||
import io.xpipe.app.platform.OptionsBuilder;
|
||||
import io.xpipe.app.platform.Validator;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -10,6 +11,5 @@ import lombok.Value;
|
||||
@AllArgsConstructor
|
||||
public class GuiDialog {
|
||||
|
||||
Comp<?> comp;
|
||||
Validator validator;
|
||||
OptionsBuilder options;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,9 @@ public class StoreCreationComp extends ModalOverlayContentComp {
|
||||
return model.getBusy();
|
||||
}
|
||||
|
||||
private Region createStoreProperties(Comp<?> providerComp, Validator providerVal, Validator propVal) {
|
||||
private OptionsBuilder createStoreProperties() {
|
||||
var nameKey = model.storeTypeNameKey();
|
||||
var built = new OptionsBuilder(propVal)
|
||||
.addComp(providerComp, model.getStore())
|
||||
var built = new OptionsBuilder()
|
||||
.name(nameKey + "Name")
|
||||
.description(nameKey + "NameDescription")
|
||||
.addString(model.getName(), false)
|
||||
@@ -50,10 +49,8 @@ public class StoreCreationComp extends ModalOverlayContentComp {
|
||||
&& DataStorage.get().getEffectiveReadOnlyState(model.getExistingEntry())
|
||||
&& s.equals(model.getExistingEntry().getName());
|
||||
return !same;
|
||||
}))
|
||||
.buildComp();
|
||||
var comp = new OptionsComp(built.getEntries(), new ChainedValidator(List.of(providerVal, propVal)));
|
||||
return comp.styleClass("store-creator-options").createRegion();
|
||||
}));
|
||||
return built;
|
||||
}
|
||||
|
||||
private Region createLayout() {
|
||||
@@ -73,16 +70,21 @@ public class StoreCreationComp extends ModalOverlayContentComp {
|
||||
model.getProvider().subscribe(n -> {
|
||||
if (n != null) {
|
||||
var d = n.guiDialog(model.getExistingEntry(), model.getStore());
|
||||
if (d == null || d.getComp() == null || d.getValidator() == null) {
|
||||
if (d == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var propVal = new SimpleValidator();
|
||||
var propR = createStoreProperties(d.getComp(), d.getValidator(), propVal);
|
||||
var propOptions = createStoreProperties();
|
||||
model.getInitialStore().setValue(model.getStore().getValue());
|
||||
|
||||
var valSp = new GraphicDecorationStackPane();
|
||||
valSp.getChildren().add(propR);
|
||||
|
||||
var full = new OptionsBuilder();
|
||||
full.sub(d.getOptions());
|
||||
full.sub(propOptions);
|
||||
|
||||
var region = full.buildComp().styleClass("store-creator-options").createRegion();
|
||||
valSp.getChildren().add(region);
|
||||
|
||||
var sp = new ScrollPane(valSp);
|
||||
sp.setSkin(new ScrollPaneSkin(sp));
|
||||
@@ -102,10 +104,10 @@ public class StoreCreationComp extends ModalOverlayContentComp {
|
||||
|
||||
layout.setCenter(vbox);
|
||||
|
||||
model.getValidator().setValue(new ChainedValidator(List.of(d.getValidator(), propVal)));
|
||||
model.getValidator().setValue(full.buildEffectiveValidator());
|
||||
|
||||
Platform.runLater(() -> {
|
||||
propR.requestFocus();
|
||||
region.requestFocus();
|
||||
});
|
||||
} else {
|
||||
layout.setCenter(null);
|
||||
|
||||
@@ -108,13 +108,4 @@ public class ChainedValidator implements Validator {
|
||||
},
|
||||
observables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Check> getActiveChecks() {
|
||||
var all = new ArrayList<Check>();
|
||||
for (var val : validators) {
|
||||
all.addAll(val.getActiveChecks());
|
||||
}
|
||||
return all;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +84,4 @@ public final class ExclusiveValidator<T> implements Validator {
|
||||
},
|
||||
observables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Check> getActiveChecks() {
|
||||
return validators.get(obs.getValue()).getActiveChecks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ public class OptionsBuilder {
|
||||
|
||||
public OptionsComp buildComp() {
|
||||
finishCurrent();
|
||||
var comp = new OptionsComp(entries, buildEffectiveValidator());
|
||||
var comp = new OptionsComp(entries, buildEffectiveValidator(), allChecks);
|
||||
for (Augment<CompStructure<VBox>> augment : augments) {
|
||||
comp.apply(augment);
|
||||
}
|
||||
@@ -421,6 +421,6 @@ public class OptionsBuilder {
|
||||
}
|
||||
|
||||
public GuiDialog buildDialog() {
|
||||
return new GuiDialog(buildComp(), buildEffectiveValidator());
|
||||
return new GuiDialog(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,11 +123,6 @@ public class SimpleValidator implements Validator {
|
||||
validationResultProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Check> getActiveChecks() {
|
||||
return checks.keySet();
|
||||
}
|
||||
|
||||
private void refreshProperties() {
|
||||
ValidationResult nextResult = new ValidationResult();
|
||||
for (Check check : checks.keySet()) {
|
||||
|
||||
@@ -122,6 +122,4 @@ public interface Validator {
|
||||
* @param separator The string to separate consecutive validation messages with
|
||||
*/
|
||||
StringBinding createStringBinding(String prefix, String separator);
|
||||
|
||||
Collection<Check> getActiveChecks();
|
||||
}
|
||||
|
||||
+2
-4
@@ -56,10 +56,9 @@ public class PodmanContainerStoreProvider implements ShellStoreProvider {
|
||||
|
||||
@Override
|
||||
public GuiDialog guiDialog(DataStoreEntry entry, Property<DataStore> store) {
|
||||
var val = new SimpleValidator();
|
||||
PodmanContainerStore st = (PodmanContainerStore) store.getValue();
|
||||
|
||||
var q = new OptionsBuilder()
|
||||
return new OptionsBuilder()
|
||||
.name("host")
|
||||
.description("podmanHostDescription")
|
||||
.addComp(StoreChoiceComp.host(
|
||||
@@ -70,8 +69,7 @@ public class PodmanContainerStoreProvider implements ShellStoreProvider {
|
||||
.name("container")
|
||||
.description("podmanContainerDescription")
|
||||
.addStaticString(st.getContainerName())
|
||||
.buildComp();
|
||||
return new GuiDialog(q, val);
|
||||
.buildDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user