Skip to content

Commit feaae3e

Browse files
authored
Merge pull request #205 from Esri/john0005/UpdateAddDeleteSample
Updating edit samples
2 parents 270bf04 + 89e8b07 commit feaae3e

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

src/main/java/com/esri/samples/editing/add_features/AddFeaturesSample.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ private void addFeature(Point mapPoint, ServiceFeatureTable featureTable) {
130130

131131
// check if feature can be added to feature table
132132
if (featureTable.canAdd()) {
133-
// add the new feature to the feature table
134-
ListenableFuture<Void> addResult = featureTable.addFeatureAsync(feature);
135-
addResult.addDoneListener(() -> applyEdits(featureTable));
133+
// add the new feature to the feature table and to server
134+
featureTable.addFeatureAsync(feature).addDoneListener(() -> applyEdits(featureTable));
136135
} else {
137136
displayMessage(null, "Cannot add a feature to this feature table");
138137
}
@@ -151,8 +150,12 @@ private void applyEdits(ServiceFeatureTable featureTable) {
151150
try {
152151
List<FeatureEditResult> edits = editResult.get();
153152
// check if the server edit was successful
154-
if (edits != null && edits.size() > 0 && edits.get(0).hasCompletedWithErrors()) {
155-
throw edits.get(0).getError();
153+
if (edits != null && edits.size() > 0) {
154+
if (!edits.get(0).hasCompletedWithErrors()) {
155+
displayMessage(null, "Feature successfully added");
156+
} else {
157+
throw edits.get(0).getError();
158+
}
156159
}
157160
} catch (InterruptedException | ExecutionException e) {
158161
displayMessage("Exception applying edits on server", e.getCause().getMessage());

src/main/java/com/esri/samples/editing/delete_features/DeleteFeaturesSample.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,8 @@ public void start(Stage stage) throws Exception {
150150
*/
151151
private void deleteFeatures(FeatureQueryResult features, ServiceFeatureTable featureTable) {
152152

153-
// delete feature from the feature table
154-
featureTable.deleteFeaturesAsync(features).addDoneListener(() -> {
155-
// apply changes to the server
156-
ListenableFuture<List<FeatureEditResult>> editResult = featureTable.applyEditsAsync();
157-
editResult.addDoneListener(() -> applyEdits(featureTable));
158-
});
153+
// delete feature from the feature table and apply edit to server
154+
featureTable.deleteFeaturesAsync(features).addDoneListener(() -> applyEdits(featureTable));
159155
}
160156

161157
/**
@@ -171,10 +167,12 @@ private void applyEdits(ServiceFeatureTable featureTable) {
171167
try {
172168
List<FeatureEditResult> edits = editResult.get();
173169
// check if the server edit was successful
174-
if (edits != null && edits.size() > 0 && !edits.get(0).hasCompletedWithErrors()) {
175-
displayMessage(null, "Feature successfully deleted");
176-
} else if (edits != null && edits.size() > 0) {
177-
throw edits.get(0).getError();
170+
if (edits != null && edits.size() > 0) {
171+
if (!edits.get(0).hasCompletedWithErrors()) {
172+
displayMessage(null, "Feature successfully deleted");
173+
} else {
174+
throw edits.get(0).getError();
175+
}
178176
}
179177
} catch (InterruptedException | ExecutionException e) {
180178
displayMessage("Exception applying edits on server", e.getCause().getMessage());

src/main/java/com/esri/samples/editing/edit_feature_attachments/EditFeatureAttachmentsSample.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,12 @@ private void applyEdits(ServiceFeatureTable featureTable) {
266266
try {
267267
List<FeatureEditResult> edits = editResult.get();
268268
// check if the server edit was successful
269-
if (edits != null && edits.size() > 0 && edits.get(0).hasCompletedWithErrors()) {
270-
throw edits.get(0).getError();
269+
if (edits != null && edits.size() > 0) {
270+
if (!edits.get(0).hasCompletedWithErrors()) {
271+
displayMessage(null, "Edited feature successfully");
272+
} else {
273+
throw edits.get(0).getError();
274+
}
271275
}
272276
// update the displayed list of attachments
273277
fetchAttachments(selected);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ private void applyEdits(ServiceFeatureTable featureTable) {
215215
try {
216216
List<FeatureEditResult> edits = editResult.get();
217217
// check if the server edit was successful
218-
if (edits != null && edits.size() > 0 && edits.get(0).hasCompletedWithErrors()) {
219-
throw edits.get(0).getError();
218+
if (edits != null && edits.size() > 0) {
219+
if (!edits.get(0).hasCompletedWithErrors()) {
220+
displayMessage(null, "Attributes updated.");
221+
} else {
222+
throw edits.get(0).getError();
223+
}
220224
}
221225
} catch (InterruptedException | ExecutionException e) {
222226
displayMessage("Error applying edits on server", e.getCause().getMessage());

src/main/java/com/esri/samples/editing/update_geometries/UpdateGeometriesSample.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void start(Stage stage) throws Exception {
104104
} else {
105105

106106
// didn't click on a feature
107-
ListenableFuture<FeatureQueryResult> selectedQuery = featureLayer.getSelectedFeaturesAsync();
107+
ListenableFuture<FeatureQueryResult> selectedQuery = featureLayer.getSelectedFeaturesAsync();
108108
selectedQuery.addDoneListener(() -> {
109109
try {
110110
// check if a feature is currently selected
@@ -161,8 +161,12 @@ private static void applyEdits() {
161161
try {
162162
List<FeatureEditResult> edits = editResult.get();
163163
// check if the server edit was successful
164-
if (edits != null && edits.size() > 0 && edits.get(0).hasCompletedWithErrors()) {
165-
throw edits.get(0).getError();
164+
if (edits != null && edits.size() > 0) {
165+
if (!edits.get(0).hasCompletedWithErrors()) {
166+
displayMessage(null, "Geometry updated");
167+
} else {
168+
throw edits.get(0).getError();
169+
}
166170
}
167171
} catch (InterruptedException | ExecutionException e) {
168172
displayMessage("Error applying edits on server", e.getCause().getMessage());

0 commit comments

Comments
 (0)