summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2015-02-05 23:50:31 +0200
committerLeif Åstrand <leif@vaadin.com>2015-02-06 11:19:17 +0200
commit0e141e31bb30a0ab6726129f3c9fa892c92573e4 (patch)
tree672975bd0671b06d1498e5ce5f984e7d30179ef7 /server/src
parent0c82dad0ab225aeb9920b2e5c6f061da871bea66 (diff)
downloadvaadin-framework-0e141e31bb30a0ab6726129f3c9fa892c92573e4.tar.gz
vaadin-framework-0e141e31bb30a0ab6726129f3c9fa892c92573e4.zip
Highlights erroneous cells in Grid editor (#16575)
Change-Id: Ie1f9d738db7a03ddb01b968782ad5e4877af1d7e
Diffstat (limited to 'server/src')
-rw-r--r--server/src/com/vaadin/ui/Grid.java76
1 files changed, 61 insertions, 15 deletions
diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java
index 69e23ecd92..ef97f9b336 100644
--- a/server/src/com/vaadin/ui/Grid.java
+++ b/server/src/com/vaadin/ui/Grid.java
@@ -260,6 +260,8 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
private CommitException cause;
+ private Set<Column> errorColumns = new HashSet<Column>();
+
public CommitErrorEvent(Grid grid, CommitException cause) {
super(grid);
this.cause = cause;
@@ -288,6 +290,26 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
return cause.getCause() instanceof InvalidValueException;
}
+ /**
+ * Marks that an error indicator should be shown for the editor of a
+ * column.
+ *
+ * @param column
+ * the column to show an error for
+ */
+ public void addErrorColumn(Column column) {
+ errorColumns.add(column);
+ }
+
+ /**
+ * Gets all the columns that have been marked as erroneous.
+ *
+ * @return an umodifiable collection of erroneous columns
+ */
+ public Collection<Column> getErrorColumns() {
+ return Collections.unmodifiableCollection(errorColumns);
+ }
+
}
/**
@@ -302,19 +324,36 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
.getCause().getInvalidFields();
if (!invalidFields.isEmpty()) {
- // Validation error, show first failure as
- // "<Column header>: <message>"
+ Object firstErrorPropertyId = null;
+ Field<?> firstErrorField = null;
+
FieldGroup fieldGroup = event.getCause().getFieldGroup();
- Object propertyId = getFirstPropertyId(fieldGroup,
- invalidFields.keySet());
- Field<?> field = fieldGroup.getField(propertyId);
- String caption = getColumn(propertyId).getHeaderCaption();
- // TODO This should be shown in the editor component once
- // there is a place for that. Optionally, all errors should be
- // shown
- Notification.show(caption + ": "
- + invalidFields.get(field).getLocalizedMessage(),
- Type.ERROR_MESSAGE);
+ for (Column column : getColumns()) {
+ Object propertyId = column.getPropertyId();
+ Field<?> field = fieldGroup.getField(propertyId);
+ if (invalidFields.keySet().contains(field)) {
+ event.addErrorColumn(column);
+
+ if (firstErrorPropertyId == null) {
+ firstErrorPropertyId = propertyId;
+ firstErrorField = field;
+ }
+ }
+ }
+
+ /*
+ * Validation error, show first failure as
+ * "<Column header>: <message>"
+ */
+ String caption = getColumn(firstErrorPropertyId)
+ .getHeaderCaption();
+ String message = invalidFields.get(firstErrorField)
+ .getLocalizedMessage();
+ /*
+ * TODO This should be shown in the editor component once there
+ * is a place for that. Optionally, all errors should be shown
+ */
+ Notification.show(caption + ": " + message, Type.ERROR_MESSAGE);
} else {
com.vaadin.server.ErrorEvent.findErrorHandler(Grid.this).error(
@@ -3016,14 +3055,21 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
@Override
public void save(int rowIndex) {
+ List<String> errorColumnIds = null;
boolean success = false;
try {
saveEditor();
success = true;
} catch (CommitException e) {
try {
- getEditorErrorHandler().commitError(
- new CommitErrorEvent(Grid.this, e));
+ CommitErrorEvent event = new CommitErrorEvent(
+ Grid.this, e);
+ getEditorErrorHandler().commitError(event);
+
+ errorColumnIds = new ArrayList<String>();
+ for (Column column : event.getErrorColumns()) {
+ errorColumnIds.add(column.state.id);
+ }
} catch (Exception ee) {
// A badly written error handler can throw an exception,
// which would lock up the Grid
@@ -3032,7 +3078,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier,
} catch (Exception e) {
handleError(e);
}
- getEditorRpc().confirmSave(success);
+ getEditorRpc().confirmSave(success, errorColumnIds);
}
private void handleError(Exception e) {