Skip to content

Commit

Permalink
updated implementation of inspector text fields to better use renamab…
Browse files Browse the repository at this point in the history
…le interface
  • Loading branch information
crissNb committed Jan 14, 2024
1 parent f5af722 commit 2b2c55b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,7 +33,7 @@ public EdgeInspectorBuilder(
addInspectorElement(new InspectorSeparator());

// Priority
addInspectorElement(new InspectorTextField(viewModel.getPriority()));
addInspectorElement(new InspectorPriorityField(viewModel.getPriority()));

addInspectorElement(new InspectorSeparator());

Expand Down
Original file line number Diff line number Diff line change
@@ -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<TextField> {

public InspectorPriorityField(IntegerProperty targetProperty) {
textProperty().bindBidirectional(targetProperty, new NumberStringConverter());
}

@Override
public TextField getControl() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -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<TextField> {
public class InspectorTextField extends TextField implements InspectorElement<TextField> {

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
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/gecko/viewmodel/Renamable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ public interface Renamable {
String getName();

void setName(String name);

StringProperty getNameProperty(); // TODO: inspector needs this for name fields
}

0 comments on commit 2b2c55b

Please sign in to comment.