private static String getDescription(final Dictionary dictionary) { if (dictionary.getDescription() != null) { return dictionary.getDescription(); } if (dictionary instanceof TextFileDictionary) { return ((TextFileDictionary) dictionary).getFilename(); } else if (dictionary instanceof DatastoreDictionary) { final DatastoreDictionary datastoreDictionary = (DatastoreDictionary) dictionary; return datastoreDictionary.getDatastoreName() + ": " + datastoreDictionary.getQualifiedColumnName(); } else if (dictionary instanceof SimpleDictionary) { final SimpleDictionary simpleDictionary = (SimpleDictionary) dictionary; final Collection<String> values = simpleDictionary.getValueSet(); final StringBuilder sb = new StringBuilder(); for (final String value : values) { if (sb.length() > 0) { sb.append(","); } sb.append(value); if (sb.length() > 20) { break; } } return sb.toString(); } return ""; }
private Element toElement(final SimpleDictionary dictionary) { final Element elem = getDocument().createElement("value-list-dictionary"); elem.setAttribute("name", dictionary.getName()); if (!Strings.isNullOrEmpty(dictionary.getDescription())) { elem.setAttribute("description", dictionary.getDescription()); } final Set<String> values = dictionary.getValueSet(); for (final String value : values) { appendElement(elem, "value", value); } appendElement(elem, "case-sensitive", dictionary.isCaseSensitive()); return elem; }
@Inject protected SimpleDictionaryDialog(@Nullable final SimpleDictionary dictionary, final MutableReferenceDataCatalog catalog, final WindowContext windowContext) { super(windowContext, ImageManager.get().getImage(IconUtils.DICTIONARY_SIMPLE_IMAGEPATH)); _originalDictionary = dictionary; _catalog = catalog; _nameTextField = WidgetFactory.createTextField("Dictionary name"); _valuesTextArea = WidgetFactory.createTextArea("Values"); _valuesTextArea.setRows(14); _caseSensitiveCheckBox = new DCCheckBox<>("Case-sensitive?", false); _caseSensitiveCheckBox.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST); _caseSensitiveCheckBox.setOpaque(false); _caseSensitiveCheckBox.setToolTipText("Only match on dictionary terms when text-case is the same."); if (dictionary != null) { _nameTextField.setText(dictionary.getName()); final Collection<String> values = dictionary.getValueSet(); final StringBuilder sb = new StringBuilder(); boolean first = true; for (final String value : values) { if (first) { first = false; } else { sb.append('\n'); } sb.append(value); } _valuesTextArea.setText(sb.toString()); _caseSensitiveCheckBox.setSelected(dictionary.isCaseSensitive()); } }