diff --git a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java index e61f3ebd7..436ac3167 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTableImpl.java @@ -2,25 +2,16 @@ package io.xpipe.api.impl; import io.xpipe.api.DataSourceConfig; import io.xpipe.api.DataTable; -import io.xpipe.api.connector.XPipeApiConnection; -import io.xpipe.beacon.BeaconConnection; -import io.xpipe.beacon.BeaconException; -import io.xpipe.beacon.exchange.api.QueryTableDataExchange; import io.xpipe.core.data.node.ArrayNode; import io.xpipe.core.data.node.DataStructureNode; import io.xpipe.core.data.node.TupleNode; -import io.xpipe.core.data.typed.TypedAbstractReader; -import io.xpipe.core.data.typed.TypedDataStreamParser; -import io.xpipe.core.data.typed.TypedDataStructureNodeReader; import io.xpipe.core.source.DataSourceId; -import io.xpipe.core.source.DataSourceReference; import io.xpipe.core.source.DataSourceType; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.stream.Stream; -import java.util.stream.StreamSupport; public class DataTableImpl extends DataSourceImpl implements DataTable { @@ -34,9 +25,7 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { } public Stream stream() { - var iterator = new TableIterator(); - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) - .onClose(iterator::finish); + return Stream.of(); } @Override @@ -52,71 +41,21 @@ public class DataTableImpl extends DataSourceImpl implements DataTable { @Override public ArrayNode read(int maxRows) { List nodes = new ArrayList<>(); - XPipeApiConnection.execute(con -> { - var req = QueryTableDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())) - .maxRows(maxRows) - .build(); - con.performInputExchange(req, (QueryTableDataExchange.Response res, InputStream in) -> { - var r = new TypedDataStreamParser(res.getDataType()); - - r.parseStructures(in, TypedDataStructureNodeReader.of(res.getDataType()), nodes::add); - }); - }); return ArrayNode.of(nodes); } @Override public Iterator iterator() { - return new TableIterator(); - } - - private class TableIterator implements Iterator { - - private final BeaconConnection connection; - private final TypedDataStreamParser parser; - private final TypedAbstractReader nodeReader; - private TupleNode node; - - { - connection = XPipeApiConnection.open(); - var req = QueryTableDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())) - .maxRows(Integer.MAX_VALUE) - .build(); - connection.sendRequest(req); - QueryTableDataExchange.Response response = connection.receiveResponse(); - - nodeReader = TypedDataStructureNodeReader.of(response.getDataType()); - parser = new TypedDataStreamParser(response.getDataType()); - - connection.receiveBody(); - } - - private void finish() { - connection.close(); - } - - @Override - public boolean hasNext() { - connection.checkClosed(); - - try { - node = (TupleNode) parser.parseStructure(connection.getInputStream(), nodeReader); - } catch (IOException e) { - throw new BeaconException(e); + return new Iterator() { + @Override + public boolean hasNext() { + return false; } - if (node == null) { - // finish(); + + @Override + public TupleNode next() { + return null; } - return node != null; - } - - @Override - public TupleNode next() { - connection.checkClosed(); - - return node; - } + }; } } diff --git a/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java index f272c7dd0..c4c72f22a 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataTextImpl.java @@ -2,25 +2,12 @@ package io.xpipe.api.impl; import io.xpipe.api.DataSourceConfig; import io.xpipe.api.DataText; -import io.xpipe.api.connector.XPipeApiConnection; -import io.xpipe.beacon.BeaconConnection; -import io.xpipe.beacon.BeaconException; -import io.xpipe.beacon.exchange.api.QueryTextDataExchange; import io.xpipe.core.source.DataSourceId; -import io.xpipe.core.source.DataSourceReference; import io.xpipe.core.source.DataSourceType; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.Iterator; import java.util.List; -import java.util.Spliterator; -import java.util.Spliterators; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; public class DataTextImpl extends DataSourceImpl implements DataText { @@ -53,47 +40,7 @@ public class DataTextImpl extends DataSourceImpl implements DataText { @Override public Stream lines() { - var iterator = new Iterator() { - - private final BeaconConnection connection; - private final BufferedReader reader; - private String nextValue; - - { - connection = XPipeApiConnection.open(); - var req = QueryTextDataExchange.Request.builder() - .ref(DataSourceReference.id(getId())) - .maxLines(-1) - .build(); - connection.sendRequest(req); - connection.receiveResponse(); - reader = new BufferedReader(new InputStreamReader(connection.receiveBody(), StandardCharsets.UTF_8)); - } - - private void close() { - connection.close(); - } - - @Override - public boolean hasNext() { - connection.checkClosed(); - - try { - nextValue = reader.readLine(); - } catch (IOException e) { - throw new BeaconException(e); - } - return nextValue != null; - } - - @Override - public String next() { - return nextValue; - } - }; - - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false) - .onClose(iterator::close); + return Stream.of(); } @Override diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index 1bbc17c9f..b635bc0cb 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -6,7 +6,6 @@ import io.xpipe.app.storage.DataStorage; import io.xpipe.app.util.BusyProperty; import io.xpipe.app.util.TerminalHelper; import io.xpipe.app.util.ThreadHelper; -import io.xpipe.app.util.XPipeDaemon; import io.xpipe.core.impl.FileNames; import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellDialects; @@ -133,7 +132,7 @@ public final class OpenFileSystemModel { && fileSystem.getShell().isPresent()) { var directory = currentPath.get(); var name = adjustedPath + " - " - + XPipeDaemon.getInstance().getStoreName(store).orElse("?"); + + DataStorage.get().getStoreDisplayName(store).orElse("?"); ThreadHelper.runFailableAsync(() -> { if (ShellDialects.ALL.stream() .anyMatch(dialect -> adjustedPath.startsWith(dialect.getOpenCommand()))) { @@ -379,8 +378,7 @@ public final class OpenFileSystemModel { var command = s.control() .initWith(connection.getShellDialect().getCdCommand(directory)) .prepareTerminalOpen(directory + " - " - + XPipeDaemon.getInstance() - .getStoreName(store) + + DataStorage.get().getStoreDisplayName(store) .orElse("?")); TerminalHelper.open(directory, command); } diff --git a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java index c56aa25a9..6aac4567a 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java @@ -7,6 +7,7 @@ import io.xpipe.app.fxcomps.util.PlatformThread; import javafx.application.Platform; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.css.PseudoClass; import javafx.scene.control.ScrollPane; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; @@ -18,6 +19,9 @@ import java.util.function.Function; public class ListBoxViewComp extends Comp> { + private static final PseudoClass ODD = PseudoClass.getPseudoClass("odd"); + private static final PseudoClass EVEN = PseudoClass.getPseudoClass("even"); + private final ObservableList shown; private final ObservableList all; private final Function> compFunction; @@ -65,6 +69,13 @@ public class ListBoxViewComp extends Comp> { }) .toList(); + for (int i = 0; i < newShown.size(); i++) { + var r = newShown.get(i); + r.pseudoClassStateChanged(ODD, false); + r.pseudoClassStateChanged(EVEN, false); + r.pseudoClassStateChanged(i % 2 == 0 ? EVEN : ODD, true); + } + if (!listView.getChildren().equals(newShown)) { listView.getChildren().setAll(newShown); listView.layout(); diff --git a/app/src/main/java/io/xpipe/app/comp/base/SystemStateComp.java b/app/src/main/java/io/xpipe/app/comp/base/SystemStateComp.java new file mode 100644 index 000000000..77cd6df55 --- /dev/null +++ b/app/src/main/java/io/xpipe/app/comp/base/SystemStateComp.java @@ -0,0 +1,42 @@ +package io.xpipe.app.comp.base; + +import io.xpipe.app.fxcomps.SimpleComp; +import io.xpipe.app.fxcomps.impl.FancyTooltipAugment; +import io.xpipe.app.fxcomps.util.PlatformThread; +import io.xpipe.app.fxcomps.util.SimpleChangeListener; +import javafx.beans.binding.Bindings; +import javafx.beans.value.ObservableValue; +import javafx.scene.layout.Pane; +import javafx.scene.layout.Region; +import org.kordamp.ikonli.javafx.FontIcon; + +public class SystemStateComp extends SimpleComp { + + + public SystemStateComp(ObservableValue name, ObservableValue state) { + this.name = name; + this.state = state; + } + + public static enum State { + STOPPED, + RUNNING, + OTHER + } + + private final ObservableValue name; + private final ObservableValue state; + + @Override + protected Region createSimple() { + var icon = PlatformThread.sync(Bindings.createStringBinding(() -> { + return state.getValue() == State.STOPPED ? "mdmz-stop_circle" : state.getValue() == State.RUNNING ? "mdrmz-play_circle_outline" : "mdmz-remove_circle_outline"; + }, state)); + var fi = new FontIcon(); + SimpleChangeListener.apply(icon, val -> fi.setIconLiteral(val)); + new FancyTooltipAugment<>(PlatformThread.sync(name)).augment(fi); + + var pane = new Pane(fi); + return pane; + } +} diff --git a/app/src/main/java/io/xpipe/app/comp/source/DataSourceTargetChoiceComp.java b/app/src/main/java/io/xpipe/app/comp/source/DataSourceTargetChoiceComp.java deleted file mode 100644 index 8e7b9bf9b..000000000 --- a/app/src/main/java/io/xpipe/app/comp/source/DataSourceTargetChoiceComp.java +++ /dev/null @@ -1,101 +0,0 @@ -package io.xpipe.app.comp.source; - -import io.xpipe.app.core.AppCache; -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.ext.DataSourceTarget; -import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.CompStructure; -import io.xpipe.app.fxcomps.SimpleCompStructure; -import io.xpipe.app.util.CustomComboBoxBuilder; -import javafx.beans.property.Property; -import javafx.geometry.Pos; -import javafx.scene.Node; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.layout.Region; -import org.kordamp.ikonli.javafx.FontIcon; - -import java.util.List; -import java.util.function.Predicate; - -public class DataSourceTargetChoiceComp extends Comp>> { - - private final Property selectedApplication; - private final List all; - - private DataSourceTargetChoiceComp(Property selectedApplication, List all) { - this.selectedApplication = selectedApplication; - this.all = all; - } - - public static DataSourceTargetChoiceComp create( - Property selectedApplication, Predicate filter) { - selectedApplication.addListener((observable, oldValue, val) -> { - AppCache.update("application-last-used", val != null ? val.getId() : null); - }); - var all = DataSourceTarget.getAll().stream().filter(filter).toList(); - - if (selectedApplication.getValue() == null) { - String selectedId = AppCache.get("application-last-used", String.class, () -> null); - var selectedProvider = selectedId != null - ? DataSourceTarget.byId(selectedId).filter(filter).orElse(null) - : null; - selectedApplication.setValue(selectedProvider); - } - - return new DataSourceTargetChoiceComp(selectedApplication, all); - } - - private String getIconCode(DataSourceTarget p) { - return p.getGraphicIcon() != null - ? p.getGraphicIcon() - : p.getCategory().equals(DataSourceTarget.Category.PROGRAMMING_LANGUAGE) - ? "mdi2c-code-tags" - : "mdral-indeterminate_check_box"; - } - - private Region createLabel(DataSourceTarget p) { - var g = new FontIcon(getIconCode(p)); - var l = new Label(p.getName().getValue(), g); - l.setAlignment(Pos.CENTER); - g.iconColorProperty().bind(l.textFillProperty()); - return l; - } - - @Override - public CompStructure> createBase() { - var addMoreLabel = new Label(AppI18n.get("addMore"), new FontIcon("mdmz-plus")); - - var builder = - new CustomComboBoxBuilder<>(selectedApplication, app -> createLabel(app), new Label(""), v -> true); - builder.setAccessibleNames( - dataSourceTarget -> dataSourceTarget.getName().getValue()); - - // builder.addFilter((v, s) -> v.getName().getValue().toLowerCase().contains(s)); - - builder.addHeader(AppI18n.get("programmingLanguages")); - all.stream() - .filter(p -> p.getCategory().equals(DataSourceTarget.Category.PROGRAMMING_LANGUAGE)) - .forEach(builder::add); - - builder.addHeader(AppI18n.get("applications")); - all.stream() - .filter(p -> p.getCategory().equals(DataSourceTarget.Category.APPLICATION)) - .forEach(builder::add); - - builder.addHeader(AppI18n.get("other")); - all.stream() - .filter(p -> p.getCategory().equals(DataSourceTarget.Category.OTHER)) - .forEach(builder::add); - - // builder.addSeparator(); - // builder.addAction(addMoreLabel, () -> { - // - // }); - - var cb = builder.build(); - cb.getStyleClass().add("application-choice-comp"); - cb.setMaxWidth(2000); - return new SimpleCompStructure<>(cb); - } -} diff --git a/app/src/main/java/io/xpipe/app/comp/source/DsCollectionComp.java b/app/src/main/java/io/xpipe/app/comp/source/DsCollectionComp.java deleted file mode 100644 index 28e0218bf..000000000 --- a/app/src/main/java/io/xpipe/app/comp/source/DsCollectionComp.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.xpipe.app.comp.source; - -import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.CompStructure; -import io.xpipe.app.fxcomps.SimpleCompStructure; -import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.core.source.CollectionReadConnection; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.scene.control.TreeItem; -import javafx.scene.control.TreeView; - -import java.util.ArrayList; - -public class DsCollectionComp extends Comp>> { - - private final ObservableValue con; - - private final ObservableValue value; - - public DsCollectionComp(ObservableValue con) { - this.con = con; - this.value = new SimpleObjectProperty<>("/"); - } - - private TreeItem createTree() { - var c = new ArrayList>(); - - if (con.getValue() != null) { - try { - con.getValue().listEntries().forEach(e -> { - // var item = new TreeItem(e.getFileName()); - // c.add(item); - }); - } catch (Exception ex) { - ErrorEvent.fromThrowable(ex).handle(); - } - } - - var ar = new TreeItem<>(value.getValue()); - ar.getChildren().setAll(c); - return ar; - } - - private void setupListener(TreeView tv) { - ChangeListener listener = (c, o, n) -> { - var nt = createTree(); - tv.setRoot(nt); - }; - con.addListener(listener); - listener.changed(con, null, con.getValue()); - } - - @Override - public CompStructure> createBase() { - var table = new TreeView(); - setupListener(table); - return new SimpleCompStructure<>(table); - } -} diff --git a/app/src/main/java/io/xpipe/app/comp/source/DsDataTransferComp.java b/app/src/main/java/io/xpipe/app/comp/source/DsDataTransferComp.java deleted file mode 100644 index cbb225538..000000000 --- a/app/src/main/java/io/xpipe/app/comp/source/DsDataTransferComp.java +++ /dev/null @@ -1,203 +0,0 @@ -package io.xpipe.app.comp.source; - -import io.xpipe.app.comp.base.ButtonComp; -import io.xpipe.app.comp.base.MultiStepComp; -import io.xpipe.app.core.AppFont; -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.core.AppWindowHelper; -import io.xpipe.app.ext.DataSourceTarget; -import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.CompStructure; -import io.xpipe.app.fxcomps.SimpleComp; -import io.xpipe.app.fxcomps.impl.DynamicOptionsComp; -import io.xpipe.app.fxcomps.impl.HorizontalComp; -import io.xpipe.app.fxcomps.util.PlatformThread; -import io.xpipe.app.fxcomps.util.SimpleChangeListener; -import io.xpipe.app.storage.DataSourceEntry; -import io.xpipe.app.storage.DataStorage; -import io.xpipe.app.util.BusyProperty; -import io.xpipe.app.util.Hyperlinks; -import io.xpipe.app.util.ThreadHelper; -import io.xpipe.core.source.DataSourceId; -import javafx.application.Platform; -import javafx.beans.binding.Bindings; -import javafx.beans.property.Property; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ObservableValue; -import javafx.geometry.Pos; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; -import javafx.scene.layout.Region; -import javafx.scene.layout.VBox; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.experimental.FieldDefaults; -import org.kordamp.ikonli.javafx.FontIcon; - -import java.util.ArrayList; -import java.util.List; - -@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) -@AllArgsConstructor -@Getter -public class DsDataTransferComp extends SimpleComp { - - private final Property dataSourceEntry; - Property selectedTarget = new SimpleObjectProperty<>(); - Property selectedDisplay = new SimpleObjectProperty<>(); - List excludedTargets = new ArrayList<>(); - - public DsDataTransferComp selectApplication(DataSourceTarget t) { - selectedTarget.setValue(t); - return this; - } - - public DsDataTransferComp exclude(DataSourceTarget t) { - excludedTargets.add(t); - return this; - } - - public static void showPipeWindow(DataSourceEntry e) { - Platform.runLater(() -> { - var loading = new SimpleBooleanProperty(); - AppWindowHelper.sideWindow( - AppI18n.get("pipeDataSource"), - window -> { - var ms = new DsDataTransferComp(new SimpleObjectProperty<>(e)) - .exclude(DataSourceTarget.byId("base.saveSource") - .orElseThrow()); - var multi = new MultiStepComp() { - @Override - protected List setup() { - return List.of(new Entry(null, new Step<>() { - @Override - public CompStructure createBase() { - return ms.createStructure(); - } - - @Override - public boolean canContinue() { - var selected = ms.selectedTarget.getValue(); - if (selected == null) { - return false; - } - - var validator = ms.selectedDisplay - .getValue() - .getValidator(); - if (validator == null) { - return true; - } - - return validator.validate(); - } - })); - } - - @Override - protected void finish() { - var onFinish = ms.getSelectedDisplay() - .getValue() - .getOnFinish(); - if (onFinish != null) { - ThreadHelper.runAsync(() -> { - try (var busy = new BusyProperty(loading)) { - onFinish.run(); - PlatformThread.runLaterIfNeeded(() -> window.close()); - } - }); - } - } - }; - return multi.apply(s -> { - SimpleChangeListener.apply(ms.getSelectedTarget(), (c) -> { - if (c != null && c.getAccessType() == DataSourceTarget.AccessType.PASSIVE) { - ((Region) s.get().getChildren().get(2)).setMaxHeight(0); - ((Region) s.get().getChildren().get(2)).setMinHeight(0); - s.get().getChildren().get(2).setVisible(false); - } else { - - ((Region) s.get().getChildren().get(2)).setMaxHeight(Region.USE_PREF_SIZE); - ((Region) s.get().getChildren().get(2)).setMinHeight(Region.USE_PREF_SIZE); - s.get().getChildren().get(2).setVisible(true); - } - }); - s.get().setPrefWidth(600); - s.get().setPrefHeight(700); - AppFont.medium(s.get()); - }); - }, - false, - loading) - .show(); - }); - } - - @Override - public Region createSimple() { - ObservableValue id = Bindings.createObjectBinding( - () -> { - if (!DataStorage.get().getSourceEntries().contains(dataSourceEntry.getValue())) { - return null; - } - - return DataStorage.get().getId(dataSourceEntry.getValue()); - }, - dataSourceEntry); - - var chooser = DataSourceTargetChoiceComp.create( - selectedTarget, - a -> !excludedTargets.contains(a) - && a.isApplicable(dataSourceEntry.getValue().getSource()) - && a.createRetrievalInstructions( - dataSourceEntry.getValue().getSource(), id) - != null); - - var setupGuideButton = new ButtonComp( - AppI18n.observable("setupGuide"), new FontIcon("mdoal-integration_instructions"), () -> { - Hyperlinks.open(selectedTarget.getValue().getSetupGuideURL()); - }) - .apply(s -> s.get() - .visibleProperty() - .bind(Bindings.createBooleanBinding( - () -> { - return selectedTarget.getValue() != null - && selectedTarget.getValue().getSetupGuideURL() != null; - }, - selectedTarget))); - var top = new HorizontalComp(List.>of( - chooser.apply(struc -> HBox.setHgrow(struc.get(), Priority.ALWAYS)), setupGuideButton)) - .apply(struc -> { - struc.get().setAlignment(Pos.CENTER); - struc.get().setSpacing(12); - struc.get().getStyleClass().add("top"); - }); - - // setupGuideButton.prefHeightProperty().bind(chooserR.heightProperty()); - - var content = new VBox( - new DynamicOptionsComp(List.of(new DynamicOptionsComp.Entry(null, null, top)), false).createRegion(), - new Region()); - SimpleChangeListener.apply(selectedTarget, c -> { - if (selectedTarget.getValue() == null) { - content.getChildren().set(1, new Region()); - selectedDisplay.setValue(null); - return; - } - - var instructions = selectedTarget - .getValue() - .createRetrievalInstructions(dataSourceEntry.getValue().getSource(), id); - content.getChildren().set(1, instructions.getRegion()); - VBox.setVgrow(instructions.getRegion(), Priority.ALWAYS); - selectedDisplay.setValue(instructions); - }); - - content.setSpacing(15); - var r = content; - r.getStyleClass().add("data-source-retrieve"); - return r; - } -} diff --git a/app/src/main/java/io/xpipe/app/comp/source/DsProviderChoiceComp.java b/app/src/main/java/io/xpipe/app/comp/source/DsProviderChoiceComp.java deleted file mode 100644 index cedcdfc61..000000000 --- a/app/src/main/java/io/xpipe/app/comp/source/DsProviderChoiceComp.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.xpipe.app.comp.source; - -import io.xpipe.app.core.AppI18n; -import io.xpipe.app.ext.DataSourceProvider; -import io.xpipe.app.ext.DataSourceProviders; -import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.CompStructure; -import io.xpipe.app.fxcomps.SimpleCompStructure; -import io.xpipe.app.prefs.AppPrefs; -import io.xpipe.app.util.*; -import io.xpipe.core.source.DataSourceType; -import javafx.beans.property.Property; -import javafx.scene.Node; -import javafx.scene.control.ComboBox; -import javafx.scene.layout.Region; -import lombok.Getter; -import net.synedra.validatorfx.Check; - -import java.util.List; - -public class DsProviderChoiceComp extends Comp>> implements Validatable { - - private final DataSourceProvider.Category type; - private final Property> provider; - - @Getter - private final Validator validator = new SimpleValidator(); - - private final Check check; - private final DataSourceType filter; - - public DsProviderChoiceComp( - DataSourceProvider.Category type, Property> provider, DataSourceType filter) { - this.type = type; - this.provider = provider; - check = Validator.nonNull(validator, AppI18n.observable("provider"), provider); - this.filter = filter; - } - - private Region createDefaultNode() { - return switch (type) { - case STREAM -> JfxHelper.createNamedEntry( - AppI18n.get("anyStream"), AppI18n.get("anyStreamDescription"), "file_icon.png"); - case DATABASE -> JfxHelper.createNamedEntry( - AppI18n.get("selectQueryType"), AppI18n.get("selectQueryTypeDescription"), "db_icon.png"); - }; - } - - private List> getProviders() { - return switch (type) { - case STREAM -> DataSourceProviders.getAll().stream() - .filter(p -> AppPrefs.get().developerShowHiddenProviders().get() - || p.getCategory() == DataSourceProvider.Category.STREAM) - .filter(p -> p.shouldShow(filter)) - .toList(); - case DATABASE -> DataSourceProviders.getAll().stream() - .filter(p -> p.getCategory() == DataSourceProvider.Category.DATABASE) - .filter(p -> AppPrefs.get().developerShowHiddenProviders().get() || p.shouldShow(filter)) - .toList(); - }; - } - - private Region createGraphic(DataSourceProvider provider) { - if (provider == null) { - return createDefaultNode(); - } - - var graphic = provider.getDisplayIconFileName(); - - return JfxHelper.createNamedEntry(provider.getDisplayName(), provider.getDisplayDescription(), graphic); - } - - @Override - public CompStructure> createBase() { - var comboBox = new CustomComboBoxBuilder<>(provider, this::createGraphic, createDefaultNode(), v -> true); - comboBox.setAccessibleNames( - dataSourceProvider -> dataSourceProvider != null ? dataSourceProvider.getDisplayName() : null); - comboBox.add(null); - comboBox.addSeparator(); - comboBox.addFilter((v, s) -> v.getDisplayName().toLowerCase().contains(s.toLowerCase())); - getProviders().forEach(comboBox::add); - ComboBox cb = comboBox.build(); - check.decorates(cb); - cb.getStyleClass().add("data-source-type"); - cb.getStyleClass().add("choice-comp"); - return new SimpleCompStructure<>(cb); - } -} diff --git a/app/src/main/java/io/xpipe/app/comp/source/DsRawComp.java b/app/src/main/java/io/xpipe/app/comp/source/DsRawComp.java deleted file mode 100644 index c3b8ca3b2..000000000 --- a/app/src/main/java/io/xpipe/app/comp/source/DsRawComp.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.xpipe.app.comp.source; - -import io.xpipe.app.fxcomps.Comp; -import io.xpipe.app.fxcomps.CompStructure; -import io.xpipe.app.fxcomps.SimpleCompStructure; -import io.xpipe.app.fxcomps.util.PlatformThread; -import io.xpipe.app.fxcomps.util.SimpleChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.scene.control.TextArea; - -import java.util.HexFormat; - -public class DsRawComp extends Comp> { - - private final ObservableValue value; - - public DsRawComp(ObservableValue value) { - this.value = value; - } - - private void setupListener(TextArea ta) { - var format = HexFormat.of().withDelimiter(" ").withUpperCase(); - SimpleChangeListener.apply(PlatformThread.sync(value), val -> { - ta.textProperty().setValue(format.formatHex(val)); - }); - } - - @Override - public CompStructure