Add extension module

This commit is contained in:
Christopher Schnick 2021-12-02 14:28:55 +01:00
parent a4ec9126af
commit 08fc604678
10 changed files with 198 additions and 1 deletions

View file

@ -3,6 +3,5 @@ module io.xpipe.api.test {
requires io.xpipe.api; requires io.xpipe.api;
requires io.xpipe.beacon; requires io.xpipe.beacon;
requires io.xpipe.app;
requires org.junit.jupiter.api; requires org.junit.jupiter.api;
} }

20
extension/build.gradle Normal file
View file

@ -0,0 +1,20 @@
plugins {
id 'java'
id "org.moditect.gradleplugin" version "1.0.0-rc3"
}
java {
modularity.inferModulePath = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
apply from: "$rootDir/deps/javafx.gradle"
repositories {
mavenCentral()
}
dependencies {
implementation project(':core')
}

View file

@ -0,0 +1,36 @@
package io.xpipe.extension;
import io.xpipe.core.source.DataSource;
import io.xpipe.core.store.DataStore;
import javafx.beans.property.Property;
import javafx.scene.image.Image;
import javafx.scene.layout.Region;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Supplier;
public interface DataSourceGuiProvider {
default boolean isHidden() {
return false;
}
boolean supportsFile(Path file);
Region createConfigOptions(DataStore input, Property<? extends DataSource<?>> source);
DataSource<?> createDefaultDataSource(DataStore input);
String getDisplayName();
Image getImage();
Supplier<String> getFileName();
Map<Supplier<String>, String> getFileExtensions();
String getDataSourceDescription(DataSource<?> source);
Class<? extends DataSource<?>> getType();
}

View file

@ -0,0 +1,34 @@
package io.xpipe.extension;
import java.util.HashSet;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
public class DataSourceGuiProviders {
private static Set<DataSourceGuiProvider> ALL;
public static void loadAll(ModuleLayer layer) {
if (ALL == null) {
ALL = new HashSet<>();
ALL.addAll(ServiceLoader.load(layer, DataSourceGuiProvider.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toSet()));
}
}
public static Optional<DataSourceGuiProvider> byClass(Class<?> clazz) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().filter(d -> d.getType().equals(clazz)).findAny();
}
public static Set<DataSourceGuiProvider> getAll() {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL;
}
}

View file

@ -0,0 +1,10 @@
package io.xpipe.extension;
import io.xpipe.core.source.DataSource;
public interface DataSourceProvider {
String getId();
Class<? extends DataSource> getType();
}

View file

@ -0,0 +1,40 @@
package io.xpipe.extension;
import io.xpipe.core.source.DataSource;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
public class DataSourceProviders {
private static Set<DataSourceProvider> ALL;
public static void init(ModuleLayer layer) {
if (ALL == null) {
ALL = ServiceLoader.load(layer, DataSourceProvider.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toSet());
}
}
public static Optional<DataSourceProvider> byDataSourceClass(Class<?> clazz) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().filter(d -> d.getType().equals(clazz)).findAny();
}
public static Optional<DataSourceProvider> byId(String name) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().filter(d -> d.getId().equals(name)).findAny();
}
public static Set<DataSourceProvider> getAll() {
return ALL;
}
}

View file

@ -0,0 +1,17 @@
package io.xpipe.extension;
import io.xpipe.core.source.DataSourceId;
import javafx.beans.value.ObservableValue;
import javafx.scene.image.Image;
import javafx.scene.layout.Region;
public interface SupportedApplicationProvider {
Region createRetrieveInstructions(ObservableValue<DataSourceId> id);
Image getLogo();
String getId();
String getName();
}

View file

@ -0,0 +1,34 @@
package io.xpipe.extension;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
public class SupportedApplicationProviders {
private static Set<SupportedApplicationProvider> ALL;
public static void loadAll(ModuleLayer layer) {
if (ALL == null) {
ALL = ServiceLoader.load(layer, SupportedApplicationProvider.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toSet());
}
}
public static Optional<SupportedApplicationProvider> byId(String id) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL.stream().filter(d -> d.getId().equals(id)).findAny();
}
public static Set<SupportedApplicationProvider> getAll() {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return ALL;
}
}

View file

@ -0,0 +1,6 @@
module io.xpipe.extension {
requires io.xpipe.core;
requires javafx.base;
exports io.xpipe.extension;
}

View file

@ -3,5 +3,6 @@ rootProject.name = 'xpipe_java'
include 'core' include 'core'
include 'beacon' include 'beacon'
include 'api' include 'api'
include 'extension'