More cleanup

This commit is contained in:
Christopher Schnick 2022-12-30 12:54:53 +01:00
parent 990bea4f59
commit b0e9a96fc6
37 changed files with 291 additions and 202 deletions

View file

@ -16,16 +16,16 @@ public interface DataSourceActionProvider<T extends DataSource<?>> {
public static void init(ModuleLayer layer) {
if (ALL.size() == 0) {
ALL.addAll(ServiceLoader.load(layer, DataSourceActionProvider.class).stream()
.map(p -> (DataSourceActionProvider<?>) p.get())
.filter(provider -> {
try {
return provider.isActive();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
}
})
.toList());
.map(p -> (DataSourceActionProvider<?>) p.get())
.filter(provider -> {
try {
return provider.isActive();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
}
})
.toList());
}
}
@ -39,11 +39,13 @@ public interface DataSourceActionProvider<T extends DataSource<?>> {
return true;
}
default void applyToRegion(T store, Region region) {}
default void applyToRegion(T store, Region region) {
}
ObservableValue<String> getName(T store);
String getIcon(T store);
default void execute(T store) throws Exception {}
default void execute(T store) throws Exception {
}
}

View file

@ -33,7 +33,8 @@ 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));
@ -64,6 +65,7 @@ public interface DataSourceProvider<T extends DataSource<?>> {
default String queryInformationString(DataStore store, int length) throws Exception {
return getDisplayName();
}
default String getDisplayIconFileName() {
return getModuleName() + ":" + getId() + "_icon.png";
}
@ -86,14 +88,14 @@ public interface DataSourceProvider<T extends DataSource<?>> {
* Checks whether this provider supports the store in principle.
* This method should not perform any further checks,
* just check whether it may be possible that the store is supported.
*
* <p>
* This method will be called for validation purposes.
*/
boolean couldSupportStore(DataStore store);
/**
* Performs a deep inspection to check whether this provider supports a given store.
*
* <p>
* This functionality will be used in case no preferred provider has been found.
*/
default boolean supportsStore(DataStore store) {

View file

@ -42,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) {
@ -126,7 +126,7 @@ public class DataSourceProviders {
return ALL.stream()
.filter(d -> d.getPossibleNames().stream()
.anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name)))
.anyMatch(s -> nameAlternatives(s).stream().anyMatch(s1 -> s1.equalsIgnoreCase(name)))
|| d.getId().equalsIgnoreCase(name))
.findAny();
}
@ -139,7 +139,8 @@ public class DataSourceProviders {
String.join("-", split),
split.stream()
.map(s -> s.equals(split.get(0)) ? s : s.substring(0, 1).toUpperCase() + s.substring(1))
.collect(Collectors.joining()));
.collect(Collectors.joining())
);
}
public static Optional<DataSourceProvider<?>> byPreferredStore(DataStore store, DataSourceType type) {

View file

@ -16,16 +16,16 @@ public interface DataStoreActionProvider<T extends DataStore> {
public static void init(ModuleLayer layer) {
if (ALL.size() == 0) {
ALL.addAll(ServiceLoader.load(layer, DataStoreActionProvider.class).stream()
.map(p -> (DataStoreActionProvider<?>) p.get())
.filter(provider -> {
try {
return provider.isActive();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
}
})
.toList());
.map(p -> (DataStoreActionProvider<?>) p.get())
.filter(provider -> {
try {
return provider.isActive();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
return false;
}
})
.toList());
}
}
@ -43,11 +43,13 @@ public interface DataStoreActionProvider<T extends DataStore> {
return true;
}
default void applyToRegion(T store, Region region) {}
default void applyToRegion(T store, Region region) {
}
ObservableValue<String> getName(T store);
String getIcon(T store);
default void execute(T store) throws Exception {}
default void execute(T store) throws Exception {
}
}

View file

@ -52,7 +52,8 @@ public class DataStoreProviders {
String.join("-", split),
split.stream()
.map(s -> s.equals(split.get(0)) ? s : s.substring(0, 1).toUpperCase() + s.substring(1))
.collect(Collectors.joining()));
.collect(Collectors.joining())
);
}
@SuppressWarnings("unchecked")

View file

@ -2,7 +2,8 @@ package io.xpipe.extension;
public class ExtensionException extends RuntimeException {
public ExtensionException() {}
public ExtensionException() {
}
public ExtensionException(String message) {
super(message);

View file

@ -23,8 +23,12 @@ public abstract class EventHandler {
@Override
public void handle(ErrorEvent ee) {
if (ee.getDescription() != null) System.err.println(ee.getDescription());
if (ee.getThrowable() != null) ee.getThrowable().printStackTrace();
if (ee.getDescription() != null) {
System.err.println(ee.getDescription());
}
if (ee.getThrowable() != null) {
ee.getThrowable().printStackTrace();
}
}
};
@ -42,13 +46,12 @@ public abstract class EventHandler {
public void handle(ErrorEvent ee) {
}
};
private static EventHandler INSTANCE;
public static void set(EventHandler handler) {
INSTANCE = handler;
}
private static EventHandler INSTANCE;
private static void init() {
if (INSTANCE == null) {
INSTANCE = ServiceLoader.load(EventHandler.class).findFirst().orElse(DEFAULT);

View file

@ -14,22 +14,20 @@ import java.util.stream.Collectors;
@Getter
public class TrackEvent {
public static TrackEventBuilder storage() {
return TrackEvent.builder().category("storage");
}
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<Object> elements;
public static TrackEventBuilder storage() {
return TrackEvent.builder().category("storage");
}
public static TrackEventBuilder fromMessage(String type, String message) {
return builder().type(type).message(message);
}
@ -115,10 +113,10 @@ public class TrackEvent {
var valueString = e.getValue() != null ? e.getValue().toString() : "null";
var value = valueString.contains("\n")
? "\n"
+ (valueString.toString()
.lines()
.map(line -> " | " + line)
.collect(Collectors.joining("\n")))
+ (valueString.toString()
.lines()
.map(line -> " | " + line)
.collect(Collectors.joining("\n")))
: valueString;
s.append(" ")
.append(e.getKey())

View file

@ -20,7 +20,8 @@ public class CharChoiceComp extends Comp<CompStructure<HBox>> {
public CharChoiceComp(
Property<Character> value,
Map<Character, ObservableValue<String>> range,
ObservableValue<String> customName) {
ObservableValue<String> customName
) {
this.value = value;
this.range = range;
this.customName = customName;

View file

@ -22,10 +22,11 @@ public class CharsetChoiceComp extends SimpleComp {
charset,
streamCharset -> {
return new Label(streamCharset.getCharset().displayName()
+ (streamCharset.hasByteOrderMark() ? " (BOM)" : ""));
+ (streamCharset.hasByteOrderMark() ? " (BOM)" : ""));
},
new Label(I18n.get("extension.none")),
null);
null
);
builder.addFilter((charset, filter) -> {
return charset.getCharset().displayName().contains(filter);
});
@ -38,7 +39,7 @@ public class CharsetChoiceComp extends SimpleComp {
for (var e : StreamCharset.RARE) {
builder.add(e);
}
var comboBox = builder.build();
var comboBox = builder.build();
comboBox.setVisibleRowCount(16);
return comboBox;
}

View file

@ -18,7 +18,10 @@ 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;

View file

@ -20,7 +20,10 @@ 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>> {
@ -75,5 +78,6 @@ public class ChoicePaneComp extends Comp<CompStructure<VBox>> {
return new SimpleCompStructure<>(vbox);
}
public record Entry(ObservableValue<String> name, Comp<?> comp) {}
public record Entry(ObservableValue<String> name, Comp<?> comp) {
}
}

View file

@ -120,7 +120,9 @@ public record CodeSnippet(List<CodeSnippet.Line> lines) {
}
}
public record Line(List<CodeSnippet.Element> elements) {}
public record Line(List<CodeSnippet.Element> elements) {
}
public record ColorScheme(Color keyword, Color identifier, Color type, Color string) {}
public record ColorScheme(Color keyword, Color identifier, Color type, Color string) {
}
}

View file

@ -104,7 +104,8 @@ public class DynamicOptionsComp extends Comp<CompStructure<Pane>> {
.orElse(0.0);
return m;
},
compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
compRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])
);
compRegions.forEach(r -> r.prefWidthProperty().bind(compWidthBinding));
}
@ -121,7 +122,8 @@ public class DynamicOptionsComp extends Comp<CompStructure<Pane>> {
.orElse(0.0);
return m;
},
nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0]));
nameRegions.stream().map(Region::widthProperty).toList().toArray(new Observable[0])
);
nameRegions.forEach(r -> r.prefWidthProperty().bind(nameWidthBinding));
}
@ -132,5 +134,6 @@ public class DynamicOptionsComp extends Comp<CompStructure<Pane>> {
return entries;
}
public record Entry(String key, ObservableValue<String> name, Comp<?> comp) {}
public record Entry(String key, ObservableValue<String> name, Comp<?> comp) {
}
}

View file

@ -22,6 +22,36 @@ import javafx.util.Duration;
public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<S> {
private static final TooltipBehavior BEHAVIOR = new TooltipBehavior(Duration.millis(400), Duration.INDEFINITE, Duration.millis(100));
private final ObservableValue<String> text;
public FancyTooltipAugment(ObservableValue<String> text) {
this.text = PlatformThread.sync(text);
}
public FancyTooltipAugment(String key) {
this.text = I18n.observable(key);
}
@Override
public void augment(S struc) {
augment(struc.get());
}
public void augment(Node region) {
var tt = new JFXTooltip();
var toDisplay = text.getValue();
if (Shortcuts.getShortcut((Region) region) != null) {
toDisplay =
toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")";
}
tt.textProperty().setValue(toDisplay);
tt.setStyle("-fx-font-size: 11pt;");
tt.setWrapText(true);
tt.setMaxWidth(400);
tt.getStyleClass().add("fancy-tooltip");
BEHAVIOR.install(region, tt);
}
private static class TooltipBehavior {
@ -37,10 +67,40 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
* the next tooltip to be shown
*/
private JFXTooltip nextTooltip;
private final EventHandler<MouseEvent> exitHandler = (MouseEvent event) -> {
// stop running hover timer as the mouse exited the node
if (hoverTimer.getStatus() == Timeline.Status.RUNNING) {
hoverTimer.stop();
} else if (visibleTimer.getStatus() == Timeline.Status.RUNNING) {
// if tool tip was already showing, stop the visible timer
// and start the left timer to hide the current tooltip
visibleTimer.stop();
leftTimer.playFromStart();
}
hoveredNode = null;
nextTooltip = null;
};
private final WeakEventHandler<MouseEvent> weakExitHandler = new WeakEventHandler<>(exitHandler);
/**
* the current showing tooltip
*/
private JFXTooltip currentTooltip;
// if mouse is pressed then stop all timers / clear all fields
private final EventHandler<MouseEvent> pressedHandler = (MouseEvent event) -> {
// stop timers
hoverTimer.stop();
visibleTimer.stop();
leftTimer.stop();
// hide current tooltip
if (currentTooltip != null) {
currentTooltip.hide();
}
// clear fields
hoveredNode = null;
currentTooltip = null;
nextTooltip = null;
};
private final WeakEventHandler<MouseEvent> weakPressedHandler = new WeakEventHandler<>(pressedHandler);
private TooltipBehavior(Duration hoverDelay, Duration visibleDuration, Duration leftDelay) {
setHoverDelay(hoverDelay);
@ -71,24 +131,7 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
private void setVisibleDuration(Duration duration) {
visibleTimer.getKeyFrames().setAll(new KeyFrame(duration));
}
private void setLeftDelay(Duration duration) {
leftTimer.getKeyFrames().setAll(new KeyFrame(duration));
}
private void hideCurrentTooltip() {
currentTooltip.hide();
currentTooltip = null;
hoveredNode = null;
}
private void showTooltip(JFXTooltip tooltip) {
// anchors are computed differently for each tooltip
tooltip.show(hoveredNode, -1, -1);
}
private final EventHandler<MouseEvent> moveHandler = (MouseEvent event) -> {
} private final EventHandler<MouseEvent> moveHandler = (MouseEvent event) -> {
// if tool tip is already showing, do nothing
if (visibleTimer.getStatus() == Timeline.Status.RUNNING) {
return;
@ -123,39 +166,21 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
uninstall(hoveredNode);
}
};
private final WeakEventHandler<MouseEvent> weakMoveHandler = new WeakEventHandler<>(moveHandler);
private final EventHandler<MouseEvent> exitHandler = (MouseEvent event) -> {
// stop running hover timer as the mouse exited the node
if (hoverTimer.getStatus() == Timeline.Status.RUNNING) {
hoverTimer.stop();
} else if (visibleTimer.getStatus() == Timeline.Status.RUNNING) {
// if tool tip was already showing, stop the visible timer
// and start the left timer to hide the current tooltip
visibleTimer.stop();
leftTimer.playFromStart();
}
hoveredNode = null;
nextTooltip = null;
};
private final WeakEventHandler<MouseEvent> weakExitHandler = new WeakEventHandler<>(exitHandler);
private void setLeftDelay(Duration duration) {
leftTimer.getKeyFrames().setAll(new KeyFrame(duration));
} private final WeakEventHandler<MouseEvent> weakMoveHandler = new WeakEventHandler<>(moveHandler);
// if mouse is pressed then stop all timers / clear all fields
private final EventHandler<MouseEvent> pressedHandler = (MouseEvent event) -> {
// stop timers
hoverTimer.stop();
visibleTimer.stop();
leftTimer.stop();
// hide current tooltip
if (currentTooltip != null) {
currentTooltip.hide();
}
// clear fields
hoveredNode = null;
private void hideCurrentTooltip() {
currentTooltip.hide();
currentTooltip = null;
nextTooltip = null;
};
private final WeakEventHandler<MouseEvent> weakPressedHandler = new WeakEventHandler<>(pressedHandler);
hoveredNode = null;
}
private void showTooltip(JFXTooltip tooltip) {
// anchors are computed differently for each tooltip
tooltip.show(hoveredNode, -1, -1);
}
private void install(Node node, JFXTooltip tooltip) {
if (node == null) {
@ -204,36 +229,9 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
final Scene scene = node == null ? null : node.getScene();
return scene == null ? null : scene.getWindow();
}
}
private final ObservableValue<String> text;
public FancyTooltipAugment(ObservableValue<String> text) {
this.text = PlatformThread.sync(text);
}
public FancyTooltipAugment(String key) {
this.text = I18n.observable(key);
}
@Override
public void augment(S struc) {
augment(struc.get());
}
public void augment(Node region) {
var tt = new JFXTooltip();
var toDisplay = text.getValue();
if (Shortcuts.getShortcut((Region) region) != null) {
toDisplay =
toDisplay + " (" + Shortcuts.getShortcut((Region) region).getDisplayText() + ")";
}
tt.textProperty().setValue(toDisplay);
tt.setStyle("-fx-font-size: 11pt;");
tt.setWrapText(true);
tt.setMaxWidth(400);
tt.getStyleClass().add("fancy-tooltip");
BEHAVIOR.install(region, tt);
}
}

View file

@ -11,7 +11,10 @@ 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;

View file

@ -37,7 +37,8 @@ public class PrettyImageComp extends SimpleComp {
return height * aspectRatioProperty.doubleValue();
}
},
aspectRatioProperty);
aspectRatioProperty
);
var heightProperty = Bindings.createDoubleBinding(
() -> {
boolean widthLimited = width / height < aspectRatioProperty.doubleValue();
@ -47,7 +48,8 @@ public class PrettyImageComp extends SimpleComp {
return height;
}
},
aspectRatioProperty);
aspectRatioProperty
);
Node node;
@ -60,7 +62,8 @@ public class PrettyImageComp extends SimpleComp {
/ storeIcon.getHeight().getValue().doubleValue();
},
storeIcon.getWidth(),
storeIcon.getHeight()));
storeIcon.getHeight()
));
node = storeIcon.createWebview();
((WebView) node).prefWidthProperty().bind(widthProperty);
((WebView) node).maxWidthProperty().bind(widthProperty);
@ -78,7 +81,8 @@ public class PrettyImageComp extends SimpleComp {
aspectRatioProperty.set(image.getWidth() / image.getHeight());
return image;
},
PlatformThread.sync(value)));
PlatformThread.sync(value)
));
storeIcon.fitWidthProperty().bind(widthProperty);
storeIcon.fitHeightProperty().bind(heightProperty);
storeIcon.setSmooth(true);

View file

@ -76,9 +76,9 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
});
var available = XPipeDaemon.getInstance().getNamedStores().stream()
.filter(s -> s != self)
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
.map(s -> (ShellStore) s)
.filter(s -> s != self)
.filter(s -> storeClass.isAssignableFrom(s.getClass()) && applicableCheck.test((T) s))
.map(s -> (ShellStore) s)
.toList();
available.forEach(s -> comboBox.add((T) s));
ComboBox<Node> cb = comboBox.build();

View file

@ -40,7 +40,8 @@ public class SvgComp {
return new Size(
Double.parseDouble(string.substring(
0, string.length() - unit.toString().length())),
unit);
unit
);
}
}
return new Size(Double.parseDouble(string), SizeUnits.PX);
@ -96,7 +97,8 @@ public class SvgComp {
return wv.getWidth() / width.getValue().doubleValue();
},
wv.widthProperty(),
width));
width
));
wv.maxWidthProperty().bind(wv.prefWidthProperty());
wv.maxHeightProperty().bind(wv.prefHeightProperty());

View file

@ -20,6 +20,7 @@ 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;
@ -59,5 +60,6 @@ public class TabPaneComp extends Comp<CompStructure<JFXTabPane>> {
return new SimpleCompStructure<>(tabPane);
}
public record Entry(ObservableValue<String> name, String graphic, Comp<?> comp) {}
public record Entry(ObservableValue<String> name, String graphic, Comp<?> comp) {
}
}

View file

@ -57,7 +57,7 @@ public class TextAreaComp extends SimpleComp {
var isEqual = Bindings.createBooleanBinding(() -> Objects.equals(lazyValue.getValue(), value.getValue()), value, lazyValue);
var button = new IconButtonComp("mdi2c-checkbox-marked-outline").hide(isEqual).createRegion();
var anchorPane = new AnchorPane(text, button);
AnchorPane.setBottomAnchor(button, 5.0 );
AnchorPane.setBottomAnchor(button, 5.0);
AnchorPane.setRightAnchor(button, 5.0);
text.prefWidthProperty().bind(anchorPane.widthProperty());

View file

@ -64,7 +64,9 @@ public class ToggleGroupComp<T> extends Comp<CompStructure<HBox>> {
});
group.selectedToggleProperty().addListener((obsVal, oldVal, newVal) -> {
if (newVal == null) oldVal.setSelected(true);
if (newVal == null) {
oldVal.setSelected(true);
}
});
return new SimpleCompStructure<>(box);

View file

@ -43,13 +43,13 @@ public class WriteModeChoiceComp extends SimpleComp implements Validatable {
var a = available;
Property<Map<WriteMode, ObservableValue<String>>> map = new SimpleObjectProperty<>(new LinkedHashMap<WriteMode, ObservableValue<String>>());
for (WriteMode writeMode : a) {
map.getValue().put(writeMode,I18n.observable(writeMode.getId()));
map.getValue().put(writeMode, I18n.observable(writeMode.getId()));
}
PlatformThread.sync(available).addListener((ListChangeListener<? super WriteMode>) c -> {
var newMap = new LinkedHashMap<WriteMode, ObservableValue<String>>();
for (WriteMode writeMode : c.getList()) {
newMap.put(writeMode,I18n.observable(writeMode.getId()));
newMap.put(writeMode, I18n.observable(writeMode.getId()));
}
map.setValue(newMap);

View file

@ -20,8 +20,9 @@ public class BindingsHelper {
public static <T extends Binding<?>> T persist(T binding) {
var dependencies = new HashSet<ObservableValue<?>>();
while (dependencies.addAll(binding.getDependencies().stream()
.map(o -> (ObservableValue<?>) o)
.toList())) {}
.map(o -> (ObservableValue<?>) o)
.toList())) {
}
dependencies.add(binding);
BINDINGS.put(new WeakReference<>(binding), dependencies);
return binding;

View file

@ -39,7 +39,7 @@ public interface PrefsChoiceValue extends Translatable {
throw new AssertionError();
}
return all.stream().filter(t -> ((PrefsChoiceValue)t).isSupported()).toList();
return all.stream().filter(t -> ((PrefsChoiceValue) t).isSupported()).toList();
}
}

View file

@ -6,5 +6,5 @@ import java.util.List;
public interface PrefsHandler {
void addSetting(List<String> category, String group, Setting<?,?> setting, Class<?> c);
void addSetting(List<String> category, String group, Setting<?, ?> setting, Class<?> c);
}

View file

@ -9,11 +9,6 @@ import java.util.stream.Collectors;
public abstract class PrefsProvider {
protected <T extends Field<?>> T editable(T o, ObservableBooleanValue v) {
o.editableProperty().bind(v);
return o;
}
private static Set<PrefsProvider> ALL;
public static void init(ModuleLayer layer) {
@ -33,5 +28,10 @@ public abstract class PrefsProvider {
return (T) ALL.stream().filter(prefsProvider -> prefsProvider.getClass().equals(c)).findAny().orElseThrow();
}
protected <T extends Field<?>> T editable(T o, ObservableBooleanValue v) {
o.editableProperty().bind(v);
return o;
}
public abstract void addPrefs(PrefsHandler handler);
}

View file

@ -104,6 +104,7 @@ public class ChainedValidator implements Validator {
.map(v -> v.createStringBinding(prefix, separator).get())
.collect(Collectors.joining("\n"));
},
observables);
observables
);
}
}

View file

@ -37,7 +37,8 @@ public class CustomComboBoxBuilder<T> {
private Node filterNode;
public CustomComboBoxBuilder(
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto) {
Property<T> selected, Function<T, Node> nodeFunction, Node emptyNode, Predicate<T> veto
) {
this.selected = selected;
this.nodeFunction = nodeFunction;
this.emptyNode = emptyNode;
@ -122,9 +123,9 @@ public class CustomComboBoxBuilder<T> {
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))))
&& (filterable.contains(nodeMap.get(e))
&& filterString.getValue() != null
&& !filterPredicate.test(nodeMap.get(e), c))))
.toList();
cb.setItems(FXCollections.observableList(filteredNodes));
});

View file

@ -92,7 +92,8 @@ public class DataStoreFormatter {
var lengthShare = (length - 3) / 2;
return String.format(
"%s.%s",
DataStoreFormatter.cut(name, lengthShare), DataStoreFormatter.cut(region, length - lengthShare));
DataStoreFormatter.cut(name, lengthShare), DataStoreFormatter.cut(region, length - lengthShare)
);
}
return cut(input, length);

View file

@ -76,7 +76,8 @@ public class DynamicOptionsBuilder {
}
public DynamicOptionsBuilder addCharacter(
Property<Character> prop, ObservableValue<String> name, Map<Character, ObservableValue<String>> names) {
Property<Character> prop, ObservableValue<String> name, Map<Character, ObservableValue<String>> names
) {
var comp = new CharChoiceComp(prop, names, null);
entries.add(new DynamicOptionsComp.Entry(null, name, comp));
props.add(prop);
@ -87,23 +88,28 @@ public class DynamicOptionsBuilder {
Property<Character> prop,
ObservableValue<String> name,
Map<Character, ObservableValue<String>> names,
ObservableValue<String> customName) {
ObservableValue<String> customName
) {
var comp = new CharChoiceComp(prop, names, customName);
entries.add(new DynamicOptionsComp.Entry(null, name, comp));
props.add(prop);
return this;
}
public DynamicOptionsBuilder addToggle(String nameKey,
Property<Boolean> prop) {
var comp = new ToggleGroupComp<>(prop, new SimpleObjectProperty<>(Map.of(Boolean.TRUE, I18n.observable("extension.yes"), Boolean.FALSE, I18n.observable("extension.no"))));
public DynamicOptionsBuilder addToggle(
String nameKey,
Property<Boolean> prop
) {
var comp = new ToggleGroupComp<>(prop, new SimpleObjectProperty<>(
Map.of(Boolean.TRUE, I18n.observable("extension.yes"), Boolean.FALSE, I18n.observable("extension.no"))));
entries.add(new DynamicOptionsComp.Entry(nameKey, I18n.observable(nameKey), comp));
props.add(prop);
return this;
}
public <V> DynamicOptionsBuilder addToggle(
Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names) {
Property<V> prop, ObservableValue<String> name, Map<V, ObservableValue<String>> names
) {
var comp = new ToggleGroupComp<>(prop, new SimpleObjectProperty<>(names));
entries.add(new DynamicOptionsComp.Entry(null, name, comp));
props.add(prop);
@ -180,13 +186,17 @@ public class DynamicOptionsBuilder {
public DynamicOptionsBuilder addComp(String nameKey, Comp<?> comp, Property<?> prop) {
entries.add(new DynamicOptionsComp.Entry(nameKey, I18n.observable(nameKey), comp));
if (prop != null) props.add(prop);
if (prop != null) {
props.add(prop);
}
return this;
}
public DynamicOptionsBuilder addComp(ObservableValue<String> name, Comp<?> comp, Property<?> prop) {
entries.add(new DynamicOptionsComp.Entry(null, name, comp));
if (prop != null) props.add(prop);
if (prop != null) {
props.add(prop);
}
return this;
}
@ -231,7 +241,8 @@ public class DynamicOptionsBuilder {
}
public final <T, V extends T> DynamicOptionsBuilder bindChoice(
Supplier<Property<? extends V>> creator, Property<T> toSet) {
Supplier<Property<? extends V>> creator, Property<T> toSet
) {
props.forEach(prop -> {
prop.addListener((c, o, n) -> {
toSet.unbind();
@ -247,7 +258,8 @@ public class DynamicOptionsBuilder {
entries.add(
0,
new DynamicOptionsComp.Entry(
null, null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header")));
null, null, Comp.of(() -> new Label(title.getValue())).styleClass("title-header"))
);
}
return new DynamicOptionsComp(entries, wrap);
}

View file

@ -81,6 +81,7 @@ public final class ExclusiveValidator<T> implements Validator {
() -> {
return get().createStringBinding(prefix, separator).get();
},
observables);
observables
);
}
}

View file

@ -20,6 +20,7 @@ public class ExecScriptHelper {
return createExecScript(l, content);
}
}
@SneakyThrows
public static String createExecScript(ShellProcessControl processControl, String content) {
var fileName = "exec-" + getConnectionHash(content);
@ -35,7 +36,8 @@ public class ExecScriptHelper {
try (var c = processControl.command(processControl.getShellType()
.joinCommands(
processControl.getShellType().createFileWriteCommand(file),
processControl.getShellType().getMakeExecutableCommand(file)))
processControl.getShellType().getMakeExecutableCommand(file)
))
.start()) {
c.discardOut();
c.discardErr();

View file

@ -15,6 +15,7 @@ public class PrettyListView<T> extends ListView<T> {
private final ScrollBar vBar = new ScrollBar();
private final ScrollBar hBar = new ScrollBar();
public PrettyListView() {
super();
skinProperty().addListener(it -> {
@ -78,14 +79,16 @@ public class PrettyListView<T> extends ListView<T> {
w - prefWidth - insets.getRight(),
insets.getTop(),
prefWidth,
h - insets.getTop() - insets.getBottom());
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);
prefHeight
);
}
public static class NoSelectionModel<T> extends MultipleSelectionModel<T> {
@ -101,31 +104,40 @@ public class PrettyListView<T> extends ListView<T> {
}
@Override
public void selectIndices(int index, int... indices) {}
public void selectIndices(int index, int... indices) {
}
@Override
public void selectAll() {}
public void selectAll() {
}
@Override
public void selectFirst() {}
public void selectFirst() {
}
@Override
public void selectLast() {}
public void selectLast() {
}
@Override
public void clearAndSelect(int index) {}
public void clearAndSelect(int index) {
}
@Override
public void select(int index) {}
public void select(int index) {
}
@Override
public void select(T obj) {}
public void select(T obj) {
}
@Override
public void clearSelection(int index) {}
public void clearSelection(int index) {
}
@Override
public void clearSelection() {}
public void clearSelection() {
}
@Override
public boolean isSelected(int index) {
@ -138,9 +150,11 @@ public class PrettyListView<T> extends ListView<T> {
}
@Override
public void selectPrevious() {}
public void selectPrevious() {
}
@Override
public void selectNext() {}
public void selectNext() {
}
}
}

View file

@ -22,7 +22,9 @@ public class SimpleValidator implements Validator {
new ReadOnlyObjectWrapper<>(new ValidationResult());
private final ReadOnlyBooleanWrapper containsErrorsProperty = new ReadOnlyBooleanWrapper();
/** Create a check that lives within this checker's domain.
/**
* Create a check that lives within this checker's domain.
*
* @return A check object whose dependsOn, decorates, etc. methods can be called
*/
public Check createCheck() {
@ -31,7 +33,9 @@ public class SimpleValidator implements Validator {
return check;
}
/** Add another check to the checker. Changes in the check's validationResultProperty will be reflected in the checker.
/**
* Add another check to the checker. Changes in the check's validationResultProperty will be reflected in the checker.
*
* @param check The check to add.
*/
public void add(Check check) {
@ -40,7 +44,9 @@ public class SimpleValidator implements Validator {
check.validationResultProperty().addListener(listener);
}
/** Removes a check from this validator.
/**
* Removes a check from this validator.
*
* @param check The check to remove from this validator.
*/
public void remove(Check check) {
@ -51,21 +57,27 @@ public class SimpleValidator implements Validator {
refreshProperties();
}
/** Retrieves current validation result
/**
* Retrieves current validation result
*
* @return validation result
*/
public ValidationResult getValidationResult() {
return validationResultProperty.get();
}
/** Can be used to track validation result changes
/**
* Can be used to track validation result changes
*
* @return The Validation result property.
*/
public ReadOnlyObjectProperty<ValidationResult> validationResultProperty() {
return validationResultProperty.getReadOnlyProperty();
}
/** A read-only boolean property indicating whether any of the checks of this validator emitted an error. */
/**
* A read-only boolean property indicating whether any of the checks of this validator emitted an error.
*/
public ReadOnlyBooleanProperty containsErrorsProperty() {
return containsErrorsProperty.getReadOnlyProperty();
}
@ -74,7 +86,9 @@ public class SimpleValidator implements Validator {
return containsErrorsProperty().get();
}
/** Run all checks (decorating nodes if appropriate)
/**
* Run all checks (decorating nodes if appropriate)
*
* @return true if no errors were found, false otherwise
*/
public boolean validate() {
@ -97,7 +111,8 @@ public class SimpleValidator implements Validator {
containsErrorsProperty.set(hasErrors);
}
/** Create a string property that depends on the validation result.
/**
* Create a string property that depends on the validation result.
* Each error message will be displayed on a separate line prefixed with a bullet.
*/
public StringBinding createStringBinding() {
@ -117,6 +132,7 @@ public class SimpleValidator implements Validator {
}
return str.toString();
},
validationResultProperty);
validationResultProperty
);
}
}

View file

@ -11,7 +11,7 @@ public class WindowsRegistry {
public static final int HKEY_LOCAL_MACHINE = 0x80000002;
public static Optional<String> readString(int hkey, String key) {
return readString(hkey,key, null);
return readString(hkey, key, null);
}
public static Optional<String> readString(int hkey, String key, String valueName) {

View file

@ -29,6 +29,7 @@ public interface XPipeDaemon {
}
void withResource(String module, String file, Charsetter.FailableConsumer<Path, IOException> con);
List<DataStore> getNamedStores();
String getVersion();
@ -41,20 +42,24 @@ public interface XPipeDaemon {
Property<DataStore> storeProperty,
Property<DataSourceProvider<?>> provider,
boolean showAnonymous,
boolean showSaved);
boolean showSaved
);
<T extends Comp<?> & Validatable> T namedStoreChooser(
ObservableValue<Predicate<DataStore>> filter,
Property<? extends DataStore> selected,
DataStoreProvider.Category category);
DataStoreProvider.Category category
);
<T extends Comp<?> & Validatable> T namedSourceChooser(
ObservableValue<Predicate<DataSource<?>>> filter,
Property<? extends DataSource<?>> selected,
DataSourceProvider.Category category);
DataSourceProvider.Category category
);
<T extends Comp<?> & Validatable> T sourceProviderChooser(
Property<DataSourceProvider<?>> provider, DataSourceProvider.Category category, DataSourceType filter);
Property<DataSourceProvider<?>> provider, DataSourceProvider.Category category, DataSourceType filter
);
Optional<DataStore> getNamedStore(String name);