private void applyChanges() {
    boolean changedFieldSet = false; // Watch if we need to rebuild entry editors

    // First remove the mappings for fields that have been deleted.
    // If these were re-added, they will be added below, so it doesn't
    // cause any harm to remove them here.
    for (String fieldName : removedFields) {
      metaData.remove(Globals.SELECTOR_META_PREFIX + fieldName);
      changedFieldSet = true;
    }

    // Cycle through all fields that we have created listmodels for:
    for (String fieldName : wordListModels.keySet()) {
      // For each field name, store the values:
      if ((fieldName == null) || FIELD_FIRST_LINE.equals(fieldName)) {
        continue;
      }
      DefaultListModel<String> lm = wordListModels.get(fieldName);
      int start = 0;
      // Avoid storing the <new word> marker if it is there:
      if (!lm.isEmpty()) {
        while ((start < lm.size()) && lm.get(start).equals(WORD_FIRSTLINE_TEXT)) {
          start++;
        }
      }
      Vector<String> data = metaData.getData(Globals.SELECTOR_META_PREFIX + fieldName);
      boolean bNewField = false;
      if (data == null) {
        bNewField = true;
        data = new Vector<>();
        changedFieldSet = true;

      } else {
        data.clear();
      }
      for (int wrd = start; wrd < lm.size(); wrd++) {
        String word = lm.get(wrd);
        data.add(word);
      }
      if (bNewField) {
        metaData.putData(Globals.SELECTOR_META_PREFIX + fieldName, data);
      }
    }

    // System.out.println("TODO: remove metadata for removed selector field.");
    panel.markNonUndoableBaseChanged();

    // Update all selectors in the current BasePanel.
    if (changedFieldSet) {
      panel.rebuildAllEntryEditors();
    } else {
      panel.updateAllContentSelectors();
    }
    panel.getAutoCompleters().addContentSelectorValuesToAutoCompleters(panel.metaData);
  }
Esempio n. 2
0
 @Override
 public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
   for (MetaDataChangeUnit unit : changes) {
     switch (unit.type) {
       case ADD:
         md.putData(unit.key, unit.value);
         mdSecondary.putData(unit.key, unit.value);
         break;
       case REMOVE:
         md.remove(unit.key);
         mdSecondary.remove(unit.key);
         break;
       case MODIFY:
         md.putData(unit.key, unit.value);
         mdSecondary.putData(unit.key, unit.value);
         break;
     }
   }
   return true;
 }