Skip to content

Commit 73489c7

Browse files
committed
use selected item property to determine if attribute should be updated
1 parent befee96 commit 73489c7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/main/java/com/esri/samples/editing/update_attributes/UpdateAttributesSample.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ public void start(Stage stage) throws Exception {
9696
// create combo box
9797
comboBox = new ComboBox<>(damageList);
9898
comboBox.setMaxWidth(Double.MAX_VALUE);
99-
comboBox.setTooltip(new Tooltip("Type of Damage"));
10099
comboBox.setDisable(true);
101100

102101
// handle type damage selection
103-
comboBox.showingProperty().addListener((obs, wasShowing, isShowing) -> {
104-
try {
105-
updateAttributes(selected);
106-
} catch (Exception e) {
107-
displayMessage("Cannot update attributes", e.getCause().getMessage());
102+
comboBox.getSelectionModel().selectedItemProperty().addListener((o, p, n) -> {
103+
if (!selected.getAttributes().get("typdamage").equals(n)) {
104+
try {
105+
updateAttributes(selected);
106+
} catch (Exception e) {
107+
displayMessage("Cannot update attributes", e.getCause().getMessage());
108+
}
108109
}
109110
});
110111

@@ -151,7 +152,7 @@ public void start(Stage stage) throws Exception {
151152
selected.loadAsync();
152153
selected.addDoneLoadingListener(() -> {
153154
if (selected.getLoadStatus() == LoadStatus.LOADED) {
154-
selectAttribute(selected);
155+
comboBox.getSelectionModel().select((String) selected.getAttributes().get("typdamage"));
155156
} else {
156157
Alert alert = new Alert(Alert.AlertType.ERROR, "Element Failed to Load!");
157158
alert.show();
@@ -180,11 +181,6 @@ public void start(Stage stage) throws Exception {
180181
}
181182
}
182183

183-
private void selectAttribute(ArcGISFeature feature) {
184-
185-
Platform.runLater(() -> comboBox.getSelectionModel().select((String) feature.getAttributes().get("typdamage")));
186-
}
187-
188184
/**
189185
* Applies changes to the feature, Service Feature Table, and server.
190186
*/

0 commit comments

Comments
 (0)