mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-07 10:22:19 -04:00
Rework stores and add some documentation
This commit is contained in:
1 parent
4eb0c80d60
commit
0f37600c96
29 files changed
+725
-187
No files matched your search
@@ -38,6 +38,10 @@ public interface DataStoreProvider {
|
||||
default void init() throws Exception {
|
||||
}
|
||||
|
||||
default boolean isHidden() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default String i18n(String key) {
|
||||
return I18n.get(getId() + "." + key);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ public interface I18n {
|
||||
}
|
||||
|
||||
public static ObservableValue<String> observable(String s, Object... vars) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bindings.createStringBinding(() -> {
|
||||
return get(s, vars);
|
||||
});
|
||||
|
||||
@@ -93,6 +93,13 @@ public class DynamicOptionsBuilder<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder<T> addStringArea(String nameKey, Property<String> prop) {
|
||||
var comp = new TextAreaComp(prop);
|
||||
entries.add(new DynamicOptionsComp.Entry(I18n.observable(nameKey), comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder<T> addString(String nameKey, Property<String> prop) {
|
||||
var comp = new TextFieldComp(prop);
|
||||
entries.add(new DynamicOptionsComp.Entry(I18n.observable(nameKey), comp));
|
||||
@@ -107,8 +114,9 @@ public class DynamicOptionsBuilder<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder<T> addComp(ObservableValue<String> name, Comp<?> comp) {
|
||||
public DynamicOptionsBuilder<T> addComp(ObservableValue<String> name, Comp<?> comp, Property<?> prop) {
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SecretFieldComp extends Comp<CompStructure<TextField>> {
|
||||
var text = new PasswordField();
|
||||
text.setText(value.getValue() != null ? value.getValue().getSecretValue() : null);
|
||||
text.textProperty().addListener((c, o, n) -> {
|
||||
value.setValue(n.length() > 0 ? Secret.create(n) : null);
|
||||
value.setValue(n.length() > 0 ? Secret.createForSecretValue(n) : null);
|
||||
});
|
||||
value.addListener((c, o, n) -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.xpipe.extension.comp;
|
||||
|
||||
import io.xpipe.fxcomps.Comp;
|
||||
import io.xpipe.fxcomps.CompStructure;
|
||||
import io.xpipe.fxcomps.SimpleCompStructure;
|
||||
import io.xpipe.fxcomps.util.PlatformThread;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.scene.control.TextArea;
|
||||
|
||||
public class TextAreaComp extends Comp<CompStructure<TextArea>> {
|
||||
|
||||
private final Property<String> value;
|
||||
|
||||
public TextAreaComp(Property<String> value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompStructure<TextArea> createBase() {
|
||||
var text = new TextArea(value.getValue() != null ? value.getValue().toString() : null);
|
||||
text.textProperty().addListener((c, o, n) -> {
|
||||
value.setValue(n != null && n.length() > 0 ? n : null);
|
||||
});
|
||||
value.addListener((c, o, n) -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
text.setText(n);
|
||||
});
|
||||
});
|
||||
return new SimpleCompStructure<>(text);
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,21 @@ public class ExceptionConverter {
|
||||
public static String convertMessage(Throwable ex) {
|
||||
var msg = ex.getLocalizedMessage();
|
||||
if (ex instanceof FileNotFoundException) {
|
||||
return I18n.get("fileNotFound", msg);
|
||||
return I18n.get("extension.fileNotFound", msg);
|
||||
}
|
||||
|
||||
if (ex instanceof ClassNotFoundException) {
|
||||
return I18n.get("classNotFound", msg);
|
||||
return I18n.get("extension.classNotFound", msg);
|
||||
}
|
||||
|
||||
if (ex instanceof NullPointerException) {
|
||||
return I18n.get("extension.nullPointer", msg);
|
||||
}
|
||||
|
||||
if (msg == null || msg.trim().length() == 0) {
|
||||
return I18n.get("extension.noInformationAvailable");
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user