/** Refresh fields with values from tempModel or editedModel. */ private void refreshDisplay() { Session s = Session.current; Model tmp = s.tempModel; int structIndex = -1; for (int j = 0; j < this.table.getChildCount(); j++) { structIndex++; View v = this.table.getChildAt(j); if (!FormViewFactory.isFieldView(v)) { // Check if it is a x2many label Model field = this.view.getStructure().get(structIndex); if (field.hasAttribute("type")) { String type = field.getString("type"); if (type.equals("many2many") || type.equals("one2many")) { // This is the label of a x2many field // It is not present in structure and next // will be the true widget. // Get back in structure for next pass // to point on the x2many field (and not next one) structIndex--; } } continue; } Model field = this.view.getStructure().get(structIndex); FormViewFactory.setValue(v, field, this.view, tmp, s.editedModel, s.prefs, this); } }
/** Update temp model to current values */ private void updateTempModel() { Model tmp; Model origin; tmp = Session.current.tempModel; origin = Session.current.editedModel; int structIndex = -1; for (int j = 0; j < this.table.getChildCount(); j++) { structIndex++; View v = this.table.getChildAt(j); if (!FormViewFactory.isFieldView(v)) { // Check if it is a x2many label Model field = this.view.getStructure().get(structIndex); if (field.hasAttribute("type")) { String type = field.getString("type"); if (type.equals("many2many") || type.equals("one2many")) { // This is the label of a x2many field // It is not present in structure and next // will be the true widget. // Get back in structure for next pass // to point on the x2many field (and not next one) structIndex--; } } // Ignore continue; } Model field = this.view.getStructure().get(structIndex); Object value = FormViewFactory.getValue(v, field, Session.current.prefs); if (value != FormViewFactory.NO_VALUE) { tmp.set(field.getString("name"), value); } else { // If NO_VALUE (not null) the value is ignored // but still set null to create the field if necessary String fieldName = field.getString("name"); if (origin != null) { // Origin always has a value, it will be merged } else { // Origin doesn't have a value, set explicit null if (!tmp.hasAttribute(fieldName)) { tmp.set(fieldName, null); } } } } }