@Override
  public boolean hasChanged(Field field) {
    final Map<Integer, Field> savedFields = new HashMap<Integer, Field>();
    if (field != null)
      for (Field subfield : field.getFields()) savedFields.put(subfield.getId(), subfield);

    for (StructureHolder holder : oneToMany.getSelected()) {
      // Field has never been saved, if there are changes, let's save.
      if (holder.getField() == null || holder.getField().getId() == 0) {
        if (holder.hasChanged()) {
          Debug.println("NEW: {0} says it has changed", holder.getStructure().getClass().getName());
          return true;
        } else return false;
      } else {
        // We are working with previously saved data that could have changed.
        Field dataField = savedFields.remove(holder.getField().getId());
        if (dataField == null) { // How??
          Debug.println("OneToMany hasChanged badness, save to clean up.");
          return true;
        }

        if (holder.getStructure().hasChanged(dataField)) {
          Debug.println("OLD: {0} says it has changed", holder.getStructure().getClass().getName());
          return true;
        }
      }
    }

    return !savedFields.isEmpty();
  }
  @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);
  }
  private void updateRecords() {
    records.clear();

    if (displayFields.isEmpty()) {
      records.setWidget(new HTML(""));
      return;
    }

    List<StructureHolder> holders = oneToMany.getSelected();
    if (holders.isEmpty()) {
      records.setWidget(new HTML(""));
      return;
    }

    List<String> descs = holders.get(0).getStructure().extractDescriptions();

    Grid grid = new Grid(holders.size() + 1, displayFields.size());
    grid.setCellSpacing(0);
    grid.setCellPadding(8);
    grid.addStyleName("page_assessment_classScheme_grid");

    int row = 0;
    int column = 0;
    for (Integer value : displayFields) {
      try {
        grid.setHTML(
            row,
            column,
            "<span class=\"page_assessment_classScheme_grid_th\">" + descs.get(value) + "</span>");
      } catch (IndexOutOfBoundsException e) {
        grid.setHTML(row, column, "<span class=\"page_assessment_classScheme_grid_th\">-</span>");
      } finally {
        column++;
      }
    }

    row++;

    for (StructureHolder holder : holders) {
      final ArrayList<String> raw = new ArrayList<String>(), pretty = new ArrayList<String>();

      final Structure<Object> structure = holder.getStructure();

      final Map<String, String> map = new LinkedHashMap<String, String>();

      for (Object obj : structure.getClassificationInfo()) {
        ClassificationInfo info = (ClassificationInfo) obj;
        map.put(info.getDescription(), info.getData());
        raw.add(info.getData());
      }

      try {
        structure.getDisplayableData(raw, pretty, 0);
      } catch (Exception e) {
        continue;
      }

      column = 0;
      for (Integer value : displayFields) {
        try {
          grid.setHTML(
              row,
              column,
              "<span class=\"page_assessment_classScheme_content\">"
                  + pretty.get(value)
                  + "</span>");
        } catch (IndexOutOfBoundsException e) {
          grid.setHTML(row, column, "<span class=\"page_assessment_classScheme_content\">-</span>");
        } finally {
          column++;
        }
      }

      row++;
    }

    for (int i = 0; i < grid.getColumnCount(); i++) grid.getColumnFormatter().setWidth(i, "150px");

    records.setWidget(grid);
  }