/** * For all fields with both autocompletion and content selector, add content selector values to * the autocompleter list: */ public void addContentSelectorValuesToAutoCompleters(MetaData metaData) { for (Map.Entry<String, AutoCompleter> entry : this.autoCompleters.entrySet()) { AutoCompleter ac = entry.getValue(); if (metaData.getData(Globals.SELECTOR_META_PREFIX + entry.getKey()) != null) { Vector<String> items = metaData.getData(Globals.SELECTOR_META_PREFIX + entry.getKey()); if (items != null) { for (String item : items) { ac.addWordToIndex(item); } } } } }
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); }
private void setupWordSelector() { // Have we already created a listmodel for this field? wordListModel = wordListModels.get(currentField); if (wordListModel != null) { wordList.setModel(wordListModel); } else { wordListModel = new DefaultListModel<>(); wordList.setModel(wordListModel); wordListModels.put(currentField, wordListModel); // wordListModel.addElement(WORD_FIRSTLINE_TEXT); Vector<String> items = metaData.getData(Globals.SELECTOR_META_PREFIX + currentField); if (items != null) { TreeSet<String> wordSet = new TreeSet<>(items); int index = 0; for (String s : wordSet) { wordListModel.add(index, s); index++; } } } }