mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-18 10:13:38 +00:00
Fixes
This commit is contained in:
parent
bdd43e978e
commit
1a5e550145
1 changed files with 62 additions and 7 deletions
|
@ -8,13 +8,17 @@ import io.xpipe.app.comp.base.*;
|
|||
import io.xpipe.app.comp.store.StoreChoicePopover;
|
||||
import io.xpipe.app.storage.DataStoreEntryRef;
|
||||
import io.xpipe.app.util.DerivedObservableList;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -72,6 +76,14 @@ public class HostAddressChoiceComp extends Comp<CompStructure<HBox>> {
|
|||
return new SimpleCompStructure<>(layout.createStructure().get());
|
||||
}
|
||||
|
||||
private String getRefName() {
|
||||
if (ref.get() == null) {
|
||||
return "?";
|
||||
}
|
||||
|
||||
return ref.get().get().getName() + " (Stored)";
|
||||
}
|
||||
|
||||
private Comp<?> createComboBox() {
|
||||
var items = new DerivedObservableList<>(allAddresses, true).mapped(o -> o.toString()).getList();
|
||||
|
||||
|
@ -81,20 +93,27 @@ public class HostAddressChoiceComp extends Comp<CompStructure<HBox>> {
|
|||
});
|
||||
prop.addListener((observable, oldValue, newValue) -> {
|
||||
currentAddress.setValue(newValue != null ? HostAddress.of(newValue) : null);
|
||||
if (ref.get() != null && !ref.get().get().getName().equals(newValue)) {
|
||||
if (ref.get() != null && !getRefName().equals(newValue)) {
|
||||
ref.set(null);
|
||||
}
|
||||
});
|
||||
ref.subscribe(r -> {
|
||||
if (r != null) {
|
||||
items.setAll(r.get().getName(), null);
|
||||
prop.setValue(r.get().getName());
|
||||
items.setAll(getRefName(), null);
|
||||
prop.setValue(getRefName());
|
||||
} else {
|
||||
if (items.size() == 2) {
|
||||
Platform.runLater(() -> {
|
||||
prop.setValue(null);
|
||||
items.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var combo = new ComboTextFieldComp(prop, items, null);
|
||||
combo.apply(struc -> {
|
||||
struc.get().setButtonCell(new ListCell<>() {
|
||||
var combo = new ComboTextFieldComp(prop, items, param -> {
|
||||
return new ListCell<String>() {
|
||||
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
|
@ -105,22 +124,58 @@ public class HostAddressChoiceComp extends Comp<CompStructure<HBox>> {
|
|||
if (item == null) {
|
||||
setText("<none>");
|
||||
setGraphic(null);
|
||||
setDisable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var isRef = ref.getValue() != null && ref.getValue().get().getName().equals(item);
|
||||
var isRef = ref.getValue() != null && getRefName().equals(item);
|
||||
if (isRef) {
|
||||
setGraphic(PrettyImageHelper.ofFixedSize(ref.getValue().get().getEffectiveIconFile(), 16, 16).createRegion());
|
||||
setText(item);
|
||||
setDisable(true);
|
||||
} else {
|
||||
setGraphic(null);
|
||||
setText(item);
|
||||
setDisable(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
combo.apply(struc -> {
|
||||
struc.get().setButtonCell(new ListCell<>() {
|
||||
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
setText("<none>");
|
||||
setGraphic(null);
|
||||
setDisable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var isRef = ref.getValue() != null && getRefName().equals(item);
|
||||
if (isRef) {
|
||||
setGraphic(PrettyImageHelper.ofFixedSize(ref.getValue().get().getEffectiveIconFile(), 16, 16).createRegion());
|
||||
setText(item);
|
||||
setDisable(true);
|
||||
} else {
|
||||
setGraphic(null);
|
||||
setText(item);
|
||||
setDisable(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ref.subscribe(r -> {
|
||||
struc.get().setEditable(r == null);
|
||||
if (r == null) {
|
||||
struc.get().requestFocus();
|
||||
}
|
||||
});
|
||||
// struc.get().disableProperty().bind(ref.isNotNull());
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue