diff --git a/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java index aaf8af99..10789566 100644 --- a/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java @@ -28,7 +28,7 @@ protected AbstractInspectorBuilder(ActionManager actionManager, T viewModel) { // Name field if applicable try { - addInspectorElement(new InspectorTextField(((Renamable) viewModel).getNameProperty())); + addInspectorElement(new InspectorTextField((Renamable) viewModel)); addInspectorElement(new InspectorSeparator()); } catch (ClassCastException e) { // Do nothing diff --git a/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java index a9cac178..837c61cf 100644 --- a/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java @@ -5,6 +5,7 @@ import org.gecko.view.inspector.element.combobox.InspectorContractComboBox; import org.gecko.view.inspector.element.combobox.InspectorKindComboBox; import org.gecko.view.inspector.element.container.InspectorEdgeStateLabel; +import org.gecko.view.inspector.element.textfield.InspectorPriorityField; import org.gecko.view.inspector.element.textfield.InspectorTextField; import org.gecko.view.inspector.element.label.InspectorLabel; import org.gecko.viewmodel.EdgeViewModel; @@ -32,7 +33,7 @@ public EdgeInspectorBuilder( addInspectorElement(new InspectorSeparator()); // Priority - addInspectorElement(new InspectorTextField(viewModel.getPriority())); + addInspectorElement(new InspectorPriorityField(viewModel.getPriority())); addInspectorElement(new InspectorSeparator()); diff --git a/src/main/java/org/gecko/view/inspector/element/textfield/InspectorPriorityField.java b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorPriorityField.java new file mode 100644 index 00000000..daa7703e --- /dev/null +++ b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorPriorityField.java @@ -0,0 +1,18 @@ +package org.gecko.view.inspector.element.textfield; + +import javafx.beans.property.IntegerProperty; +import javafx.scene.control.TextField; +import javafx.util.converter.NumberStringConverter; +import org.gecko.view.inspector.element.InspectorElement; + +public class InspectorPriorityField extends TextField implements InspectorElement { + + public InspectorPriorityField(IntegerProperty targetProperty) { + textProperty().bindBidirectional(targetProperty, new NumberStringConverter()); + } + + @Override + public TextField getControl() { + return this; + } +} diff --git a/src/main/java/org/gecko/view/inspector/element/textfield/InspectorTextField.java b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorTextField.java index a5853608..262b8d55 100644 --- a/src/main/java/org/gecko/view/inspector/element/textfield/InspectorTextField.java +++ b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorTextField.java @@ -1,20 +1,19 @@ package org.gecko.view.inspector.element.textfield; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.StringProperty; import javafx.scene.control.TextField; -import javafx.util.converter.NumberStringConverter; import org.gecko.view.inspector.element.InspectorElement; +import org.gecko.viewmodel.Renamable; -public class InspectorTextField extends TextField - implements InspectorElement { +public class InspectorTextField extends TextField implements InspectorElement { - public InspectorTextField(IntegerProperty targetIntegerProperty) { - textProperty().bindBidirectional(targetIntegerProperty, new NumberStringConverter()); - } + public InspectorTextField(Renamable renamable) { + setText(renamable.getName()); - public InspectorTextField(StringProperty targetStringProperty) { - textProperty().bindBidirectional(targetStringProperty); + textProperty() + .addListener( + (observable, oldValue, newValue) -> { + renamable.setName(newValue); + }); } @Override diff --git a/src/main/java/org/gecko/viewmodel/Renamable.java b/src/main/java/org/gecko/viewmodel/Renamable.java index 13d3c63c..3fd4ddc2 100644 --- a/src/main/java/org/gecko/viewmodel/Renamable.java +++ b/src/main/java/org/gecko/viewmodel/Renamable.java @@ -6,6 +6,4 @@ public interface Renamable { String getName(); void setName(String name); - - StringProperty getNameProperty(); // TODO: inspector needs this for name fields }