From 5fb33a0c9f0d2414a773b432c0b9d9c9364c1b21 Mon Sep 17 00:00:00 2001 From: Adam Vanko Date: Mon, 13 Dec 2021 14:29:25 +0100 Subject: [PATCH] Fix - adding/removing function cleared choicebox's selection. --- .../arc/FunctionalMultiplicitySubEditor.java | 8 ++++---- .../propertieseditor/common/MyChoiceBox.java | 19 +++++++++++++++++++ .../TransitionPropertiesEditor.java | 7 ++++--- ...ctionalProbabilityPropertiesSubEditor.java | 8 ++++---- ...pendentProbabilityPropertiesSubEditor.java | 8 ++++---- ...tionalTransitionDistributionSubEditor.java | 8 ++++---- ...endentTransitionDistributionSubEditor.java | 8 ++++---- 7 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/common/MyChoiceBox.java diff --git a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/arc/FunctionalMultiplicitySubEditor.java b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/arc/FunctionalMultiplicitySubEditor.java index 80550c39..94ebd0a4 100644 --- a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/arc/FunctionalMultiplicitySubEditor.java +++ b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/arc/FunctionalMultiplicitySubEditor.java @@ -5,9 +5,9 @@ import cz.muni.fi.spnp.gui.components.diagram.graph.elements.arc.viewmodels.ArcViewModel; import cz.muni.fi.spnp.gui.components.menu.view.functions.FunctionViewModel; import cz.muni.fi.spnp.gui.components.propertieseditor.common.FunctionViewModelStringConverter; +import cz.muni.fi.spnp.gui.components.propertieseditor.common.MyChoiceBox; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; -import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import java.util.stream.Collectors; @@ -18,7 +18,7 @@ public class FunctionalMultiplicitySubEditor extends ArcMultiplicitySubEditor { private Label multiplicityFunctionLabel; - private ChoiceBox multiplicityFunctionChoiceBox; + private MyChoiceBox multiplicityFunctionChoiceBox; private final ListChangeListener onFunctionsChangedListener; @@ -30,7 +30,7 @@ public FunctionalMultiplicitySubEditor() { private void createView() { multiplicityFunctionLabel = new Label("Multiplicity function:"); - multiplicityFunctionChoiceBox = new ChoiceBox<>(); + multiplicityFunctionChoiceBox = new MyChoiceBox<>(); addRow(multiplicityFunctionLabel, multiplicityFunctionChoiceBox); } @@ -42,7 +42,7 @@ private void onFunctionsChangedListener(ListChangeListener.Change type of the items + */ +public class MyChoiceBox extends ChoiceBox { + + public void setItemsWithSelected(ObservableList newItems) { + var selectedItem = getSelectionModel().getSelectedItem(); + super.setItems(newItems); + getSelectionModel().select(selectedItem); + } + +} diff --git a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/TransitionPropertiesEditor.java b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/TransitionPropertiesEditor.java index a723dc29..dee4e90e 100644 --- a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/TransitionPropertiesEditor.java +++ b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/TransitionPropertiesEditor.java @@ -9,6 +9,7 @@ import cz.muni.fi.spnp.gui.components.propertieseditor.ElementPropertiesEditor; import cz.muni.fi.spnp.gui.components.propertieseditor.common.FunctionViewModelStringConverter; import cz.muni.fi.spnp.gui.components.propertieseditor.common.IntegerTextField; +import cz.muni.fi.spnp.gui.components.propertieseditor.common.MyChoiceBox; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.scene.control.ChoiceBox; @@ -25,7 +26,7 @@ public abstract class TransitionPropertiesEditor extends ElementPropertiesEditor private final Label priorityLabel; private final IntegerTextField priorityTextField; private final Label guardFunctionLabel; - private final ChoiceBox guardFunctionChoiceBox; + private final MyChoiceBox guardFunctionChoiceBox; private final ListChangeListener onFunctionsChangedListener; private final Label orientationLabel; private final ChoiceBox orientationChoiceBox; @@ -36,7 +37,7 @@ public TransitionPropertiesEditor() { addRow(priorityLabel, priorityTextField.getTextField()); guardFunctionLabel = new Label("Guard function:"); - guardFunctionChoiceBox = new ChoiceBox<>(); + guardFunctionChoiceBox = new MyChoiceBox<>(); addRow(guardFunctionLabel, guardFunctionChoiceBox); orientationLabel = new Label("Orientation:"); @@ -58,7 +59,7 @@ private void onFunctionsChangedListener(ListChangeListener.Change onFunctionsChangedListener; private Label functionLabel; - private ChoiceBox functionChoiceBox; + private MyChoiceBox functionChoiceBox; public FunctionalProbabilityPropertiesSubEditor() { createView(); @@ -30,7 +30,7 @@ public FunctionalProbabilityPropertiesSubEditor() { private void createView() { functionLabel = new Label("Function:"); - functionChoiceBox = new ChoiceBox<>(); + functionChoiceBox = new MyChoiceBox<>(); addRow(functionLabel, functionChoiceBox); } @@ -41,7 +41,7 @@ private void onFunctionsChangedListener(ListChangeListener.Change dependentPlaceChoiceBox; + private MyChoiceBox dependentPlaceChoiceBox; public PlaceDependentProbabilityPropertiesSubEditor() { createView(); @@ -35,14 +35,14 @@ private void createView() { addRow(valueLabel, valueTextField); dependentPlaceLabel = new Label("Dependent place:"); - dependentPlaceChoiceBox = new ChoiceBox<>(); + dependentPlaceChoiceBox = new MyChoiceBox<>(); addRow(dependentPlaceLabel, dependentPlaceChoiceBox); } private void onPlacesChangedListener(ListChangeListener.Change placesChange) { var placesCopy = FXCollections.observableArrayList(diagramViewModel.getPlaces()); placesCopy.add(0, null); - dependentPlaceChoiceBox.setItems(placesCopy); + dependentPlaceChoiceBox.setItemsWithSelected(placesCopy); } @Override diff --git a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/timed/FunctionalTransitionDistributionSubEditor.java b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/timed/FunctionalTransitionDistributionSubEditor.java index e4b8db14..67bff628 100644 --- a/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/timed/FunctionalTransitionDistributionSubEditor.java +++ b/src/main/java/cz/muni/fi/spnp/gui/components/propertieseditor/transition/timed/FunctionalTransitionDistributionSubEditor.java @@ -5,10 +5,10 @@ import cz.muni.fi.spnp.gui.components.diagram.graph.elements.transition.viewmodels.timed.distributions.TransitionDistributionViewModel; import cz.muni.fi.spnp.gui.components.menu.view.functions.FunctionViewModel; import cz.muni.fi.spnp.gui.components.propertieseditor.common.FunctionViewModelStringConverter; +import cz.muni.fi.spnp.gui.components.propertieseditor.common.MyChoiceBox; import cz.muni.fi.spnp.gui.components.propertieseditor.transition.PropertiesEditorRow; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; -import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import java.util.ArrayList; @@ -22,7 +22,7 @@ public class FunctionalTransitionDistributionSubEditor extends TransitionDistrib private final ListChangeListener onFunctionsChangedListener; private List