mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-07 10:22:19 -04:00
Refactor
This commit is contained in:
1 parent
27843ae0fd
commit
55da767dab
186 files changed
+1541
-1606
No files matched your search
@@ -8,8 +8,6 @@ public interface Cache {
|
||||
|
||||
Cache INSTANCE = ServiceLoader.load(Cache.class).findFirst().orElseThrow();
|
||||
|
||||
public <T> T getValue(String key, Class<?> type, Supplier<T> notPresent);
|
||||
|
||||
public static <T> T get(String key, Class<T> type, Supplier<T> notPresent) {
|
||||
return INSTANCE.getValue(key, type, notPresent);
|
||||
}
|
||||
@@ -18,9 +16,11 @@ public interface Cache {
|
||||
return Optional.ofNullable(get(key, type, () -> null));
|
||||
}
|
||||
|
||||
public <T> void updateValue(String key, T val);
|
||||
|
||||
public static <T> void update(String key, T val) {
|
||||
INSTANCE.updateValue(key, key);
|
||||
}
|
||||
|
||||
public <T> T getValue(String key, Class<?> type, Supplier<T> notPresent);
|
||||
|
||||
public <T> void updateValue(String key, T val);
|
||||
}
|
||||
@@ -12,11 +12,6 @@ import java.util.Map;
|
||||
|
||||
public interface DataSourceProvider<T extends DataSource<?>> {
|
||||
|
||||
static enum Category {
|
||||
FILE,
|
||||
DATABASE;
|
||||
}
|
||||
|
||||
default void validate() throws Exception {
|
||||
getCategory();
|
||||
getSourceClass();
|
||||
@@ -38,8 +33,7 @@ public interface DataSourceProvider<T extends DataSource<?>> {
|
||||
throw new ExtensionException();
|
||||
}
|
||||
|
||||
default void init() throws Exception {
|
||||
}
|
||||
default void init() throws Exception {}
|
||||
|
||||
default String i18n(String key) {
|
||||
return I18n.get(i18nKey(key));
|
||||
@@ -71,20 +65,10 @@ public interface DataSourceProvider<T extends DataSource<?>> {
|
||||
return getModuleName() + ":" + getId() + "_icon.png";
|
||||
}
|
||||
|
||||
|
||||
default String getSourceDescription(T source) {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
interface FileProvider {
|
||||
|
||||
String getFileName();
|
||||
|
||||
Map<String, List<String>> getFileExtensions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Dialog configDialog(T source, boolean all);
|
||||
|
||||
default boolean shouldShow(DataSourceType type) {
|
||||
@@ -125,7 +109,6 @@ public interface DataSourceProvider<T extends DataSource<?>> {
|
||||
return getPossibleNames().get(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to create a useful data source descriptor from a data store.
|
||||
* The result does not need to be always right, it should only reflect the best effort.
|
||||
@@ -134,6 +117,17 @@ public interface DataSourceProvider<T extends DataSource<?>> {
|
||||
|
||||
Class<T> getSourceClass();
|
||||
|
||||
|
||||
List<String> getPossibleNames();
|
||||
|
||||
static enum Category {
|
||||
FILE,
|
||||
DATABASE;
|
||||
}
|
||||
|
||||
interface FileProvider {
|
||||
|
||||
String getFileName();
|
||||
|
||||
Map<String, List<String>> getFileExtensions();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,10 @@ import io.xpipe.core.store.FileStore;
|
||||
import io.xpipe.extension.event.ErrorEvent;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataSourceProviders {
|
||||
@@ -15,8 +18,7 @@ public class DataSourceProviders {
|
||||
|
||||
public static void init(ModuleLayer layer) {
|
||||
if (ALL == null) {
|
||||
ALL = ServiceLoader.load(layer, DataSourceProvider.class)
|
||||
.stream()
|
||||
ALL = ServiceLoader.load(layer, DataSourceProvider.class).stream()
|
||||
.map(p -> (DataSourceProvider<?>) p.get())
|
||||
.sorted(Comparator.comparing(DataSourceProvider::getId))
|
||||
.collect(Collectors.toList());
|
||||
@@ -26,8 +28,7 @@ public class DataSourceProviders {
|
||||
p.validate();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e)
|
||||
.handle();
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -41,7 +42,7 @@ public class DataSourceProviders {
|
||||
case STRUCTURE -> DataSourceProviders.byId("xpbs");
|
||||
case TEXT -> DataSourceProviders.byId("text");
|
||||
case RAW -> DataSourceProviders.byId("binary");
|
||||
//TODO
|
||||
// TODO
|
||||
case COLLECTION -> null;
|
||||
};
|
||||
} catch (Exception ex) {
|
||||
@@ -52,46 +53,46 @@ public class DataSourceProviders {
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public static StructureDataSource<FileStore> createLocalStructureDescriptor(DataStore store) {
|
||||
return (StructureDataSource<FileStore>)
|
||||
DataSourceProviders.byId("xpbs")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0].newInstance(store);
|
||||
return (StructureDataSource<FileStore>) DataSourceProviders.byId("xpbs")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0]
|
||||
.newInstance(store);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public static RawDataSource<FileStore> createLocalRawDescriptor(DataStore store) {
|
||||
return (RawDataSource<FileStore>)
|
||||
DataSourceProviders.byId("binary")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0].newInstance(store);
|
||||
return (RawDataSource<FileStore>) DataSourceProviders.byId("binary")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0]
|
||||
.newInstance(store);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public static RawDataSource<FileStore> createLocalCollectionDescriptor(DataStore store) {
|
||||
return (RawDataSource<FileStore>)
|
||||
DataSourceProviders.byId("br")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0].newInstance(store);
|
||||
return (RawDataSource<FileStore>) DataSourceProviders.byId("br")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0]
|
||||
.newInstance(store);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public static TextDataSource<FileStore> createLocalTextDescriptor(DataStore store) {
|
||||
return (TextDataSource<FileStore>)
|
||||
DataSourceProviders.byId("text")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0].newInstance(store);
|
||||
return (TextDataSource<FileStore>) DataSourceProviders.byId("text")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0]
|
||||
.newInstance(store);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SneakyThrows
|
||||
public static TableDataSource<FileStore> createLocalTableDescriptor(DataStore store) {
|
||||
return (TableDataSource<FileStore>)
|
||||
DataSourceProviders.byId("xpbt")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0].newInstance(store);
|
||||
return (TableDataSource<FileStore>) DataSourceProviders.byId("xpbt")
|
||||
.getSourceClass()
|
||||
.getDeclaredConstructors()[0]
|
||||
.newInstance(store);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -101,13 +102,11 @@ public class DataSourceProviders {
|
||||
}
|
||||
|
||||
return (T) ALL.stream()
|
||||
.filter(d -> d.getId()
|
||||
.equals(name))
|
||||
.filter(d -> d.getId().equals(name))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Provider " + name + " not found"));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <C extends DataSource<?>, T extends DataSourceProvider<C>> T byDataSourceClass(Class<C> c) {
|
||||
if (ALL == null) {
|
||||
@@ -115,8 +114,7 @@ public class DataSourceProviders {
|
||||
}
|
||||
|
||||
return (T) ALL.stream()
|
||||
.filter(d -> d.getSourceClass()
|
||||
.equals(c))
|
||||
.filter(d -> d.getSourceClass().equals(c))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Provider for " + c.getSimpleName() + " not found"));
|
||||
}
|
||||
@@ -127,24 +125,21 @@ public class DataSourceProviders {
|
||||
}
|
||||
|
||||
return ALL.stream()
|
||||
.filter(d -> d.getPossibleNames()
|
||||
.stream()
|
||||
.anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name))) || d.getId().equalsIgnoreCase(name))
|
||||
.filter(d -> d.getPossibleNames().stream()
|
||||
.anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name)))
|
||||
|| d.getId().equalsIgnoreCase(name))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
private static List<String> nameAlternatives(String name) {
|
||||
var split = List.of(name.split("_"));
|
||||
return List.of(String.join(" ", split), String.join(
|
||||
"_", split
|
||||
), String.join(
|
||||
"-", split
|
||||
), split.stream()
|
||||
.map(s -> s.equals(split.get(0)) ?
|
||||
s :
|
||||
s.substring(0, 1)
|
||||
.toUpperCase() + s.substring(1))
|
||||
.collect(Collectors.joining()));
|
||||
return List.of(
|
||||
String.join(" ", split),
|
||||
String.join("_", split),
|
||||
String.join("-", split),
|
||||
split.stream()
|
||||
.map(s -> s.equals(split.get(0)) ? s : s.substring(0, 1).toUpperCase() + s.substring(1))
|
||||
.collect(Collectors.joining()));
|
||||
}
|
||||
|
||||
public static Optional<DataSourceProvider<?>> byPreferredStore(DataStore store, DataSourceType type) {
|
||||
@@ -153,7 +148,7 @@ public class DataSourceProviders {
|
||||
}
|
||||
|
||||
return ALL.stream()
|
||||
.filter(d -> type == null || d.getPrimaryType() == type)
|
||||
.filter(d -> type == null || d.getPrimaryType() == type)
|
||||
.filter(d -> d.getFileProvider() != null)
|
||||
.filter(d -> d.prefersStore(store, type))
|
||||
.findAny();
|
||||
|
||||
@@ -9,22 +9,16 @@ import java.util.List;
|
||||
|
||||
public interface DataStoreProvider {
|
||||
|
||||
enum Category {
|
||||
STREAM,
|
||||
MACHINE,
|
||||
DATABASE;
|
||||
}
|
||||
|
||||
default void validate() throws Exception {
|
||||
getCategory();
|
||||
for (Class<?> storeClass : getStoreClasses()) {
|
||||
if (!JacksonizedValue.class.isAssignableFrom(storeClass)) {
|
||||
throw new ExtensionException(String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName()));
|
||||
throw new ExtensionException(
|
||||
String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default Category getCategory() {
|
||||
var c = getStoreClasses().get(0);
|
||||
if (StreamDataStore.class.isAssignableFrom(c)) {
|
||||
@@ -97,6 +91,12 @@ public interface DataStoreProvider {
|
||||
List<Class<?>> getStoreClasses();
|
||||
|
||||
default DataFlow[] getPossibleFlows() {
|
||||
return new DataFlow[]{DataFlow.INPUT};
|
||||
return new DataFlow[] {DataFlow.INPUT};
|
||||
}
|
||||
|
||||
enum Category {
|
||||
STREAM,
|
||||
MACHINE,
|
||||
DATABASE;
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,7 @@ public class DataStoreProviders {
|
||||
p.validate();
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e)
|
||||
.handle();
|
||||
ErrorEvent.fromThrowable(e).handle();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -36,25 +35,27 @@ public class DataStoreProviders {
|
||||
throw new IllegalStateException("Not initialized");
|
||||
}
|
||||
|
||||
return ALL.stream().filter(d -> d.getPossibleNames().stream()
|
||||
.anyMatch(s -> s.equalsIgnoreCase(name))).findAny();
|
||||
return ALL.stream()
|
||||
.filter(d -> d.getPossibleNames().stream().anyMatch(s -> s.equalsIgnoreCase(name)))
|
||||
.findAny();
|
||||
}
|
||||
|
||||
|
||||
public static Optional<Dialog> byString(String s) {
|
||||
if (ALL == null) {
|
||||
throw new IllegalStateException("Not initialized");
|
||||
}
|
||||
|
||||
return ALL.stream().map(d -> {
|
||||
var store = d.storeForString(s);
|
||||
if (store != null) {
|
||||
return d.dialogForStore(store);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
).filter(Objects::nonNull).findAny();
|
||||
return ALL.stream()
|
||||
.map(d -> {
|
||||
var store = d.storeForString(s);
|
||||
if (store != null) {
|
||||
return d.dialogForStore(store);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.findAny();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -68,8 +69,8 @@ public class DataStoreProviders {
|
||||
throw new IllegalStateException("Not initialized");
|
||||
}
|
||||
|
||||
|
||||
return (Optional<T>) ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny();
|
||||
return (Optional<T>)
|
||||
ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny();
|
||||
}
|
||||
|
||||
public static List<DataStoreProvider> getAll() {
|
||||
|
||||
@@ -2,8 +2,7 @@ package io.xpipe.extension;
|
||||
|
||||
public class ExtensionException extends RuntimeException {
|
||||
|
||||
public ExtensionException() {
|
||||
}
|
||||
public ExtensionException() {}
|
||||
|
||||
public ExtensionException(String message) {
|
||||
super(message);
|
||||
|
||||
@@ -9,7 +9,6 @@ public interface I18n {
|
||||
|
||||
I18n INSTANCE = ServiceLoader.load(I18n.class).findFirst().orElseThrow();
|
||||
|
||||
|
||||
public static ObservableValue<String> observable(String s, Object... vars) {
|
||||
if (s == null) {
|
||||
return null;
|
||||
|
||||
@@ -9,32 +9,6 @@ import lombok.Value;
|
||||
|
||||
public interface SupportedApplicationProvider {
|
||||
|
||||
enum Category {
|
||||
PROGRAMMING_LANGUAGE,
|
||||
APPLICATION,
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum AccessType {
|
||||
ACTIVE,
|
||||
PASSIVE
|
||||
}
|
||||
|
||||
@Value
|
||||
@AllArgsConstructor
|
||||
public static class InstructionsDisplay {
|
||||
Region region;
|
||||
Runnable onFinish;
|
||||
Validator validator;
|
||||
|
||||
public InstructionsDisplay(Region region) {
|
||||
this.region = region;
|
||||
onFinish = null;
|
||||
validator = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default InstructionsDisplay createRetrievalInstructions(DataSource<?> source, ObservableValue<String> id) {
|
||||
return null;
|
||||
}
|
||||
@@ -60,5 +34,29 @@ public interface SupportedApplicationProvider {
|
||||
default boolean isApplicable(DataSource<?> source) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
enum Category {
|
||||
PROGRAMMING_LANGUAGE,
|
||||
APPLICATION,
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum AccessType {
|
||||
ACTIVE,
|
||||
PASSIVE
|
||||
}
|
||||
|
||||
@Value
|
||||
@AllArgsConstructor
|
||||
public static class InstructionsDisplay {
|
||||
Region region;
|
||||
Runnable onFinish;
|
||||
Validator validator;
|
||||
|
||||
public InstructionsDisplay(Region region) {
|
||||
this.region = region;
|
||||
onFinish = null;
|
||||
validator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ public class SupportedApplicationProviders {
|
||||
public static void loadAll(ModuleLayer layer) {
|
||||
if (ALL == null) {
|
||||
ALL = ServiceLoader.load(layer, SupportedApplicationProvider.class).stream()
|
||||
.map(ServiceLoader.Provider::get).collect(Collectors.toSet());
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@ public class CharChoiceComp extends Comp<CompStructure<HBox>> {
|
||||
private final Map<Character, ObservableValue<String>> range;
|
||||
private final ObservableValue<String> customName;
|
||||
|
||||
public CharChoiceComp(Property<Character> value, Map<Character, ObservableValue<String>> range, ObservableValue<String> customName) {
|
||||
public CharChoiceComp(
|
||||
Property<Character> value,
|
||||
Map<Character, ObservableValue<String>> range,
|
||||
ObservableValue<String> customName) {
|
||||
this.value = value;
|
||||
this.range = range;
|
||||
this.customName = customName;
|
||||
|
||||
@@ -18,11 +18,14 @@ public class CharsetChoiceComp extends SimpleComp {
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var builder = new CustomComboBoxBuilder<>(charset, streamCharset -> {
|
||||
return new Label(streamCharset.getCharset().displayName() + (streamCharset.hasByteOrderMark() ?
|
||||
" (BOM)" :
|
||||
""));
|
||||
}, new Label(I18n.get("extension.none")), null);
|
||||
var builder = new CustomComboBoxBuilder<>(
|
||||
charset,
|
||||
streamCharset -> {
|
||||
return new Label(streamCharset.getCharset().displayName()
|
||||
+ (streamCharset.hasByteOrderMark() ? " (BOM)" : ""));
|
||||
},
|
||||
new Label(I18n.get("extension.none")),
|
||||
null);
|
||||
builder.addHeader(I18n.get("extension.common"));
|
||||
for (var e : StreamCharset.COMMON) {
|
||||
builder.add(e);
|
||||
|
||||
@@ -17,10 +17,7 @@ import lombok.experimental.FieldDefaults;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FieldDefaults(
|
||||
makeFinal = true,
|
||||
level = AccessLevel.PRIVATE
|
||||
)
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
public class ChoiceComp<T> extends Comp<CompStructure<ComboBox<T>>> {
|
||||
|
||||
Property<T> value;
|
||||
@@ -54,7 +51,6 @@ public class ChoiceComp<T> extends Comp<CompStructure<ComboBox<T>>> {
|
||||
return found.getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public T fromString(String string) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -20,10 +20,7 @@ import lombok.experimental.FieldDefaults;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@FieldDefaults(
|
||||
makeFinal = true,
|
||||
level = AccessLevel.PRIVATE
|
||||
)
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor
|
||||
public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
|
||||
|
||||
@@ -54,7 +51,7 @@ public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
|
||||
var vbox = new VBox(transformer.apply(cb));
|
||||
vbox.setFillWidth(true);
|
||||
cb.prefWidthProperty().bind(vbox.widthProperty());
|
||||
cb.valueProperty().addListener((c,o,n) -> {
|
||||
cb.valueProperty().addListener((c, o, n) -> {
|
||||
if (n == null) {
|
||||
vbox.getChildren().remove(1);
|
||||
} else {
|
||||
@@ -78,7 +75,5 @@ public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
|
||||
return new SimpleCompStructure<>(vbox);
|
||||
}
|
||||
|
||||
public static record Entry(ObservableValue<String> name, Comp<?> comp) {
|
||||
|
||||
}
|
||||
public static record Entry(ObservableValue<String> name, Comp<?> comp) {}
|
||||
}
|
||||
@@ -9,21 +9,7 @@ import java.util.stream.Collectors;
|
||||
public record CodeSnippet(List<CodeSnippet.Line> lines) {
|
||||
|
||||
public static final ColorScheme LIGHT_MODE = new ColorScheme(
|
||||
Color.valueOf("0033B3"),
|
||||
Color.valueOf("000000"),
|
||||
Color.valueOf("000000"),
|
||||
Color.valueOf("067D17")
|
||||
);
|
||||
|
||||
public String toString() {
|
||||
return getRawString();
|
||||
}
|
||||
|
||||
public String getRawString() {
|
||||
return lines.stream().map(line -> line.elements().stream()
|
||||
.map(Element::text).collect(Collectors.joining()))
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
Color.valueOf("0033B3"), Color.valueOf("000000"), Color.valueOf("000000"), Color.valueOf("067D17"));
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder(LIGHT_MODE);
|
||||
@@ -33,6 +19,16 @@ public record CodeSnippet(List<CodeSnippet.Line> lines) {
|
||||
return new Builder(scheme);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getRawString();
|
||||
}
|
||||
|
||||
public String getRawString() {
|
||||
return lines.stream()
|
||||
.map(line -> line.elements().stream().map(Element::text).collect(Collectors.joining()))
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
|
||||
public static interface Element {
|
||||
|
||||
String text();
|
||||
@@ -124,11 +120,7 @@ public record CodeSnippet(List<CodeSnippet.Line> lines) {
|
||||
}
|
||||
}
|
||||
|
||||
public static record Line(List<CodeSnippet.Element> elements) {
|
||||
}
|
||||
public static record Line(List<CodeSnippet.Element> elements) {}
|
||||
|
||||
public static record ColorScheme(
|
||||
Color keyword, Color identifier, Color type, Color string) {
|
||||
|
||||
}
|
||||
public static record ColorScheme(Color keyword, Color identifier, Color type, Color string) {}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
||||
|
||||
public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
|
||||
|
||||
private final ObservableValue<Boolean> showLineNumbers;
|
||||
@@ -36,10 +35,9 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
|
||||
}
|
||||
|
||||
private static String toRGBCode(Color color) {
|
||||
return String.format("#%02X%02X%02X",
|
||||
(int) (color.getRed() * 255),
|
||||
(int) (color.getGreen() * 255),
|
||||
(int) (color.getBlue() * 255));
|
||||
return String.format(
|
||||
"#%02X%02X%02X",
|
||||
(int) (color.getRed() * 255), (int) (color.getGreen() * 255), (int) (color.getBlue() * 255));
|
||||
}
|
||||
|
||||
private void fillArea(VBox lineNumbers, InlineCssTextArea s) {
|
||||
@@ -94,7 +92,7 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
|
||||
var lineNumbers = new VBox();
|
||||
lineNumbers.getStyleClass().add("line-numbers");
|
||||
fillArea(lineNumbers, s);
|
||||
value.addListener((c,o,n) -> {
|
||||
value.addListener((c, o, n) -> {
|
||||
fillArea(lineNumbers, s);
|
||||
});
|
||||
|
||||
@@ -107,7 +105,7 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
|
||||
content.getChildren().add(0, lineNumbers);
|
||||
content.getChildren().add(1, spacer);
|
||||
}
|
||||
showLineNumbers.addListener((c,o,n) -> {
|
||||
showLineNumbers.addListener((c, o, n) -> {
|
||||
if (n) {
|
||||
content.getChildren().add(0, lineNumbers);
|
||||
content.getChildren().add(1, spacer);
|
||||
|
||||
@@ -24,10 +24,15 @@ public class DataStoreFlowChoiceComp extends SimpleComp {
|
||||
map.put(DataFlow.INPUT, I18n.observable("extension.input"));
|
||||
map.put(DataFlow.OUTPUT, I18n.observable("extension.output"));
|
||||
map.put(DataFlow.INPUT_OUTPUT, I18n.observable("extension.inout"));
|
||||
return new ToggleGroupComp<>(selected, map).apply(struc -> {
|
||||
new FancyTooltipAugment<>("extension.inputDescription").augment(struc.get().getChildren().get(0));
|
||||
new FancyTooltipAugment<>("extension.outputDescription").augment(struc.get().getChildren().get(1));
|
||||
new FancyTooltipAugment<>("extension.inoutDescription").augment(struc.get().getChildren().get(2));
|
||||
}).createRegion();
|
||||
return new ToggleGroupComp<>(selected, map)
|
||||
.apply(struc -> {
|
||||
new FancyTooltipAugment<>("extension.inputDescription")
|
||||
.augment(struc.get().getChildren().get(0));
|
||||
new FancyTooltipAugment<>("extension.outputDescription")
|
||||
.augment(struc.get().getChildren().get(1));
|
||||
new FancyTooltipAugment<>("extension.inoutDescription")
|
||||
.augment(struc.get().getChildren().get(2));
|
||||
})
|
||||
.createRegion();
|
||||
}
|
||||
}
|
||||
@@ -68,25 +68,35 @@ public class DynamicOptionsComp extends Comp<CompStructure<FlowPane>> {
|
||||
}
|
||||
|
||||
if (wrap) {
|
||||
var compWidthBinding = Bindings.createDoubleBinding(() -> {
|
||||
if (compRegions.stream().anyMatch(r -> r.getWidth() == 0)) {
|
||||
return Region.USE_COMPUTED_SIZE;
|
||||
}
|
||||
var compWidthBinding = Bindings.createDoubleBinding(
|
||||
() -> {
|
||||
if (compRegions.stream().anyMatch(r -> r.getWidth() == 0)) {
|
||||
return Region.USE_COMPUTED_SIZE;
|
||||
}
|
||||
|
||||
var m = compRegions.stream().map(Region::getWidth).max(Double::compareTo).orElse(0.0);
|
||||
return m;
|
||||
}, compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
|
||||
var m = compRegions.stream()
|
||||
.map(Region::getWidth)
|
||||
.max(Double::compareTo)
|
||||
.orElse(0.0);
|
||||
return m;
|
||||
},
|
||||
compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
|
||||
compRegions.forEach(r -> r.prefWidthProperty().bind(compWidthBinding));
|
||||
}
|
||||
|
||||
var nameWidthBinding = Bindings.createDoubleBinding(() -> {
|
||||
if (nameRegions.stream().anyMatch(r -> r.getWidth() == 0)) {
|
||||
return Region.USE_COMPUTED_SIZE;
|
||||
}
|
||||
var nameWidthBinding = Bindings.createDoubleBinding(
|
||||
() -> {
|
||||
if (nameRegions.stream().anyMatch(r -> r.getWidth() == 0)) {
|
||||
return Region.USE_COMPUTED_SIZE;
|
||||
}
|
||||
|
||||
var m = nameRegions.stream().map(Region::getWidth).max(Double::compareTo).orElse(0.0);
|
||||
return m;
|
||||
}, nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
|
||||
var m = nameRegions.stream()
|
||||
.map(Region::getWidth)
|
||||
.max(Double::compareTo)
|
||||
.orElse(0.0);
|
||||
return m;
|
||||
},
|
||||
nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
|
||||
nameRegions.forEach(r -> r.prefWidthProperty().bind(nameWidthBinding));
|
||||
|
||||
return new SimpleCompStructure<>(flow);
|
||||
@@ -96,7 +106,5 @@ public class DynamicOptionsComp extends Comp<CompStructure<FlowPane>> {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static record Entry(ObservableValue<String> name, Comp<?> comp) {
|
||||
|
||||
}
|
||||
public static record Entry(ObservableValue<String> name, Comp<?> comp) {}
|
||||
}
|
||||
@@ -44,12 +44,12 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
|
||||
tt.getStyleClass().add("fancy-tooltip");
|
||||
}
|
||||
|
||||
|
||||
public void augment(Node region) {
|
||||
var tt = new FocusTooltip();
|
||||
var toDisplay = text.getValue();
|
||||
if (Shortcuts.getShortcut((Region) region) != null) {
|
||||
toDisplay = toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")";
|
||||
toDisplay =
|
||||
toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")";
|
||||
}
|
||||
tt.textProperty().setValue(toDisplay);
|
||||
tt.setStyle("-fx-font-size: 11pt;");
|
||||
@@ -61,8 +61,7 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
|
||||
|
||||
private static class FocusTooltip extends JFXTooltip {
|
||||
|
||||
public FocusTooltip() {
|
||||
}
|
||||
public FocusTooltip() {}
|
||||
|
||||
public FocusTooltip(String string) {
|
||||
super(string);
|
||||
|
||||
@@ -16,26 +16,12 @@ import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
public class FilterComp extends Comp<FilterComp.Structure> {
|
||||
|
||||
private final Property<String> filterText;
|
||||
|
||||
public FilterComp(Property<String> filterText) {
|
||||
this.filterText = filterText;
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class Structure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
Node inactiveIcon;
|
||||
Label inactiveText;
|
||||
TextField text;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
|
||||
private final Property<String> filterText;
|
||||
|
||||
@Override
|
||||
public Structure createBase() {
|
||||
var fi = new FontIcon("mdi2m-magnify");
|
||||
@@ -50,12 +36,34 @@ public class FilterComp extends Comp<FilterComp.Structure> {
|
||||
filterText.setValue(newValue);
|
||||
});
|
||||
|
||||
bgLabel.visibleProperty().bind(Bindings.createBooleanBinding(() -> (filter.getText() == null || filter.getText().isEmpty()),
|
||||
filter.textProperty(), filter.focusedProperty()));
|
||||
bgLabel.visibleProperty()
|
||||
.bind(Bindings.createBooleanBinding(
|
||||
() -> (filter.getText() == null || filter.getText().isEmpty()),
|
||||
filter.textProperty(),
|
||||
filter.focusedProperty()));
|
||||
|
||||
var stack = new StackPane(bgLabel, filter);
|
||||
stack.getStyleClass().add("filter-comp");
|
||||
|
||||
return Structure.builder().inactiveIcon(fi).inactiveText(bgLabel).text(filter).pane(stack).build();
|
||||
return Structure.builder()
|
||||
.inactiveIcon(fi)
|
||||
.inactiveText(bgLabel)
|
||||
.text(filter)
|
||||
.pane(stack)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class Structure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
Node inactiveIcon;
|
||||
Label inactiveText;
|
||||
TextField text;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,7 @@ import javafx.scene.input.KeyEvent;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
@FieldDefaults(
|
||||
makeFinal = true,
|
||||
level = AccessLevel.PRIVATE
|
||||
)
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
public class IntFieldComp extends Comp<CompStructure<TextField>> {
|
||||
|
||||
Property<Integer> value;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
package io.xpipe.extension.comp;
|
||||
|
||||
public class MultiVariantComp {
|
||||
}
|
||||
public class MultiVariantComp {}
|
||||
@@ -22,7 +22,17 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Getter
|
||||
public class SvgComp {
|
||||
public class SvgComp {
|
||||
|
||||
private final ObservableValue<Number> width;
|
||||
private final ObservableValue<Number> height;
|
||||
private final ObservableValue<String> svgContent;
|
||||
|
||||
public SvgComp(ObservableValue<Number> width, ObservableValue<Number> height, ObservableValue<String> svgContent) {
|
||||
this.width = PlatformThread.sync(width);
|
||||
this.height = PlatformThread.sync(height);
|
||||
this.svgContent = PlatformThread.sync(svgContent);
|
||||
}
|
||||
|
||||
private static Size parseSize(String string) {
|
||||
for (SizeUnits unit : SizeUnits.values()) {
|
||||
@@ -57,28 +67,6 @@ public class SvgComp {
|
||||
return new SvgComp(widthProperty, heightProperty, content);
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class Structure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
WebView webView;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
|
||||
private final ObservableValue<Number> width;
|
||||
private final ObservableValue<Number> height;
|
||||
private final ObservableValue<String> svgContent;
|
||||
|
||||
public SvgComp(ObservableValue<Number> width, ObservableValue<Number> height, ObservableValue<String> svgContent) {
|
||||
this.width = PlatformThread.sync(width);
|
||||
this.height = PlatformThread.sync(height);
|
||||
this.svgContent = PlatformThread.sync(svgContent);
|
||||
}
|
||||
|
||||
private String getHtml(String content) {
|
||||
return "<html><body style='margin: 0; padding: 0; border: none;' >" + content + "</body></html>";
|
||||
}
|
||||
@@ -115,10 +103,21 @@ public class SvgComp {
|
||||
return wv;
|
||||
}
|
||||
|
||||
|
||||
public WebView createWebview() {
|
||||
var wv = createWebView();
|
||||
wv.getStyleClass().add("svg-comp");
|
||||
wv.getStyleClass().add("svg-comp");
|
||||
return wv;
|
||||
}
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public static class Structure implements CompStructure<StackPane> {
|
||||
StackPane pane;
|
||||
WebView webView;
|
||||
|
||||
@Override
|
||||
public StackPane get() {
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,13 @@ import java.util.List;
|
||||
@Getter
|
||||
public class TabPaneComp extends Comp<CompStructure<JFXTabPane>> {
|
||||
|
||||
private final Property<Entry> selected;
|
||||
private final List<Entry> entries;
|
||||
public TabPaneComp(Property<Entry> selected, List<Entry> entries) {
|
||||
this.selected = selected;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompStructure<JFXTabPane> createBase() {
|
||||
JFXTabPane tabPane = new JFXTabPane();
|
||||
@@ -40,10 +47,10 @@ public class TabPaneComp extends Comp<CompStructure<JFXTabPane>> {
|
||||
}
|
||||
|
||||
tabPane.getSelectionModel().select(entries.indexOf(selected.getValue()));
|
||||
tabPane.getSelectionModel().selectedIndexProperty().addListener((c,o,n) -> {
|
||||
tabPane.getSelectionModel().selectedIndexProperty().addListener((c, o, n) -> {
|
||||
selected.setValue(entries.get(n.intValue()));
|
||||
});
|
||||
selected.addListener((c,o,n) -> {
|
||||
selected.addListener((c, o, n) -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
tabPane.getSelectionModel().select(entries.indexOf(n));
|
||||
});
|
||||
@@ -52,15 +59,5 @@ public class TabPaneComp extends Comp<CompStructure<JFXTabPane>> {
|
||||
return new SimpleCompStructure<>(tabPane);
|
||||
}
|
||||
|
||||
private final Property<Entry> selected;
|
||||
private final List<Entry> entries;
|
||||
|
||||
public TabPaneComp(Property<Entry> selected, List<Entry> entries) {
|
||||
this.selected = selected;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public static record Entry(ObservableValue<String> name, String graphic, Comp<?> comp) {
|
||||
|
||||
}
|
||||
public static record Entry(ObservableValue<String> name, String graphic, Comp<?> comp) {}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ public class TextFieldComp extends Comp<CompStructure<TextField>> {
|
||||
public TextFieldComp(Property<String> value) {
|
||||
this.value = value;
|
||||
this.lazyValue = value;
|
||||
|
||||
}
|
||||
|
||||
public TextFieldComp(Property<String> value, Property<String> lazyValue) {
|
||||
|
||||
@@ -49,8 +49,7 @@ public class ToggleGroupComp<T> extends Comp<CompStructure<HBox>> {
|
||||
box.getChildren().get(box.getChildren().size() - 1).getStyleClass().add("last");
|
||||
|
||||
group.selectedToggleProperty().addListener((obsVal, oldVal, newVal) -> {
|
||||
if (newVal == null)
|
||||
oldVal.setSelected(true);
|
||||
if (newVal == null) oldVal.setSelected(true);
|
||||
});
|
||||
|
||||
return new SimpleCompStructure<>(box);
|
||||
|
||||
@@ -26,18 +26,18 @@ public class WriteModeChoiceComp extends SimpleComp implements Validatable {
|
||||
Validator validator = new SimpleValidator();
|
||||
Check check;
|
||||
|
||||
public WriteModeChoiceComp(Property<WriteMode> selected, WriteMode[] available) {
|
||||
this.selected = selected;
|
||||
this.available = available;
|
||||
if (available.length == 1) {
|
||||
selected.setValue(available[0]);
|
||||
}
|
||||
check = Validators.nonNull(validator, I18n.observable("mode"), selected);
|
||||
}
|
||||
public WriteModeChoiceComp(Property<WriteMode> selected, WriteMode[] available) {
|
||||
this.selected = selected;
|
||||
this.available = available;
|
||||
if (available.length == 1) {
|
||||
selected.setValue(available[0]);
|
||||
}
|
||||
check = Validators.nonNull(validator, I18n.observable("mode"), selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var a = Arrays.asList(available);
|
||||
var a = Arrays.asList(available);
|
||||
var map = new LinkedHashMap<WriteMode, ObservableValue<String>>();
|
||||
var replaceIndex = -1;
|
||||
if (a.contains(WriteMode.REPLACE)) {
|
||||
@@ -60,10 +60,19 @@ public class WriteModeChoiceComp extends SimpleComp implements Validatable {
|
||||
int finalReplaceIndex = replaceIndex;
|
||||
int finalAppendIndex = appendIndex;
|
||||
int finalPrependIndex = prependIndex;
|
||||
return new ToggleGroupComp<>(selected, map).apply(struc -> {
|
||||
if (finalReplaceIndex != -1) new FancyTooltipAugment<>("extension.replaceDescription").augment(struc.get().getChildren().get(0));
|
||||
if (finalAppendIndex != -1) new FancyTooltipAugment<>("extension.appendDescription").augment(struc.get().getChildren().get(finalAppendIndex));
|
||||
if (finalPrependIndex != -1) new FancyTooltipAugment<>("extension.prependDescription").augment(struc.get().getChildren().get(finalPrependIndex));
|
||||
}).apply(struc -> check.decorates(struc.get())).createRegion();
|
||||
return new ToggleGroupComp<>(selected, map)
|
||||
.apply(struc -> {
|
||||
if (finalReplaceIndex != -1)
|
||||
new FancyTooltipAugment<>("extension.replaceDescription")
|
||||
.augment(struc.get().getChildren().get(0));
|
||||
if (finalAppendIndex != -1)
|
||||
new FancyTooltipAugment<>("extension.appendDescription")
|
||||
.augment(struc.get().getChildren().get(finalAppendIndex));
|
||||
if (finalPrependIndex != -1)
|
||||
new FancyTooltipAugment<>("extension.prependDescription")
|
||||
.augment(struc.get().getChildren().get(finalPrependIndex));
|
||||
})
|
||||
.apply(struc -> check.decorates(struc.get()))
|
||||
.createRegion();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,42 @@ import java.util.List;
|
||||
@Getter
|
||||
public class ErrorEvent {
|
||||
|
||||
private final List<TrackEvent> trackEvents = EventHandler.get().snapshotEvents();
|
||||
private String description;
|
||||
private boolean terminal;
|
||||
@Builder.Default
|
||||
private boolean omitted = false;
|
||||
@Builder.Default
|
||||
private boolean reportable = true;
|
||||
private Throwable throwable;
|
||||
@Singular
|
||||
private List<Path> attachments;
|
||||
|
||||
public static ErrorEventBuilder fromThrowable(Throwable t) {
|
||||
return builder().throwable(t).description(ExceptionConverter.convertMessage(t));
|
||||
}
|
||||
|
||||
public static ErrorEventBuilder fromThrowable(String msg, Throwable t) {
|
||||
return builder().throwable(t).description(msg);
|
||||
}
|
||||
|
||||
public static ErrorEventBuilder fromMessage(String msg) {
|
||||
return builder().description(msg);
|
||||
}
|
||||
|
||||
public void handle() {
|
||||
EventHandler.get().handle(this);
|
||||
}
|
||||
|
||||
public void addAttachment(Path file) {
|
||||
attachments = new ArrayList<>(attachments);
|
||||
attachments.add(file);
|
||||
}
|
||||
|
||||
public void clearAttachments() {
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static class ErrorEventBuilder {
|
||||
|
||||
public ErrorEventBuilder omit() {
|
||||
@@ -22,49 +58,4 @@ public class ErrorEvent {
|
||||
build().handle();
|
||||
}
|
||||
}
|
||||
|
||||
public static ErrorEventBuilder fromThrowable(Throwable t) {
|
||||
return builder().throwable(t)
|
||||
.description(ExceptionConverter.convertMessage(t));
|
||||
}
|
||||
|
||||
public static ErrorEventBuilder fromThrowable(String msg, Throwable t) {
|
||||
return builder().throwable(t)
|
||||
.description(msg);
|
||||
}
|
||||
|
||||
public static ErrorEventBuilder fromMessage(String msg) {
|
||||
return builder()
|
||||
.description(msg);
|
||||
}
|
||||
|
||||
public void handle() {
|
||||
EventHandler.get().handle(this);
|
||||
}
|
||||
|
||||
private String description;
|
||||
|
||||
private boolean terminal;
|
||||
|
||||
@Builder.Default
|
||||
private boolean omitted = false;
|
||||
|
||||
@Builder.Default
|
||||
private boolean reportable = true;
|
||||
|
||||
private Throwable throwable;
|
||||
|
||||
@Singular
|
||||
private List<Path> attachments;
|
||||
|
||||
private final List<TrackEvent> trackEvents = EventHandler.get().snapshotEvents();
|
||||
|
||||
public void addAttachment(Path file) {
|
||||
attachments = new ArrayList<>(attachments);
|
||||
attachments.add(file);
|
||||
}
|
||||
|
||||
public void clearAttachments() {
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ public class ExceptionConverter {
|
||||
return I18n.get("extension.unsupportedOperation", msg);
|
||||
}
|
||||
|
||||
|
||||
if (ex instanceof ClassNotFoundException) {
|
||||
return I18n.get("extension.classNotFound", msg);
|
||||
}
|
||||
|
||||
@@ -13,27 +13,15 @@ import java.util.Map;
|
||||
@Getter
|
||||
public class TrackEvent {
|
||||
|
||||
public static class TrackEventBuilder {
|
||||
|
||||
public TrackEventBuilder windowCategory() {
|
||||
this.category("window");
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackEventBuilder copy() {
|
||||
var copy = builder();
|
||||
copy.category = category;
|
||||
copy.message = message;
|
||||
copy.tags$key = new ArrayList<>(tags$key);
|
||||
copy.tags$value = new ArrayList<>(tags$value);
|
||||
copy.type = type;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void handle() {
|
||||
build().handle();
|
||||
}
|
||||
}
|
||||
private final Thread thread = Thread.currentThread();
|
||||
private final Instant instant = Instant.now();
|
||||
private String type;
|
||||
private String message;
|
||||
private String category;
|
||||
@Singular
|
||||
private Map<String, Object> tags;
|
||||
@Singular
|
||||
private List<String> elements;
|
||||
|
||||
public static TrackEventBuilder fromMessage(String type, String message) {
|
||||
return builder().type(type).message(message);
|
||||
@@ -99,28 +87,13 @@ public class TrackEvent {
|
||||
builder().type("error").message(message).build().handle();
|
||||
}
|
||||
|
||||
private final Thread thread = Thread.currentThread();
|
||||
private final Instant instant = Instant.now();
|
||||
|
||||
private String type;
|
||||
|
||||
private String message;
|
||||
|
||||
private String category;
|
||||
|
||||
@Singular
|
||||
private Map<String, Object> tags;
|
||||
|
||||
@Singular
|
||||
private List<String> elements;
|
||||
|
||||
public void handle() {
|
||||
EventHandler.get().handle(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
var s = message;
|
||||
var s = message;
|
||||
if (tags.size() > 0) {
|
||||
s += " {\n";
|
||||
for (var e : tags.entrySet()) {
|
||||
@@ -130,4 +103,26 @@ public class TrackEvent {
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static class TrackEventBuilder {
|
||||
|
||||
public TrackEventBuilder windowCategory() {
|
||||
this.category("window");
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackEventBuilder copy() {
|
||||
var copy = builder();
|
||||
copy.category = category;
|
||||
copy.message = message;
|
||||
copy.tags$key = new ArrayList<>(tags$key);
|
||||
copy.tags$value = new ArrayList<>(tags$value);
|
||||
copy.type = type;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void handle() {
|
||||
build().handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,5 @@ package io.xpipe.extension.prefs;
|
||||
|
||||
public interface PrefsHandler {
|
||||
|
||||
// void addSetting(List<String> category, String group, Setting<?,?> setting);
|
||||
// void addSetting(List<String> category, String group, Setting<?,?> setting);
|
||||
}
|
||||
@@ -11,7 +11,8 @@ public class PrefsProviders {
|
||||
public static void init(ModuleLayer layer) {
|
||||
if (ALL == null) {
|
||||
ALL = ServiceLoader.load(layer, PrefsProvider.class).stream()
|
||||
.map(ServiceLoader.Provider::get).collect(Collectors.toSet());
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,17 +18,18 @@ import java.util.stream.Collectors;
|
||||
public class ChainedValidator implements Validator {
|
||||
|
||||
private final List<Validator> validators;
|
||||
private final ReadOnlyObjectWrapper<ValidationResult> validationResultProperty = new ReadOnlyObjectWrapper<>(new ValidationResult());
|
||||
private final ReadOnlyObjectWrapper<ValidationResult> validationResultProperty =
|
||||
new ReadOnlyObjectWrapper<>(new ValidationResult());
|
||||
private final ReadOnlyBooleanWrapper containsErrorsProperty = new ReadOnlyBooleanWrapper();
|
||||
|
||||
public ChainedValidator(List<Validator> validators) {
|
||||
this.validators = validators;
|
||||
validators.forEach(v -> {
|
||||
v.containsErrorsProperty().addListener((c,o,n) -> {
|
||||
v.containsErrorsProperty().addListener((c, o, n) -> {
|
||||
containsErrorsProperty.set(containsErrors());
|
||||
});
|
||||
|
||||
v.validationResultProperty().addListener((c,o,n) -> {
|
||||
v.validationResultProperty().addListener((c, o, n) -> {
|
||||
validationResultProperty.set(getValidationResult());
|
||||
});
|
||||
});
|
||||
@@ -94,10 +95,15 @@ public class ChainedValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public StringBinding createStringBinding(String prefix, String separator) {
|
||||
var list = new ArrayList<Observable>(validators.stream().map(Validator::createStringBinding).toList());
|
||||
var list = new ArrayList<Observable>(
|
||||
validators.stream().map(Validator::createStringBinding).toList());
|
||||
Observable[] observables = list.toArray(Observable[]::new);
|
||||
return Bindings.createStringBinding(() -> {
|
||||
return validators.stream().map(v -> v.createStringBinding(prefix, separator).get()).collect(Collectors.joining("\n"));
|
||||
}, observables);
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
return validators.stream()
|
||||
.map(v -> v.createStringBinding(prefix, separator).get())
|
||||
.collect(Collectors.joining("\n"));
|
||||
},
|
||||
observables);
|
||||
}
|
||||
}
|
||||
@@ -31,11 +31,19 @@ public class CustomComboBoxBuilder<T> {
|
||||
private final Set<Node> disabledNodes = new HashSet<>();
|
||||
private final Node emptyNode;
|
||||
private final Predicate<T> veto;
|
||||
private BiPredicate<T, String> filterPredicate;
|
||||
private final Property<String> filterString = new SimpleStringProperty();
|
||||
private final List<T> filterable = new ArrayList<>();
|
||||
private BiPredicate<T, String> filterPredicate;
|
||||
private Node filterNode;
|
||||
|
||||
public CustomComboBoxBuilder(
|
||||
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto) {
|
||||
this.selected = selected;
|
||||
this.nodeFunction = nodeFunction;
|
||||
this.emptyNode = emptyNode;
|
||||
this.veto = veto;
|
||||
}
|
||||
|
||||
public void addAction(Node node, Runnable run) {
|
||||
nodes.add(node);
|
||||
actionsMap.put(node, run);
|
||||
@@ -80,13 +88,6 @@ public class CustomComboBoxBuilder<T> {
|
||||
filterNode = header.getText();
|
||||
}
|
||||
|
||||
public CustomComboBoxBuilder(Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto) {
|
||||
this.selected = selected;
|
||||
this.nodeFunction = nodeFunction;
|
||||
this.emptyNode = emptyNode;
|
||||
this.veto = veto;
|
||||
}
|
||||
|
||||
public ComboBox<Node> build() {
|
||||
var cb = new ComboBox<Node>();
|
||||
cb.getItems().addAll(nodes);
|
||||
@@ -95,7 +96,11 @@ public class CustomComboBoxBuilder<T> {
|
||||
});
|
||||
cb.setButtonCell(new SelectedCell());
|
||||
SimpleChangeListener.apply(selected, c -> {
|
||||
var item = nodeMap.entrySet().stream().filter(e -> e.getValue() != null && e.getValue().equals(c)).map(e -> e.getKey()).findAny().orElse(null);
|
||||
var item = nodeMap.entrySet().stream()
|
||||
.filter(e -> e.getValue() != null && e.getValue().equals(c))
|
||||
.map(e -> e.getKey())
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
cb.setValue(Optional.ofNullable(item).orElse(emptyNode));
|
||||
});
|
||||
cb.valueProperty().addListener((c, o, n) -> {
|
||||
@@ -115,8 +120,13 @@ public class CustomComboBoxBuilder<T> {
|
||||
if (filterPredicate != null) {
|
||||
|
||||
SimpleChangeListener.apply(filterString, c -> {
|
||||
var filteredNodes = nodes.stream().filter(e -> e.equals(cb.getValue()) || !(nodeMap.get(e) != null && (
|
||||
filterable.contains(nodeMap.get(e)) && filterString.getValue() != null && !filterPredicate.test(nodeMap.get(e), c)))).toList();
|
||||
var filteredNodes = nodes.stream()
|
||||
.filter(e -> e.equals(cb.getValue())
|
||||
|| !(nodeMap.get(e) != null
|
||||
&& (filterable.contains(nodeMap.get(e))
|
||||
&& filterString.getValue() != null
|
||||
&& !filterPredicate.test(nodeMap.get(e), c))))
|
||||
.toList();
|
||||
cb.setItems(FXCollections.observableList(filteredNodes));
|
||||
});
|
||||
|
||||
@@ -125,17 +135,13 @@ public class CustomComboBoxBuilder<T> {
|
||||
n.getWindow().focusedProperty().addListener((c2, o2, n2) -> {
|
||||
Platform.runLater(() -> {
|
||||
filterNode.requestFocus();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
filterNode.requestFocus();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return cb;
|
||||
@@ -182,8 +188,8 @@ public class CustomComboBoxBuilder<T> {
|
||||
setGraphic(item);
|
||||
if (disabledNodes.contains(item)) {
|
||||
this.setDisable(true);
|
||||
// this.setPadding(Insets.EMPTY);
|
||||
}else {
|
||||
// this.setPadding(Insets.EMPTY);
|
||||
} else {
|
||||
this.setDisable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,6 @@ import java.util.function.Predicate;
|
||||
|
||||
public class DialogHelper {
|
||||
|
||||
@Value
|
||||
public static class Address {
|
||||
String hostname;
|
||||
Integer port;
|
||||
}
|
||||
|
||||
public static Dialog addressQuery(Address address) {
|
||||
var hostNameQuery = Dialog.query("Hostname", false, true, false, address.getHostname(), QueryConverter.STRING);
|
||||
var portQuery = Dialog.query("Port", false, true, false, address.getPort(), QueryConverter.INTEGER);
|
||||
@@ -27,17 +21,14 @@ public class DialogHelper {
|
||||
}
|
||||
|
||||
public static Dialog machineQuery(DataStore store) {
|
||||
var storeName = XPipeDaemon.getInstance()
|
||||
.getStoreName(store)
|
||||
.orElse("local");
|
||||
var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local");
|
||||
return Dialog.query("Machine", false, true, false, storeName, QueryConverter.STRING)
|
||||
.map((String name) -> {
|
||||
if (name.equals("local")) {
|
||||
return new LocalStore();
|
||||
}
|
||||
|
||||
var stored = XPipeDaemon.getInstance()
|
||||
.getNamedStore(name);
|
||||
var stored = XPipeDaemon.getInstance().getNamedStore(name);
|
||||
if (stored.isEmpty()) {
|
||||
throw new IllegalArgumentException(String.format("Store not found: %s", name));
|
||||
}
|
||||
@@ -55,17 +46,14 @@ public class DialogHelper {
|
||||
}
|
||||
|
||||
public static Dialog shellQuery(DataStore store) {
|
||||
var storeName = XPipeDaemon.getInstance()
|
||||
.getStoreName(store)
|
||||
.orElse("local");
|
||||
var storeName = XPipeDaemon.getInstance().getStoreName(store).orElse("local");
|
||||
return Dialog.query("Shell", false, true, false, storeName, QueryConverter.STRING)
|
||||
.map((String name) -> {
|
||||
if (name.equals("local")) {
|
||||
return new LocalStore();
|
||||
}
|
||||
|
||||
var stored = XPipeDaemon.getInstance()
|
||||
.getNamedStore(name);
|
||||
var stored = XPipeDaemon.getInstance().getNamedStore(name);
|
||||
if (stored.isEmpty()) {
|
||||
throw new IllegalArgumentException(String.format("Store not found: %s", name));
|
||||
}
|
||||
@@ -78,16 +66,15 @@ public class DialogHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static Dialog charsetQuery(StreamCharset c, boolean all) {
|
||||
return Dialog.query("Charset", false, true, c != null &&!all, c, QueryConverter.CHARSET);
|
||||
public static Dialog charsetQuery(StreamCharset c, boolean all) {
|
||||
return Dialog.query("Charset", false, true, c != null && !all, c, QueryConverter.CHARSET);
|
||||
}
|
||||
|
||||
public static Dialog newLineQuery(NewLine n, boolean all) {
|
||||
return Dialog.query("Newline", false, true, n != null &&!all, n, QueryConverter.NEW_LINE);
|
||||
return Dialog.query("Newline", false, true, n != null && !all, n, QueryConverter.NEW_LINE);
|
||||
}
|
||||
|
||||
|
||||
public static <T> Dialog query(String desc, T value, boolean required, QueryConverter<T> c, boolean all) {
|
||||
public static <T> Dialog query(String desc, T value, boolean required, QueryConverter<T> c, boolean all) {
|
||||
return Dialog.query(desc, false, required, value != null && !all, value, c);
|
||||
}
|
||||
|
||||
@@ -100,14 +87,10 @@ public class DialogHelper {
|
||||
}
|
||||
|
||||
public static Dialog namedStoreQuery(DataStore store, Class<? extends DataStore> filter) {
|
||||
var name = XPipeDaemon.getInstance()
|
||||
.getStoreName(store)
|
||||
.orElse(null);
|
||||
var name = XPipeDaemon.getInstance().getStoreName(store).orElse(null);
|
||||
return Dialog.query("Store", false, true, false, name, QueryConverter.STRING)
|
||||
.map((String newName) -> {
|
||||
var found = XPipeDaemon.getInstance()
|
||||
.getNamedStore(newName)
|
||||
.orElseThrow();
|
||||
var found = XPipeDaemon.getInstance().getNamedStore(newName).orElseThrow();
|
||||
if (!filter.isAssignableFrom(found.getClass())) {
|
||||
throw new IllegalArgumentException("Incompatible store type");
|
||||
}
|
||||
@@ -116,14 +99,10 @@ public class DialogHelper {
|
||||
}
|
||||
|
||||
public static Dialog sourceQuery(DataSource<?> source, Predicate<DataSource<?>> filter) {
|
||||
var id = XPipeDaemon.getInstance()
|
||||
.getSourceId(source)
|
||||
.orElse(null);
|
||||
var id = XPipeDaemon.getInstance().getSourceId(source).orElse(null);
|
||||
return Dialog.query("Source Id", false, true, false, id, QueryConverter.STRING)
|
||||
.map((String newName) -> {
|
||||
var found = XPipeDaemon.getInstance()
|
||||
.getSource(newName)
|
||||
.orElseThrow();
|
||||
var found = XPipeDaemon.getInstance().getSource(newName).orElseThrow();
|
||||
if (!filter.test(found)) {
|
||||
throw new IllegalArgumentException("Incompatible store type");
|
||||
}
|
||||
@@ -139,4 +118,9 @@ public class DialogHelper {
|
||||
return Dialog.query("Timeout", false, true, false, timeout, QueryConverter.INTEGER);
|
||||
}
|
||||
|
||||
@Value
|
||||
public static class Address {
|
||||
String hostname;
|
||||
Integer port;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class DynamicOptionsBuilder {
|
||||
|
||||
private final List<DynamicOptionsComp.Entry> entries = new ArrayList<>();
|
||||
private final List<DynamicOptionsComp.Entry> entries = new ArrayList<>();
|
||||
private final List<Property<?>> props = new ArrayList<>();
|
||||
private final List<Property<?>> lazyProperties = new ArrayList<>();
|
||||
|
||||
@@ -42,12 +42,14 @@ public class DynamicOptionsBuilder {
|
||||
this.wrap = false;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder addTitle(String titleKey) {
|
||||
return addTitle(I18n.observable(titleKey));
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder addTitle(ObservableValue<String> title) {
|
||||
entries.add(new DynamicOptionsComp.Entry(null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header")));
|
||||
entries.add(new DynamicOptionsComp.Entry(
|
||||
null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header")));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -81,35 +83,43 @@ public class DynamicOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder addCharacter(Property<Character> prop, ObservableValue<String> name, Map<Character, ObservableValue<String>> names) {
|
||||
public DynamicOptionsBuilder addCharacter(
|
||||
Property<Character> prop, ObservableValue<String> name, Map<Character, ObservableValue<String>> names) {
|
||||
var comp = new CharChoiceComp(prop, names, null);
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DynamicOptionsBuilder addCharacter(Property<Character> prop, ObservableValue<String> name, Map<Character, ObservableValue<String>> names, ObservableValue<String> customName) {
|
||||
public DynamicOptionsBuilder addCharacter(
|
||||
Property<Character> prop,
|
||||
ObservableValue<String> name,
|
||||
Map<Character, ObservableValue<String>> names,
|
||||
ObservableValue<String> customName) {
|
||||
var comp = new CharChoiceComp(prop, names, customName);
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> DynamicOptionsBuilder addToggle(Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names) {
|
||||
public <V> DynamicOptionsBuilder addToggle(
|
||||
Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names) {
|
||||
var comp = new ToggleGroupComp<>(prop, names);
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> DynamicOptionsBuilder addChoice(Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names) {
|
||||
public <V> DynamicOptionsBuilder addChoice(
|
||||
Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names) {
|
||||
var comp = new ChoiceComp<>(prop, names);
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <V> DynamicOptionsBuilder addChoice(Property<V> prop, ObservableValue<String> name, ObservableValue<Map<V, ObservableValue<String>>> names) {
|
||||
public <V> DynamicOptionsBuilder addChoice(
|
||||
Property<V> prop, ObservableValue<String> name, ObservableValue<Map<V, ObservableValue<String>>> names) {
|
||||
var comp = new ChoiceComp<>(prop, names);
|
||||
entries.add(new DynamicOptionsComp.Entry(name, comp));
|
||||
props.add(prop);
|
||||
@@ -212,7 +222,7 @@ public class DynamicOptionsBuilder {
|
||||
|
||||
public <T, V extends T> DynamicOptionsBuilder bindLazy(Supplier<V> creator, Property<T> toLazySet) {
|
||||
lazyProperties.forEach(prop -> {
|
||||
prop.addListener((c,o,n) -> {
|
||||
prop.addListener((c, o, n) -> {
|
||||
toLazySet.setValue(creator.get());
|
||||
});
|
||||
});
|
||||
@@ -221,9 +231,10 @@ public class DynamicOptionsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public final <T, V extends T> DynamicOptionsBuilder bindChoice(Supplier<Property<? extends V>> creator, Property<T> toSet) {
|
||||
public final <T, V extends T> DynamicOptionsBuilder bindChoice(
|
||||
Supplier<Property<? extends V>> creator, Property<T> toSet) {
|
||||
props.forEach(prop -> {
|
||||
prop.addListener((c,o,n) -> {
|
||||
prop.addListener((c, o, n) -> {
|
||||
toSet.unbind();
|
||||
toSet.bind(creator.get());
|
||||
});
|
||||
@@ -234,12 +245,14 @@ public class DynamicOptionsBuilder {
|
||||
|
||||
public Comp<? extends CompStructure<?>> buildComp() {
|
||||
if (title != null) {
|
||||
entries.add(0, new DynamicOptionsComp.Entry(null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header")));
|
||||
entries.add(
|
||||
0,
|
||||
new DynamicOptionsComp.Entry(
|
||||
null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header")));
|
||||
}
|
||||
return new DynamicOptionsComp(entries, wrap);
|
||||
}
|
||||
|
||||
|
||||
public Region build() {
|
||||
return buildComp().createRegion();
|
||||
}
|
||||
|
||||
@@ -73,11 +73,14 @@ public final class ExclusiveValidator<T> implements Validator {
|
||||
|
||||
@Override
|
||||
public StringBinding createStringBinding(String prefix, String separator) {
|
||||
var list = new ArrayList<Observable>(validators.values().stream().map(Validator::createStringBinding).toList());
|
||||
var list = new ArrayList<Observable>(
|
||||
validators.values().stream().map(Validator::createStringBinding).toList());
|
||||
list.add(obs);
|
||||
Observable[] observables = list.toArray(Observable[]::new);
|
||||
return Bindings.createStringBinding(() -> {
|
||||
return get().createStringBinding(prefix, separator).get();
|
||||
}, observables);
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
return get().createStringBinding(prefix, separator).get();
|
||||
},
|
||||
observables);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import java.nio.file.Path;
|
||||
|
||||
public class ExtensionTest {
|
||||
|
||||
|
||||
public static DataStore getResource(String name) {
|
||||
var url = ExtensionTest.class.getClassLoader().getResource(name);
|
||||
if (url == null) {
|
||||
|
||||
@@ -8,6 +8,10 @@ import java.util.List;
|
||||
@Value
|
||||
public class NamedCharacter {
|
||||
|
||||
char character;
|
||||
List<String> names;
|
||||
String translationKey;
|
||||
|
||||
public static QueryConverter<Character> converter(List<NamedCharacter> chars, boolean allowOthers) {
|
||||
return new QueryConverter<Character>() {
|
||||
@Override
|
||||
@@ -16,15 +20,19 @@ public class NamedCharacter {
|
||||
throw new IllegalArgumentException("No character");
|
||||
}
|
||||
|
||||
var byName = chars.stream().filter(nc -> nc.getNames().stream()
|
||||
var byName = chars.stream()
|
||||
.filter(nc -> nc.getNames().stream()
|
||||
.anyMatch(n -> n.toLowerCase().contains(s.toLowerCase())))
|
||||
.findFirst().orElse(null);
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (byName != null) {
|
||||
return byName.getCharacter();
|
||||
}
|
||||
|
||||
var byChar = chars.stream().filter(nc -> String.valueOf(nc.getCharacter()).equalsIgnoreCase(s))
|
||||
.findFirst().orElse(null);
|
||||
var byChar = chars.stream()
|
||||
.filter(nc -> String.valueOf(nc.getCharacter()).equalsIgnoreCase(s))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (byChar != null) {
|
||||
return byChar.getCharacter();
|
||||
}
|
||||
@@ -38,8 +46,10 @@ public class NamedCharacter {
|
||||
|
||||
@Override
|
||||
protected String toString(Character value) {
|
||||
var byChar = chars.stream().filter(nc -> value.equals(nc.getCharacter()))
|
||||
.findFirst().orElse(null);
|
||||
var byChar = chars.stream()
|
||||
.filter(nc -> value.equals(nc.getCharacter()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (byChar != null) {
|
||||
return byChar.getNames().get(0);
|
||||
}
|
||||
@@ -48,8 +58,4 @@ public class NamedCharacter {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char character;
|
||||
List<String> names;
|
||||
String translationKey;
|
||||
}
|
||||
@@ -13,76 +13,8 @@ import java.util.Set;
|
||||
|
||||
public class PrettyListView<T> extends ListView<T> {
|
||||
|
||||
public static class NoSelectionModel<T> extends MultipleSelectionModel<T> {
|
||||
|
||||
@Override
|
||||
public ObservableList<Integer> getSelectedIndices() {
|
||||
return FXCollections.emptyObservableList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<T> getSelectedItems() {
|
||||
return FXCollections.emptyObservableList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectIndices(int index, int... indices) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectAll() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectFirst() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectLast() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAndSelect(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(T obj) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelection(int index) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelection() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPrevious() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectNext() {
|
||||
}
|
||||
}
|
||||
|
||||
private final ScrollBar vBar = new ScrollBar();
|
||||
private final ScrollBar hBar = new ScrollBar();
|
||||
|
||||
public PrettyListView() {
|
||||
super();
|
||||
skinProperty().addListener(it -> {
|
||||
@@ -142,9 +74,73 @@ public class PrettyListView<T> extends ListView<T> {
|
||||
double w = getWidth();
|
||||
double h = getHeight();
|
||||
final double prefWidth = vBar.prefWidth(-1);
|
||||
vBar.resizeRelocate(w - prefWidth - insets.getRight(), insets.getTop(), prefWidth, h - insets.getTop() - insets.getBottom());
|
||||
vBar.resizeRelocate(
|
||||
w - prefWidth - insets.getRight(),
|
||||
insets.getTop(),
|
||||
prefWidth,
|
||||
h - insets.getTop() - insets.getBottom());
|
||||
|
||||
final double prefHeight = hBar.prefHeight(-1);
|
||||
hBar.resizeRelocate(insets.getLeft(), h - prefHeight - insets.getBottom(), w - insets.getLeft() - insets.getRight(), prefHeight);
|
||||
hBar.resizeRelocate(
|
||||
insets.getLeft(),
|
||||
h - prefHeight - insets.getBottom(),
|
||||
w - insets.getLeft() - insets.getRight(),
|
||||
prefHeight);
|
||||
}
|
||||
|
||||
public static class NoSelectionModel<T> extends MultipleSelectionModel<T> {
|
||||
|
||||
@Override
|
||||
public ObservableList<Integer> getSelectedIndices() {
|
||||
return FXCollections.emptyObservableList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<T> getSelectedItems() {
|
||||
return FXCollections.emptyObservableList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectIndices(int index, int... indices) {}
|
||||
|
||||
@Override
|
||||
public void selectAll() {}
|
||||
|
||||
@Override
|
||||
public void selectFirst() {}
|
||||
|
||||
@Override
|
||||
public void selectLast() {}
|
||||
|
||||
@Override
|
||||
public void clearAndSelect(int index) {}
|
||||
|
||||
@Override
|
||||
public void select(int index) {}
|
||||
|
||||
@Override
|
||||
public void select(T obj) {}
|
||||
|
||||
@Override
|
||||
public void clearSelection(int index) {}
|
||||
|
||||
@Override
|
||||
public void clearSelection() {}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPrevious() {}
|
||||
|
||||
@Override
|
||||
public void selectNext() {}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,9 @@ import java.util.Map;
|
||||
|
||||
public class PropertiesHelper {
|
||||
|
||||
public static <T, V> void bindExclusive(Property<V> selected, Map<V, ? extends Property<T>> map, Property<T> toBind) {
|
||||
selected.addListener((c,o,n) -> {
|
||||
public static <T, V> void bindExclusive(
|
||||
Property<V> selected, Map<V, ? extends Property<T>> map, Property<T> toBind) {
|
||||
selected.addListener((c, o, n) -> {
|
||||
toBind.unbind();
|
||||
toBind.bind(map.get(n));
|
||||
});
|
||||
|
||||
@@ -22,8 +22,7 @@ public interface SimpleFileDataSourceProvider<T extends DataSource<?>> extends D
|
||||
|
||||
@Override
|
||||
default DataSource<?> convert(T in, DataSourceType t) throws Exception {
|
||||
return DataSourceProviders.byId("binary")
|
||||
.createDefaultSource(in.getStore());
|
||||
return DataSourceProviders.byId("binary").createDefaultSource(in.getStore());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,8 +42,7 @@ public interface SimpleFileDataSourceProvider<T extends DataSource<?>> extends D
|
||||
}
|
||||
|
||||
if (store instanceof FilenameStore l) {
|
||||
return l.getFileExtension()
|
||||
.equalsIgnoreCase(ext);
|
||||
return l.getFileExtension().equalsIgnoreCase(ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ import net.synedra.validatorfx.Severity;
|
||||
import net.synedra.validatorfx.ValidationMessage;
|
||||
import net.synedra.validatorfx.ValidationResult;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleValidator implements Validator {
|
||||
|
||||
private final Map<Check, ChangeListener<ValidationResult>> checks = new LinkedHashMap<>();
|
||||
private final ReadOnlyObjectWrapper<ValidationResult> validationResultProperty = new ReadOnlyObjectWrapper<>(new ValidationResult());
|
||||
private final ReadOnlyObjectWrapper<ValidationResult> validationResultProperty =
|
||||
new ReadOnlyObjectWrapper<>(new ValidationResult());
|
||||
private final ReadOnlyBooleanWrapper containsErrorsProperty = new ReadOnlyBooleanWrapper();
|
||||
|
||||
/** Create a check that lives within this checker's domain.
|
||||
@@ -79,7 +81,7 @@ public class SimpleValidator implements Validator {
|
||||
for (Check check : checks.keySet()) {
|
||||
check.recheck();
|
||||
}
|
||||
return ! containsErrors();
|
||||
return !containsErrors();
|
||||
}
|
||||
|
||||
private void refreshProperties() {
|
||||
@@ -104,15 +106,17 @@ public class SimpleValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public StringBinding createStringBinding(String prefix, String separator) {
|
||||
return Bindings.createStringBinding( () -> {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (ValidationMessage msg : validationResultProperty.get().getMessages()) {
|
||||
if (str.length() > 0) {
|
||||
str.append(separator);
|
||||
}
|
||||
str.append(prefix).append(msg.getText());
|
||||
}
|
||||
return str.toString();
|
||||
}, validationResultProperty);
|
||||
return Bindings.createStringBinding(
|
||||
() -> {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (ValidationMessage msg : validationResultProperty.get().getMessages()) {
|
||||
if (str.length() > 0) {
|
||||
str.append(separator);
|
||||
}
|
||||
str.append(prefix).append(msg.getText());
|
||||
}
|
||||
return str.toString();
|
||||
},
|
||||
validationResultProperty);
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,4 @@ public interface UniformDataSourceProvider<T extends DataSource<?>> extends Data
|
||||
default Dialog configDialog(T source, boolean all) {
|
||||
return Dialog.empty().evaluateTo(() -> source);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,19 +25,24 @@ public interface XPipeDaemon {
|
||||
|
||||
public Image image(String file);
|
||||
|
||||
<T extends Comp<?> & Validatable> T streamStoreChooser(Property<DataStore> storeProperty, Property<DataSourceProvider<?>> provider,
|
||||
boolean showAnonymous,
|
||||
boolean showSaved);
|
||||
<T extends Comp<?> & Validatable> T streamStoreChooser(
|
||||
Property<DataStore> storeProperty,
|
||||
Property<DataSourceProvider<?>> provider,
|
||||
boolean showAnonymous,
|
||||
boolean showSaved);
|
||||
|
||||
<T extends Comp<?> & Validatable> T namedStoreChooser(
|
||||
ObservableValue<Predicate<DataStore>> filter, Property<? extends DataStore> selected, DataStoreProvider.Category category
|
||||
);
|
||||
<T extends Comp<?> & Validatable> T namedStoreChooser(
|
||||
ObservableValue<Predicate<DataStore>> filter,
|
||||
Property<? extends DataStore> selected,
|
||||
DataStoreProvider.Category category);
|
||||
|
||||
Comp<?> namedSourceChooser(
|
||||
ObservableValue<Predicate<DataSource<?>>> filter, Property<? extends DataSource<?>> selected, DataSourceProvider.Category category
|
||||
);
|
||||
ObservableValue<Predicate<DataSource<?>>> filter,
|
||||
Property<? extends DataSource<?>> selected,
|
||||
DataSourceProvider.Category category);
|
||||
|
||||
<T extends Comp<?> & Validatable> T sourceProviderChooser(Property<DataSourceProvider<?>> provider, DataSourceProvider.Category category, DataSourceType filter);
|
||||
<T extends Comp<?> & Validatable> T sourceProviderChooser(
|
||||
Property<DataSourceProvider<?>> provider, DataSourceProvider.Category category, DataSourceType filter);
|
||||
|
||||
Optional<DataStore> getNamedStore(String name);
|
||||
|
||||
|
||||
@@ -37,4 +37,4 @@ open module io.xpipe.extension {
|
||||
uses io.xpipe.extension.DataStoreProvider;
|
||||
uses XPipeDaemon;
|
||||
uses io.xpipe.extension.Cache;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user