@Override public void save(Field parent, Field field) { if (field == null) { field = new Field(); field.setName(getId()); if (parent != null) { field.setParent(parent); parent.getFields().add(field); } } final List<StructureHolder> unsaved = new ArrayList<StructureHolder>(); final List<Integer> saved = new ArrayList<Integer>(); saved.add(0); for (StructureHolder cur : oneToMany.getSelected()) { if (cur.getField() == null) unsaved.add(cur); else { cur.getStructure().save(field, cur.getField()); saved.add(cur.getField().getId()); } } for (StructureHolder cur : unsaved) { Field subfield = new Field(field.getName() + "Subfield", null); subfield.setParent(field); cur.getStructure().save(field, subfield); field.getFields().add(subfield); cur.setField(subfield); } final HashSet<Field> savedSet = new HashSet<Field>(); for (Field subfield : field.getFields()) if (saved.contains(subfield.getId())) savedSet.add(subfield); field.setFields(savedSet); }
@Override public void save(Field parent, Field field) { // FIXME: what should this actually do? if (field == null) { field = new Field(); field.setName(getId()); field.setParent(parent); } /* * Obviously this will be null... */ if (getData() != null) { PrimitiveField<String> newPrim = new StringPrimitiveField(getId(), field); newPrim.setRawValue(getData()); field.addPrimitiveField(newPrim); } }