This commit is contained in:
Christopher Schnick 2022-06-20 01:35:51 +02:00
parent b80b8121f6
commit af17d731ab
29 changed files with 60 additions and 308 deletions

View file

@ -27,6 +27,11 @@ public class FileStore implements StreamDataStore, FilenameStore {
this.file = file;
}
@Override
public boolean canOpen() {
return machine.exists(file);
}
@Override
public String toDisplay() {
return file + "@" + machine.toDisplay();

View file

@ -109,7 +109,7 @@ public class InputStreamDataStore implements StreamDataStore {
}
@Override
public boolean exists() {
public boolean canOpen() {
return true;
}
}

View file

@ -10,6 +10,11 @@ import java.nio.file.Path;
@JsonTypeName("local")
public class LocalMachineStore implements MachineStore {
@Override
public boolean exists(String file) {
return Files.exists(Path.of(file));
}
@Override
public String toDisplay() {
return "local";

View file

@ -13,4 +13,5 @@ public interface MachineStore extends DataStore {
OutputStream openOutput(String file) throws Exception;
public boolean exists(String file);
}

View file

@ -22,7 +22,7 @@ public class OutputStreamStore implements StreamDataStore {
}
@Override
public boolean exists() {
public boolean canOpen() {
return true;
}
}

View file

@ -87,7 +87,7 @@ public class StdinDataStore implements StreamDataStore {
}
@Override
public boolean exists() {
public boolean canOpen() {
return false;
}
}

View file

@ -40,7 +40,7 @@ public class StdoutDataStore implements StreamDataStore {
}
@Override
public boolean exists() {
public boolean canOpen() {
return false;
}
}

View file

@ -23,12 +23,8 @@ public interface StreamDataStore extends DataStore {
throw new UnsupportedOperationException("Can't open store output");
}
default OutputStream openAppendingOutput() throws Exception {
throw new UnsupportedOperationException("Can't open store output");
}
default boolean exists() {
return false;
default boolean canOpen() {
return true;
}
default boolean persistent() {

View file

@ -16,7 +16,7 @@ public class URLDataStore implements StreamDataStore {
}
@Override
public boolean exists() {
public boolean canOpen() {
return true;
}
}

2
deps

@ -1 +1 @@
Subproject commit cbac51bc63e727c0ff5038cace4e91daa168a556
Subproject commit 49a1ad06bc6872f72c1d20ea864d24f3df59b7c5

View file

@ -158,6 +158,12 @@ public interface DataSourceProvider<T extends DataSource<?>> {
return getPossibleNames().get(0);
}
default String getModuleName() {
var n = getClass().getPackageName();
var i = n.lastIndexOf('.');
return i != -1 ? n.substring(i + 1) : n;
}
/**
* 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.

View file

@ -27,8 +27,14 @@ public interface DataStoreProvider {
return i18n("displayDescription");
}
default String getModuleName() {
var n = getClass().getPackageName();
var i = n.lastIndexOf('.');
return i != -1 ? n.substring(i + 1) : n;
}
default String getDisplayIconFileName() {
return getId() + ":icon.png";
return getModuleName() + ":" + getId() + ".png";
}
default Dialog dialogForURL(URL url) {
@ -50,4 +56,6 @@ public interface DataStoreProvider {
default String getId() {
return getPossibleNames().get(0);
}
List<Class<?>> getStoreClasses();
}

View file

@ -53,6 +53,16 @@ public class DataStoreProviders {
return ALL.stream().map(d -> d.dialogForString(s)).filter(Objects::nonNull).findAny();
}
@SuppressWarnings("unchecked")
public static <T extends DataStoreProvider> T byStoreClass(Class<?> c) {
if (ALL == null) {
throw new IllegalStateException("Not initialized");
}
return (T) ALL.stream().filter(d -> d.getStoreClasses().contains(c)).findAny()
.orElseThrow(() -> new IllegalArgumentException("Provider for " + c.getSimpleName() + " not found"));
}
public static Set<DataStoreProvider> getAll() {
return ALL;
}

View file

@ -12,7 +12,7 @@ public interface SupportedApplicationProvider {
APPLICATION
}
Region createRetrieveInstructions(DataSourceProvider provider, ObservableValue<String> id);
Region createRetrieveInstructions(DataSourceProvider<?> provider, ObservableValue<String> id);
String getId();

View file

@ -88,6 +88,21 @@ public record CodeSnippet(List<CodeSnippet.Line> lines) {
}
return new CodeSnippet(lines);
}
public Builder snippet(CodeSnippet s) {
if (s.lines.size() == 0) {
return this;
}
var first = s.lines.get(0);
var line = new ArrayList<>(currentLine);
line.addAll(first.elements);
lines.add(new Line(new ArrayList<>(line)));
currentLine.clear();
s.lines.stream().skip(1).forEach(l -> lines.add(l));
return this;
}
}
public static record StaticElement(String value, Color color) implements Element {

View file

@ -1,11 +0,0 @@
plugins {
id 'java'
id "org.moditect.gradleplugin" version "1.0.0-rc3"
}
apply from: "$rootDir/deps/lombok.gradle"
apply from: "$rootDir/deps/extension.gradle"
configurations {
compileOnly.extendsFrom(dep)
}

View file

@ -1,18 +0,0 @@
package io.xpipe.ext.json;
import io.xpipe.core.source.RawDataSourceDescriptor;
import io.xpipe.core.source.RawReadConnection;
import io.xpipe.core.source.RawWriteConnection;
import io.xpipe.core.store.StreamDataStore;
public class MyRawFileDescriptor extends RawDataSourceDescriptor<StreamDataStore> {
@Override
protected RawWriteConnection newWriteConnection(StreamDataStore store) {
return new MyRawFileWriteConnection(store);
}
@Override
protected RawReadConnection newReadConnection(StreamDataStore store) {
return new MyRawFileReadConnection(store);
}
}

View file

@ -1,30 +0,0 @@
package io.xpipe.ext.json;
import io.xpipe.core.source.DataSourceDescriptor;
import io.xpipe.core.source.DataSourceType;
import io.xpipe.extension.DataSourceProvider;
import io.xpipe.extension.SimpleFileDataSourceProvider;
import io.xpipe.extension.UniformDataSourceProvider;
import java.util.LinkedHashMap;
import java.util.Map;
public class MyRawFileProvider implements UniformDataSourceProvider, SimpleFileDataSourceProvider, DataSourceProvider {
@Override
public DataSourceType getPrimaryType() {
return DataSourceType.RAW;
}
@Override
public Map<String, String> getSupportedExtensions() {
var map = new LinkedHashMap<String, String>();
map.put(i18nKey("fileName"), "myf");
return map;
}
@Override
public Class<? extends DataSourceDescriptor<?>> getDescriptorClass() {
return MyRawFileDescriptor.class;
}
}

View file

@ -1,43 +0,0 @@
package io.xpipe.ext.json;
import io.xpipe.core.source.RawReadConnection;
import io.xpipe.core.store.StreamDataStore;
import java.io.InputStream;
public class MyRawFileReadConnection implements RawReadConnection {
private InputStream inputStream;
private final StreamDataStore store;
public MyRawFileReadConnection(StreamDataStore store) {
this.store = store;
}
@Override
public void init() throws Exception {
if (inputStream != null) {
throw new IllegalStateException("Already initialized");
}
inputStream = store.openInput();
}
@Override
public void close() throws Exception {
if (inputStream == null) {
throw new IllegalStateException("Not initialized");
}
inputStream.close();
}
@Override
public byte[] readBytes(int max) throws Exception {
if (inputStream == null) {
throw new IllegalStateException("Not initialized");
}
return inputStream.readNBytes(max);
}
}

View file

@ -1,43 +0,0 @@
package io.xpipe.ext.json;
import io.xpipe.core.source.RawWriteConnection;
import io.xpipe.core.store.StreamDataStore;
import java.io.OutputStream;
public class MyRawFileWriteConnection implements RawWriteConnection {
private final StreamDataStore store;
private OutputStream outputStream;
public MyRawFileWriteConnection(StreamDataStore store) {
this.store = store;
}
@Override
public void init() throws Exception {
if (outputStream != null) {
throw new IllegalStateException("Already initialized");
}
outputStream = store.openOutput();
}
@Override
public void close() throws Exception {
if (outputStream == null) {
throw new IllegalStateException("Not initialized");
}
outputStream.close();
}
@Override
public void write(byte[] bytes) throws Exception {
if (outputStream == null) {
throw new IllegalStateException("Not initialized");
}
outputStream.write(bytes);
}
}

View file

@ -1,13 +0,0 @@
import io.xpipe.ext.json.MyRawFileProvider;
import io.xpipe.extension.DataSourceProvider;
module io.xpipe.ext.file_data_source_sample {
exports io.xpipe.ext.json;
opens io.xpipe.ext.json;
requires io.xpipe.core;
requires io.xpipe.extension;
provides DataSourceProvider with MyRawFileProvider;
}

View file

@ -1,3 +0,0 @@
displayName=Mein Dateiformat
description=Meine Dateiformat-Beschreibung
fileName=Mein Dateiformat Datei

View file

@ -1,3 +0,0 @@
displayName=My file format
description=My file format description
fileName=My file format file

View file

@ -1,28 +0,0 @@
plugins {
id 'application'
}
java {
modularity.inferModulePath = true
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
// The used X-Pipe API version.
// In your case, you have to fix this value to the target API version,
// which you can find at https://search.maven.org/artifact/io.xpipe/api/
def apiVersion = file('../../misc/version').text
dependencies {
implementation project(':core')
implementation project(':api')
}
application {
mainModule = 'io.xpipe.sample'
mainClass = 'io.xpipe.sample.HomePricesSample'
}

View file

@ -1,38 +0,0 @@
package io.xpipe.sample;
import io.xpipe.api.DataSource;
import io.xpipe.api.DataTable;
import io.xpipe.core.data.node.TupleNode;
import java.util.Comparator;
import java.util.Map;
public class HomePricesSample {
private static DataTable homePricesTable;
public static void main(String[] args) {
var resource = HomePricesSample.class.getResource("homes.csv");
// Creates a wrapped data source using the url.
// Note that while this is possible, it is not recommended as
// all queries are routed through the XPipe client anyway.
// It allows us however to bundle the data with this sample program.
homePricesTable = DataSource.createAnonymous("csv", Map.of(), resource).asTable();
// As we didn't pass any configuration parameters, X-Pipe will try to automatically detect
// the correct configuration parameters. You can access these parameters like this:
System.out.println("Determined configuration: " + homePricesTable.getConfig());
// In case these some parameters are not chosen correctly, you can pass the proper values
// to the wrap() method.
System.out.println("The highest selling house entry is: " + getHighestSellingHouse());
}
private static TupleNode getHighestSellingHouse() {
return homePricesTable.stream()
.min(Comparator.comparingInt(t -> t.forKey("Sell").asInt()))
.get();
}
}

View file

@ -1,4 +0,0 @@
module io.xpipe.sample {
requires io.xpipe.api;
requires io.xpipe.core;
}

View file

@ -1,52 +0,0 @@
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
138, 140, 17, 7, 3, 1, 22, 0.46, 3204
232, 240, 25, 8, 4, 3, 5, 2.05, 3613
135, 140, 18, 7, 4, 3, 9, 0.57, 3028
150, 160, 20, 8, 4, 3, 18, 4.00, 3131
207, 225, 22, 8, 4, 2, 16, 2.22, 5158
271, 285, 30, 10, 5, 2, 30, 0.53, 5702
89, 90, 10, 5, 3, 1, 43, 0.30, 2054
153, 157, 22, 8, 3, 3, 18, 0.38, 4127
87, 90, 16, 7, 3, 1, 50, 0.65, 1445
234, 238, 25, 8, 4, 2, 2, 1.61, 2087
106, 116, 20, 8, 4, 1, 13, 0.22, 2818
175, 180, 22, 8, 4, 2, 15, 2.06, 3917
165, 170, 17, 8, 4, 2, 33, 0.46, 2220
166, 170, 23, 9, 4, 2, 37, 0.27, 3498
136, 140, 19, 7, 3, 1, 22, 0.63, 3607
148, 160, 17, 7, 3, 2, 13, 0.36, 3648
151, 153, 19, 8, 4, 2, 24, 0.34, 3561
180, 190, 24, 9, 4, 2, 10, 1.55, 4681
293, 305, 26, 8, 4, 3, 6, 0.46, 7088
167, 170, 20, 9, 4, 2, 46, 0.46, 3482
190, 193, 22, 9, 5, 2, 37, 0.48, 3920
184, 190, 21, 9, 5, 2, 27, 1.30, 4162
157, 165, 20, 8, 4, 2, 7, 0.30, 3785
110, 115, 16, 8, 4, 1, 26, 0.29, 3103
135, 145, 18, 7, 4, 1, 35, 0.43, 3363
567, 625, 64, 11, 4, 4, 4, 0.85, 12192
180, 185, 20, 8, 4, 2, 11, 1.00, 3831
183, 188, 17, 7, 3, 2, 16, 3.00, 3564
185, 193, 20, 9, 3, 2, 56, 6.49, 3765
152, 155, 17, 8, 4, 1, 33, 0.70, 3361
148, 153, 13, 6, 3, 2, 22, 0.39, 3950
152, 159, 15, 7, 3, 1, 25, 0.59, 3055
146, 150, 16, 7, 3, 1, 31, 0.36, 2950
170, 190, 24, 10, 3, 2, 33, 0.57, 3346
127, 130, 20, 8, 4, 1, 65, 0.40, 3334
265, 270, 36, 10, 6, 3, 33, 1.20, 5853
157, 163, 18, 8, 4, 2, 12, 1.13, 3982
128, 135, 17, 9, 4, 1, 25, 0.52, 3374
110, 120, 15, 8, 4, 2, 11, 0.59, 3119
123, 130, 18, 8, 4, 2, 43, 0.39, 3268
212, 230, 39, 12, 5, 3, 202, 4.29, 3648
145, 145, 18, 8, 4, 2, 44, 0.22, 2783
129, 135, 10, 6, 3, 1, 15, 1.00, 2438
143, 145, 21, 7, 4, 2, 10, 1.20, 3529
247, 252, 29, 9, 4, 2, 4, 1.25, 4626
111, 120, 15, 8, 3, 1, 97, 1.11, 3205
133, 145, 26, 7, 3, 1, 42, 0.36, 3059
Can't render this file because it has a wrong number of fields in line 52.

View file

@ -4,11 +4,3 @@ include 'api'
include 'core'
include 'beacon'
include 'extension'
include 'sample_extension'
project(":sample_extension").projectDir = file("samples/sample_extension")
include 'sample_program'
project(":sample_program").projectDir = file("samples/sample_program")