1.1 --- a/json/src/main/java/org/apidesign/html/json/spi/Proto.java Sun Jan 05 22:48:45 2014 +0100
1.2 +++ b/json/src/main/java/org/apidesign/html/json/spi/Proto.java Sun Jan 05 23:09:49 2014 +0100
1.3 @@ -45,6 +45,7 @@
1.4 import java.util.Collection;
1.5 import java.util.List;
1.6 import net.java.html.BrwsrCtx;
1.7 +import net.java.html.json.ComputedProperty;
1.8 import net.java.html.json.Model;
1.9 import org.netbeans.html.json.impl.Bindings;
1.10 import org.netbeans.html.json.impl.JSON;
1.11 @@ -281,14 +282,40 @@
1.12 return JSON.toNumber(context, data, propName);
1.13 }
1.14
1.15 - public <T> T toModel(Class<T> type, Object data, String propName) {
1.16 - return JSON.toModel(context, type, data, propName);
1.17 + /** Converts raw JSON data into a {@link Model} class representation.
1.18 + *
1.19 + * @param <T> type of the model to create
1.20 + * @param type class of the model to create
1.21 + * @param data raw JSON data (depends on associated {@link Technology})
1.22 + * @return new instances of the model class filled with values from the
1.23 + * <code>data</code> object
1.24 + */
1.25 + public <T> T toModel(Class<T> type, Object data) {
1.26 + return JSON.toModel(context, type, data, null);
1.27 }
1.28
1.29 + /** Creates new JSON like observable list.
1.30 + *
1.31 + * @param <T> the type of the list elements
1.32 + * @param propName name of a property this list is associated with
1.33 + * @param onChange index of the property to use when the list is modified
1.34 + * during callback to {@link Type#onChange(java.lang.Object, int)}
1.35 + * @param dependingProps the array of {@link ComputedProperty derived properties}
1.36 + * that depend on the value of the list
1.37 + * @return new, empty list associated with this proto-object and its model
1.38 + */
1.39 public <T> List<T> createList(String propName, int onChange, String... dependingProps) {
1.40 return new JSONList<T>(this, propName, onChange, dependingProps);
1.41 }
1.42 -
1.43 +
1.44 + /** Copies content of one collection to another, re-assigning all its
1.45 + * elements from their current context to the new <code>ctx</code>.
1.46 + *
1.47 + * @param <T> type of the collections
1.48 + * @param to the target collection to be filled with cloned values
1.49 + * @param ctx context for the new collection
1.50 + * @param from original collection with its data
1.51 + */
1.52 public <T> void cloneList(Collection<T> to, BrwsrCtx ctx, Collection<T> from) {
1.53 Boolean isModel = null;
1.54 for (T t : from) {
2.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Sun Jan 05 22:48:45 2014 +0100
2.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Sun Jan 05 23:09:49 2014 +0100
2.3 @@ -1234,6 +1234,7 @@
2.4 first = false;
2.5 String toCall = null;
2.6 String toFinish = null;
2.7 + boolean addNull = true;
2.8 if (ve.asType() == stringType) {
2.9 if (ve.getSimpleName().contentEquals("id")) {
2.10 params.append('"').append(id).append('"');
2.11 @@ -1251,13 +1252,16 @@
2.12 }
2.13 if (dataName != null && ve.getSimpleName().contentEquals(dataName) && isModel(ve.asType())) {
2.14 toCall = "proto.toModel(" + ve.asType() + ".class, ";
2.15 + addNull = false;
2.16 }
2.17
2.18 if (toCall != null) {
2.19 params.append(toCall);
2.20 if (dataName != null && ve.getSimpleName().contentEquals(dataName)) {
2.21 params.append(dataName);
2.22 - params.append(", null");
2.23 + if (addNull) {
2.24 + params.append(", null");
2.25 + }
2.26 } else {
2.27 if (evName == null) {
2.28 final StringBuilder sb = new StringBuilder();