Refactor exchanges, add dialog APIs, add store providers

This commit is contained in:
Christopher Schnick committed 2022-06-12 02:40:28 +02:00
1 parent f4f9c1d978
commit 696568d5bc
50 files changed
+791 -206

No files matched your search

@@ -1,7 +1,7 @@
package io.xpipe.extension;
import io.xpipe.charsetter.NewLine;
import io.xpipe.core.config.ConfigConverter;
import io.xpipe.core.config.QueryConverter;
import io.xpipe.core.config.ConfigParameter;
import io.xpipe.core.source.DataSource;
import io.xpipe.core.source.DataSourceType;
@@ -9,7 +9,6 @@ import io.xpipe.core.store.DataStore;
import javafx.beans.property.Property;
import javafx.scene.layout.Region;
import lombok.SneakyThrows;
import lombok.Value;
import java.util.Arrays;
import java.util.List;
@@ -93,13 +92,6 @@ public interface DataSourceProvider<T extends DataSource<?>> {
interface ConfigProvider<T extends DataSource<?>> {
@Value
static class Parameter {
ConfigParameter parameter;
Object currentValue;
boolean required;
}
static <T extends DataSource<?>> ConfigProvider<T> empty(List<String> names, Function<DataStore, T> func) {
return new ConfigProvider<>() {
@Override
@@ -124,9 +116,9 @@ public interface DataSourceProvider<T extends DataSource<?>> {
}
ConfigParameter CHARSET = new ConfigParameter(
"charset", ConfigConverter.CHARSET);
"charset", QueryConverter.CHARSET);
public static final ConfigConverter<NewLine> NEW_LINE_CONVERTER = new ConfigConverter<NewLine>() {
public static final QueryConverter<NewLine> NEW_LINE_CONVERTER = new QueryConverter<NewLine>() {
@Override
protected NewLine fromString(String s) {
return NewLine.id(s);
@@ -0,0 +1,46 @@
package io.xpipe.extension;
import io.xpipe.core.config.Dialog;
import java.net.URL;
import java.util.List;
public interface DataStoreProvider {
default void init() throws Exception {
}
default String i18n(String key) {
return I18n.get(getId() + "." + key);
}
default String i18nKey(String key) {
return getId() + "." + key;
}
default String getDisplayName() {
return i18n("displayName");
}
default String getDisplayDescription() {
return i18n("displayDescription");
}
default String getDisplayIconFileName() {
return getId() + ":icon.png";
}
default Dialog dialogForURL(URL url) {
return null;
}
Dialog defaultDialog();
List<String> getPossibleNames();
default String getId() {
var n = getClass().getPackageName();
var i = n.lastIndexOf('.');
return i != -1 ? n.substring(i + 1) : n;
}
}
@@ -0,0 +1,51 @@
package io.xpipe.extension;
import io.xpipe.core.config.Dialog;
import io.xpipe.extension.event.ErrorEvent;
import java.net.URL;
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
public class DataStoreProviders {
private static Set<DataStoreProvider> ALL;
public static void init(ModuleLayer layer) {
if (ALL == null) {
ALL = ServiceLoader.load(layer, DataStoreProvider.class).stream()
.map(p -> (DataStoreProvider) p.get()).collect(Collectors.toSet());
ALL.forEach(p -> {
try {
p.init();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
}
});
}
}
public static Optional<DataStoreProvider> byName(String name) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().filter(d -> d.getPossibleNames().stream()
.anyMatch(s -> s.equalsIgnoreCase(name))).findAny();
}
public static Optional<Dialog> byURL(URL url) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().map(d -> d.dialogForURL(url)).filter(Objects::nonNull).findAny();
}
public static Set<DataStoreProvider> getAll() {
return ALL;
}
}
+1
View File
@@ -35,4 +35,5 @@ module io.xpipe.extension {
uses io.xpipe.extension.I18n;
uses io.xpipe.extension.event.EventHandler;
uses io.xpipe.extension.prefs.PrefsProvider;
uses io.xpipe.extension.DataStoreProvider;
}