if (newSel == null) {
newSel = Collections.<OsmPrimitive>emptyList();
}
String selectedTag;
Relation selectedRelation = null;
selectedTag = editHelper.getChangedKey(); // select last added or last edited key by default
if (selectedTag == null && tagTable.getSelectedRowCount() == 1) {
selectedTag = (String)tagData.getValueAt(tagTable.getSelectedRow(), 0);
}
if (membershipTable.getSelectedRowCount() == 1) {
selectedRelation = (Relation)membershipData.getValueAt(membershipTable.getSelectedRow(), 0);
}
// re-load tag data
tagData.setRowCount(0);
final boolean displayDiscardableKeys = Main.pref.getBoolean("display.discardable-keys", false);
final Map<String, Integer> keyCount = new HashMap<>();
final Map<String, String> tags = new HashMap<>();
valueCount.clear();
EnumSet<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
for (OsmPrimitive osm : newSel) {
types.add(TaggingPresetType.forPrimitive(osm));
for (String key : osm.keySet()) {
if (displayDiscardableKeys || !OsmPrimitive.getDiscardableKeys().contains(key)) {
String value = osm.get(key);
keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1);
if (valueCount.containsKey(key)) {
Map<String, Integer> v = valueCount.get(key);
v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);
} else {
TreeMap<String, Integer> v = new TreeMap<>();
v.put(value, 1);
valueCount.put(key, v);
}
}
}
}
for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) {
int count = 0;
for (Entry<String, Integer> e1 : e.getValue().entrySet()) {
count += e1.getValue();
}
if (count < newSel.size()) {
e.getValue().put("", newSel.size() - count);
}
tagData.addRow(new Object[]{e.getKey(), e.getValue()});
tags.put(e.getKey(), e.getValue().size() == 1
? e.getValue().keySet().iterator().next() : tr("<different>"));
}
membershipData.setRowCount(0);
Map<Relation, MemberInfo> roles = new HashMap<>();
for (OsmPrimitive primitive: newSel) {
for (OsmPrimitive ref: primitive.getReferrers(true)) {
if (ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted()) {
Relation r = (Relation) ref;
MemberInfo mi = roles.get(r);
if(mi == null) {
mi = new MemberInfo(newSel);
}
roles.put(r, mi);
int i = 1;
for (RelationMember m : r.getMembers()) {
if (m.getMember() == primitive) {
mi.add(m, i);
}
++i;
}