mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-06-21 22:09:09 -04:00
Various small fixes [release]
This commit is contained in:
@@ -62,7 +62,7 @@ public class DataStoreSelectorComp extends Comp<CompStructure<Button>> {
|
||||
AppI18n.get("selectStreamStore"), AppI18n.get("openStreamStoreWizard"), graphic);
|
||||
} else {
|
||||
return JfxHelper.createNamedEntry(
|
||||
f.getFileName().toString(), f.getFile().toString(), graphic);
|
||||
f.getFileName().toString(), f.getPath().toString(), graphic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,11 +65,11 @@ public class DsLocalFileBrowseComp extends Comp<CompStructure<Button>> {
|
||||
|
||||
private Region getGraphic() {
|
||||
var graphic = hasProvider() ? provider.getValue().getDisplayIconFileName() : "file_icon.png";
|
||||
if (chosenFile.getValue() == null || !(chosenFile.getValue() instanceof FileStore f) || f.getFile() == null) {
|
||||
if (chosenFile.getValue() == null || !(chosenFile.getValue() instanceof FileStore f) || f.getPath() == null) {
|
||||
return JfxHelper.createNamedEntry(AppI18n.get("browse"), AppI18n.get("selectFileFromComputer"), graphic);
|
||||
} else {
|
||||
return JfxHelper.createNamedEntry(
|
||||
f.getFileName().toString(), f.getFile().toString(), graphic);
|
||||
f.getFileName().toString(), f.getPath().toString(), graphic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DsRemoteFileChoiceComp extends SimpleComp {
|
||||
|
||||
return FileStore.builder()
|
||||
.fileSystem(machine.get())
|
||||
.file(fileName.get())
|
||||
.path(fileName.get())
|
||||
.build();
|
||||
},
|
||||
store)
|
||||
|
||||
@@ -85,6 +85,12 @@ public class GuiDsStoreCreator extends MultiStepComp.Step<CompStructure<?>> {
|
||||
r.get().setPrefWidth(AppFont.em(36));
|
||||
r.get().setPrefHeight(AppFont.em(42));
|
||||
});
|
||||
|
||||
this.validator.addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
newValue.validate();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void showEdit(DataStoreEntry e) {
|
||||
|
||||
@@ -155,7 +155,7 @@ public class StoreEntryComp extends SimpleComp {
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
var found = entry.getDefaultActionProvider().getValue();
|
||||
if (found != null) {
|
||||
found.getDataStoreCallSite()
|
||||
found
|
||||
.createAction(entry.getEntry().getStore().asNeeded())
|
||||
.execute();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStoreEntry;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -31,7 +28,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
|
||||
private final StringProperty information = new SimpleStringProperty();
|
||||
private final StringProperty summary = new SimpleStringProperty();
|
||||
private final Map<ActionProvider, BooleanProperty> actionProviders;
|
||||
private final ObservableValue<ActionProvider> defaultActionProvider;
|
||||
private final Property<ActionProvider.DefaultDataStoreCallSite<?>> defaultActionProvider;
|
||||
private final BooleanProperty editable = new SimpleBooleanProperty();
|
||||
private final BooleanProperty renamable = new SimpleBooleanProperty();
|
||||
private final BooleanProperty refreshable = new SimpleBooleanProperty();
|
||||
@@ -54,16 +51,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
|
||||
.forEach(dataStoreActionProvider -> {
|
||||
actionProviders.put(dataStoreActionProvider, new SimpleBooleanProperty(true));
|
||||
});
|
||||
this.defaultActionProvider = Bindings.createObjectBinding(
|
||||
() -> {
|
||||
var found = actionProviders.entrySet().stream()
|
||||
.filter(e -> e.getValue().get())
|
||||
.filter(e -> e.getKey().getDataStoreCallSite() != null
|
||||
&& e.getKey().getDataStoreCallSite().isDefault())
|
||||
.findFirst();
|
||||
return found.map(p -> p.getKey()).orElse(null);
|
||||
},
|
||||
actionProviders.values().toArray(Observable[]::new));
|
||||
this.defaultActionProvider = new SimpleObjectProperty<>();
|
||||
setupListeners();
|
||||
update();
|
||||
}
|
||||
@@ -126,6 +114,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
|
||||
actionProviders.keySet().forEach(dataStoreActionProvider -> {
|
||||
if (!isInStorage()) {
|
||||
actionProviders.get(dataStoreActionProvider).set(false);
|
||||
defaultActionProvider.setValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,6 +127,12 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
|
||||
return;
|
||||
}
|
||||
|
||||
var defaultProvider = ActionProvider.ALL.stream()
|
||||
.filter(e -> e.getDefaultDataStoreCallSite() != null
|
||||
&& e.getDefaultDataStoreCallSite().isApplicable(entry.getStore().asNeeded()))
|
||||
.findFirst().map(ActionProvider::getDefaultDataStoreCallSite).orElse(null);
|
||||
this.defaultActionProvider.setValue(defaultProvider);
|
||||
|
||||
try {
|
||||
actionProviders
|
||||
.get(dataStoreActionProvider)
|
||||
|
||||
@@ -68,11 +68,26 @@ public interface ActionProvider {
|
||||
default DataStoreCallSite<?> getDataStoreCallSite() {
|
||||
return null;
|
||||
}
|
||||
default DefaultDataStoreCallSite<?> getDefaultDataStoreCallSite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default DataSourceCallSite<?> getDataSourceCallSite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static interface DefaultDataStoreCallSite<T extends DataStore> {
|
||||
|
||||
Action createAction(T store);
|
||||
|
||||
Class<T> getApplicableClass();
|
||||
|
||||
default boolean isApplicable(T o) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface DataStoreCallSite<T extends DataStore> {
|
||||
|
||||
enum ActiveType {
|
||||
@@ -85,10 +100,6 @@ public interface ActionProvider {
|
||||
|
||||
Class<T> getApplicableClass();
|
||||
|
||||
default boolean isDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isMajor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,12 +33,12 @@ public class FileStoreChoiceComp extends SimpleComp {
|
||||
@Override
|
||||
protected Region createSimple() {
|
||||
var fileProperty = new SimpleStringProperty(
|
||||
selected.getValue() != null ? selected.getValue().getFile() : null);
|
||||
selected.getValue() != null ? selected.getValue().getPath() : null);
|
||||
fileProperty.addListener((observable, oldValue, newValue) -> {
|
||||
setSelected(selected.getValue().getFileSystem(), newValue);
|
||||
});
|
||||
selected.addListener((observable, oldValue, newValue) -> {
|
||||
fileProperty.setValue(newValue.getFile());
|
||||
fileProperty.setValue(newValue.getPath());
|
||||
});
|
||||
|
||||
var fileSystemChoiceComp = new FileSystemStoreChoiceComp(selected).grow(false, true).styleClass(Styles.LEFT_PILL);
|
||||
|
||||
@@ -51,12 +51,12 @@ public class FileSystemStoreChoiceComp extends SimpleComp {
|
||||
fileSystemProperty.addListener((observable, oldValue, newValue) -> {
|
||||
selected.setValue(FileStore.builder()
|
||||
.fileSystem(newValue)
|
||||
.file(selected.getValue() != null ? selected.getValue().getFile() : null)
|
||||
.path(selected.getValue() != null ? selected.getValue().getPath() : null)
|
||||
.build());
|
||||
});
|
||||
|
||||
selected.addListener((observable, oldValue, newValue) -> {
|
||||
fileSystemProperty.setValue(newValue.getFileSystem());
|
||||
fileSystemProperty.setValue(newValue != null?newValue.getFileSystem():null);
|
||||
});
|
||||
|
||||
var comboBox =
|
||||
|
||||
@@ -7,8 +7,8 @@ import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.core.AppWindowHelper;
|
||||
import io.xpipe.app.fxcomps.SimpleComp;
|
||||
import io.xpipe.app.fxcomps.augment.GrowAugment;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.app.util.JfxHelper;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Separator;
|
||||
@@ -20,6 +20,8 @@ import javafx.stage.Stage;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static atlantafx.base.theme.Styles.ACCENT;
|
||||
@@ -37,27 +39,67 @@ public class ErrorHandlerComp extends SimpleComp {
|
||||
}
|
||||
|
||||
public static void showAndWait(ErrorEvent event) {
|
||||
PlatformThread.runLaterIfNeededBlocking(() -> {
|
||||
synchronized (showing) {
|
||||
if (!showing.get()) {
|
||||
showing.set(true);
|
||||
var window = AppWindowHelper.sideWindow(
|
||||
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
|
||||
window.setOnHidden(e -> {
|
||||
showing.set(false);
|
||||
});
|
||||
if (Platform.isFxApplicationThread()) {
|
||||
showAndWaitWithPlatformThread(event);
|
||||
} else {
|
||||
showAndWaitWithOtherThread(event);
|
||||
}
|
||||
}
|
||||
|
||||
// An exception is thrown when show and wait is called
|
||||
// within an animation or layout processing task
|
||||
try {
|
||||
window.showAndWait();
|
||||
} catch (Throwable t) {
|
||||
window.show();
|
||||
t.printStackTrace();
|
||||
}
|
||||
public static void showAndWaitWithPlatformThread(ErrorEvent event) {
|
||||
var finishLatch = new CountDownLatch(1);
|
||||
if (!showing.get()) {
|
||||
showing.set(true);
|
||||
var window = AppWindowHelper.sideWindow(
|
||||
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
|
||||
window.setOnHidden(e -> {
|
||||
showing.set(false);
|
||||
finishLatch.countDown();
|
||||
});
|
||||
|
||||
// An exception is thrown when show and wait is called
|
||||
// within an animation or layout processing task, so use show
|
||||
try {
|
||||
window.show();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAndWaitWithOtherThread(ErrorEvent event) {
|
||||
var showLatch = new CountDownLatch(1);
|
||||
var finishLatch = new CountDownLatch(1);
|
||||
Platform.runLater(() -> {
|
||||
if (!showing.get()) {
|
||||
showing.set(true);
|
||||
var window = AppWindowHelper.sideWindow(
|
||||
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
|
||||
window.setOnHidden(e -> {
|
||||
showing.set(false);
|
||||
finishLatch.countDown();
|
||||
});
|
||||
|
||||
// An exception is thrown when show and wait is called
|
||||
// within an animation or layout processing task, so use show
|
||||
try {
|
||||
showLatch.countDown();
|
||||
window.show();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
// Only wait for a certain time in case we somehow deadlocked the platform thread
|
||||
if (showLatch.await(5, TimeUnit.SECONDS)) {
|
||||
finishLatch.await();
|
||||
} else {
|
||||
TrackEvent.error("Platform thread in error handler was timed out");
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private Region createActionComp(ErrorAction a) {
|
||||
|
||||
@@ -367,30 +367,32 @@ public abstract class DataStorage {
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void propagateUpdate() {
|
||||
private void propagateUpdate() {
|
||||
for (DataStoreEntry dataStoreEntry : getStoreEntries()) {
|
||||
dataStoreEntry.simpleRefresh();
|
||||
}
|
||||
|
||||
for (var e : sourceEntries) {
|
||||
for (var e : getSourceEntries()) {
|
||||
e.simpleRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addStoreEntry(@NonNull DataStoreEntry e) {
|
||||
public void addStoreEntry(@NonNull DataStoreEntry e) {
|
||||
if (getStoreEntryIfPresent(e.getName()).isPresent()) {
|
||||
throw new IllegalArgumentException("Store with name " + e.getName() + " already exists");
|
||||
}
|
||||
|
||||
e.setDirectory(getStoresDir().resolve(e.getUuid().toString()));
|
||||
this.storeEntries.add(e);
|
||||
synchronized (this) {
|
||||
e.setDirectory(getStoresDir().resolve(e.getUuid().toString()));
|
||||
this.storeEntries.add(e);
|
||||
}
|
||||
propagateUpdate();
|
||||
save();
|
||||
|
||||
this.listeners.forEach(l -> l.onStoreAdd(e));
|
||||
}
|
||||
|
||||
public synchronized void addStoreEntryIfNotPresent(@NonNull String name, DataStore store) {
|
||||
public void addStoreEntryIfNotPresent(@NonNull String name, DataStore store) {
|
||||
if (getStoreEntryIfPresent(store).isPresent()) {
|
||||
return;
|
||||
}
|
||||
@@ -399,21 +401,22 @@ public abstract class DataStorage {
|
||||
addStoreEntry(e);
|
||||
}
|
||||
|
||||
public synchronized DataStoreEntry addStoreEntry(@NonNull String name, DataStore store) {
|
||||
public DataStoreEntry addStoreEntry(@NonNull String name, DataStore store) {
|
||||
var e = DataStoreEntry.createNew(UUID.randomUUID(), createUniqueStoreEntryName(name), store);
|
||||
addStoreEntry(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
public synchronized void deleteStoreEntry(@NonNull DataStoreEntry store) {
|
||||
public void deleteStoreEntry(@NonNull DataStoreEntry store) {
|
||||
if (!store.getConfiguration().isDeletable()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
this.storeEntries.remove(store);
|
||||
synchronized (this) {
|
||||
this.storeEntries.remove(store);
|
||||
}
|
||||
propagateUpdate();
|
||||
save();
|
||||
|
||||
this.listeners.forEach(l -> l.onStoreRemove(store));
|
||||
}
|
||||
|
||||
@@ -421,7 +424,7 @@ public abstract class DataStorage {
|
||||
this.listeners.add(l);
|
||||
}
|
||||
|
||||
public synchronized DataSourceCollection createOrGetCollection(String name) {
|
||||
public DataSourceCollection createOrGetCollection(String name) {
|
||||
return getCollectionForName(name).orElseGet(() -> {
|
||||
var col = DataSourceCollection.createNew(name);
|
||||
addCollection(col);
|
||||
@@ -460,8 +463,8 @@ public abstract class DataStorage {
|
||||
|
||||
public abstract void load();
|
||||
|
||||
public synchronized void refresh() {
|
||||
storeEntries.forEach(entry -> {
|
||||
public void refresh() {
|
||||
getStoreEntries().forEach(entry -> {
|
||||
entry.simpleRefresh();
|
||||
});
|
||||
save();
|
||||
|
||||
Reference in New Issue
Block a user