DcField field = null;
int module;
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode current;
DefaultMutableTreeNode parent;
DefaultMutableTreeNode previous;
boolean exists = false;
Map<String, Integer> items = DataManager.getKeys(DataFilters.getCurrent(getModule()));
Collection<String> keys = null;
if (DataFilters.isFilterActive(getModule())) {
keys = new ArrayList<String>(items.keySet());
}
while (rs.next() && !stop) {
int level = 0;
parent = top;
for (int idx = 0; idx < fields.length; idx++) {
field = DcModules.get(getModule()).getField(fields[idx]);
if (field.isUiOnly() &&
field.getIndex() != DcObject._SYS_MODULE &&
field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
field.getFieldType() != ComponentFactory._REFERENCEFIELD)
continue;
if (stop) break;
// for each level the field index is shifted to the end.
id = rs.getString(1);
module = rs.getInt(2);
key = field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getObject((level * 3) + 3);
value = field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getString((level * 3) + 4);
iconBase64 = field.getIndex() != DcObject._SYS_MODULE ? rs.getString((level * 3) + 5) : null;
icon = field.getIndex() == DcObject._SYS_MODULE ?
new DcImageIcon(DcModules.get(module).getIcon16().getImage()) :
iconBase64 != null ? DataManager.addIcon(String.valueOf(key), iconBase64) : null;
if (keys != null && !keys.contains(id)) continue;
previous = parent.getChildCount() == 0 ? null : ((DefaultMutableTreeNode) parent.getChildAt(parent.getChildCount() - 1));
exists = previous == null || (((NodeElement) previous.getUserObject()).getKey() == null && key != null) ? false :
((NodeElement) previous.getUserObject()).getKey() == key || // empty key
((NodeElement) previous.getUserObject()).getKey().equals(key);
if (!exists) {
if (key == null) {
ne = new NodeElement(null, empty, null);
} else {
ne = new NodeElement(key, value, icon);
}
ne.addItem(id, module);
current = new DcDefaultMutableTreeNode(ne);
parent.add(current);
parent = current;
} else { // exists
existingNe =(NodeElement) previous.getUserObject();
existingNe.addItem(id, module);
model.nodeChanged(previous);
parent = previous;
}