Skip to content

Instantly share code, notes, and snippets.

@yukihane
Created May 20, 2016 02:37
Show Gist options
  • Save yukihane/6d6f1e08238545dc4b2e26500e9ade4a to your computer and use it in GitHub Desktop.
Save yukihane/6d6f1e08238545dc4b2e26500e9ade4a to your computer and use it in GitHub Desktop.
diff --git a/src/gxt3-extension/src/main/java/com/sencha/gxt/data/shared/Store.java b/src/gxt3-extension/src/main/java/com/sencha/gxt/data/shared/Store.java
index 1768b85..ffb92a1 100644
--- a/src/gxt3-extension/src/main/java/com/sencha/gxt/data/shared/Store.java
+++ b/src/gxt3-extension/src/main/java/com/sencha/gxt/data/shared/Store.java
@@ -141,6 +141,8 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
private final M model;
private final Map<Object, Change<M, ?>> changes = new HashMap<Object, Store.Change<M, ?>>();
+ private Map<String, Boolean> validMap;
+
/**
* Creates a new record that wraps the given model.
*
@@ -171,9 +173,15 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
changes.put(c.getChangeTag(), c);
modifiedRecords.add(this);
}
+ if (validMap != null) {
+ validMap.remove(property.getPath());
+ }
fireEvent(new StoreRecordChangeEvent<M>(this, property));
} else {
property.setValue(model, value);
+ if (validMap != null) {
+ validMap.remove(property.getPath());
+ }
fireEvent(new StoreUpdateEvent<M>(Collections.singletonList(this.model)));
}
}
@@ -188,6 +196,7 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
c.modify(model);
}
changes.clear();
+ validMap = null;
if (fireEvent) {
fireEvent(new StoreUpdateEvent<M>(Collections.singletonList(this.model)));
}
@@ -258,6 +267,41 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
}
/**
+ * Sets whether the record is valid (defaults to true). The valid state of a
+ * record is not modified or changed by the record itself. Both EditorGrid
+ * and FieldBinding will set the valid state of the record to match the
+ * field's valid state after an edit completes. (以上, gxt2における記述)
+ *
+ * @param property
+ * the property name
+ * @param valid
+ * true if valid, false otherwise
+ */
+ public void setValid(String property, boolean valid) {
+ if (validMap == null) {
+ validMap = new FastMap<Boolean>();
+ }
+ validMap.put(property, valid);
+ }
+
+ /**
+ * Returns true if the record is valid. (以上, gxt2における記述)
+ *
+ * @param property
+ * the property name
+ * @return true if the record is valid
+ */
+ public boolean isValid(String property) {
+ if (validMap == null) {
+ return true;
+ }
+ if (validMap.containsKey(property)) {
+ return validMap.get(property);
+ }
+ return true;
+ }
+
+ /**
* Rejects a single change made to the Record since its creation, or since
* the last commit operation.
*
@@ -266,6 +310,9 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
* @param property the property of the model to revert
*/
public void revert(ValueProvider<? super M,?> property) {
+ if (validMap != null) {
+ validMap.remove(property.getPath());
+ }
if (changes.remove(property.getPath()) != null) {
fireEvent(new StoreUpdateEvent<M>(Collections.singletonList(this.model)));
}
@@ -277,6 +324,7 @@ public abstract class Store<M> implements HasStoreHandlers<M> {
*/
public void revert() {
changes.clear();
+ validMap = null;
fireEvent(new StoreUpdateEvent<M>(Collections.singletonList(this.model)));
}
diff --git a/src/gxt3-extension/src/main/java/com/sencha/gxt/theme/base/client/grid/Grid.css b/src/gxt3-extension/src/main/java/com/sencha/gxt/theme/base/client/grid/Grid.css
index 3753c2e..e7cfbec 100644
--- a/src/gxt3-extension/src/main/java/com/sencha/gxt/theme/base/client/grid/Grid.css
+++ b/src/gxt3-extension/src/main/java/com/sencha/gxt/theme/base/client/grid/Grid.css
@@ -96,9 +96,9 @@
background-image: dirty;
}
-.cellDirty {
- background: transparent no-repeat 0 0;
- background-image: dirty;
+.cellInvalid {
+ background: repeat-x bottom;
+ background-image: invalidLine;
}
.row .grid-cellSelected {
diff --git a/src/gxt3-extension/src/main/java/com/sencha/gxt/widget/core/client/grid/GridView.java b/src/gxt3-extension/src/main/java/com/sencha/gxt/widget/core/client/grid/GridView.java
index 8f8cde3..bccff7a 100644
--- a/src/gxt3-extension/src/main/java/com/sencha/gxt/widget/core/client/grid/GridView.java
+++ b/src/gxt3-extension/src/main/java/com/sencha/gxt/widget/core/client/grid/GridView.java
@@ -209,6 +209,8 @@ public class GridView<M> {
String cellDirty();
+ String cellInvalid();
+
String cellInner();
String noPadding();
@@ -1389,6 +1391,7 @@ public class GridView<M> {
final String cellFirstClass = "x-grid-cell-first";
final String cellLastClass = "x-grid-cell-last";
final String cellDirty = styles.cellDirty();
+ final String cellInvalid = styles.cellInvalid();
final String rowWrap = styles.rowWrap() + " " + states.rowWrap();
final String rowBody = styles.rowBody() + " " + states.rowBody();
@@ -1463,6 +1466,10 @@ public class GridView<M> {
cellClasses += " " + cellDirty;
}
+ if (r != null && !r.isValid(columnConfig.getPath())) {
+ cellClasses += " " + cellInvalid;
+ }
+
if (viewConfig != null) {
cellClasses += " " + viewConfig.getColStyle(model, cm.getValueProvider(i), rowIndex, i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment