1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 | import static org.xnap.commons.i18n.I18n.marktr;
|
---|
7 |
|
---|
8 | import java.awt.BorderLayout;
|
---|
9 | import java.awt.Component;
|
---|
10 | import java.awt.Font;
|
---|
11 | import java.awt.GridBagLayout;
|
---|
12 | import java.awt.GridLayout;
|
---|
13 | import java.awt.event.ActionEvent;
|
---|
14 | import java.awt.event.ActionListener;
|
---|
15 | import java.awt.event.FocusAdapter;
|
---|
16 | import java.awt.event.FocusEvent;
|
---|
17 | import java.awt.event.KeyEvent;
|
---|
18 | import java.awt.event.MouseAdapter;
|
---|
19 | import java.awt.event.MouseEvent;
|
---|
20 | import java.util.Collection;
|
---|
21 | import java.util.HashMap;
|
---|
22 | import java.util.Map;
|
---|
23 | import java.util.TreeMap;
|
---|
24 | import java.util.TreeSet;
|
---|
25 | import java.util.Vector;
|
---|
26 | import java.util.Map.Entry;
|
---|
27 |
|
---|
28 | import javax.swing.Box;
|
---|
29 | import javax.swing.DefaultComboBoxModel;
|
---|
30 | import javax.swing.JButton;
|
---|
31 | import javax.swing.JComboBox;
|
---|
32 | import javax.swing.JDialog;
|
---|
33 | import javax.swing.JLabel;
|
---|
34 | import javax.swing.JOptionPane;
|
---|
35 | import javax.swing.JPanel;
|
---|
36 | import javax.swing.JScrollPane;
|
---|
37 | import javax.swing.JTable;
|
---|
38 | import javax.swing.JTextField;
|
---|
39 | import javax.swing.ListSelectionModel;
|
---|
40 | import javax.swing.table.DefaultTableCellRenderer;
|
---|
41 | import javax.swing.table.DefaultTableModel;
|
---|
42 | import javax.swing.text.JTextComponent;
|
---|
43 |
|
---|
44 | import org.openstreetmap.josm.Main;
|
---|
45 | import org.openstreetmap.josm.command.ChangePropertyCommand;
|
---|
46 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
47 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
48 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
49 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
50 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
51 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
52 | import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
|
---|
53 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
54 | import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
|
---|
55 | import org.openstreetmap.josm.gui.tagging.ForwardActionListener;
|
---|
56 | import org.openstreetmap.josm.gui.tagging.TaggingCellRenderer;
|
---|
57 | import org.openstreetmap.josm.gui.tagging.TaggingPreset;
|
---|
58 | import org.openstreetmap.josm.tools.AutoCompleteComboBox;
|
---|
59 | import org.openstreetmap.josm.tools.GBC;
|
---|
60 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * This dialog displays the properties of the current selected primitives.
|
---|
64 | *
|
---|
65 | * If no object is selected, the dialog list is empty.
|
---|
66 | * If only one is selected, all properties of this object are selected.
|
---|
67 | * If more than one object are selected, the sum of all properties are displayed. If the
|
---|
68 | * different objects share the same property, the shared value is displayed. If they have
|
---|
69 | * different values, all of them are put in a combo box and the string "<different>"
|
---|
70 | * is displayed in italic.
|
---|
71 | *
|
---|
72 | * Below the list, the user can click on an add, modify and delete property button to
|
---|
73 | * edit the table selection value.
|
---|
74 | *
|
---|
75 | * The command is applied to all selected entries.
|
---|
76 | *
|
---|
77 | * @author imi
|
---|
78 | */
|
---|
79 | public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener {
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Used to display relation names in the membership table
|
---|
83 | */
|
---|
84 | private NameVisitor nameVisitor = new NameVisitor();
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Watches for double clicks and from editing or new property, depending on the
|
---|
88 | * location, the click was.
|
---|
89 | * @author imi
|
---|
90 | */
|
---|
91 | public class DblClickWatch extends MouseAdapter {
|
---|
92 | @Override public void mouseClicked(MouseEvent e) {
|
---|
93 | if (e.getClickCount() < 2)
|
---|
94 | return;
|
---|
95 |
|
---|
96 | if (e.getSource() == propertyTable)
|
---|
97 | {
|
---|
98 | int row = propertyTable.rowAtPoint(e.getPoint());
|
---|
99 | if (row > -1) {
|
---|
100 | propertyEdit(row);
|
---|
101 | return;
|
---|
102 | }
|
---|
103 | } else if (e.getSource() == membershipTable) {
|
---|
104 | int row = membershipTable.rowAtPoint(e.getPoint());
|
---|
105 | if (row > -1) {
|
---|
106 | membershipEdit(row);
|
---|
107 | return;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | add();
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Edit the value in the properties table row
|
---|
116 | * @param row The row of the table from which the value is edited.
|
---|
117 | */
|
---|
118 | void propertyEdit(int row) {
|
---|
119 | String key = propertyData.getValueAt(row, 0).toString();
|
---|
120 | Collection<OsmPrimitive> sel = Main.ds.getSelected();
|
---|
121 | if (sel.isEmpty()) {
|
---|
122 | JOptionPane.showMessageDialog(Main.parent, tr("Please select the objects you want to change properties for."));
|
---|
123 | return;
|
---|
124 | }
|
---|
125 | String msg = "<html>"+trn("This will change {0} object.", "This will change {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>";
|
---|
126 |
|
---|
127 | JPanel panel = new JPanel(new BorderLayout());
|
---|
128 | panel.add(new JLabel(msg), BorderLayout.NORTH);
|
---|
129 |
|
---|
130 | JPanel p = new JPanel(new GridBagLayout());
|
---|
131 | panel.add(p, BorderLayout.CENTER);
|
---|
132 |
|
---|
133 | final JTextField keyField = new JTextField(key);
|
---|
134 | p.add(new JLabel(tr("Key")), GBC.std());
|
---|
135 | p.add(Box.createHorizontalStrut(10), GBC.std());
|
---|
136 | p.add(keyField, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
137 |
|
---|
138 | final JTextField valueField = new JTextField((String)propertyData.getValueAt(row, 1));
|
---|
139 | p.add(new JLabel(tr("Value")), GBC.std());
|
---|
140 | p.add(Box.createHorizontalStrut(10), GBC.std());
|
---|
141 | p.add(valueField, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
142 |
|
---|
143 | final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
|
---|
144 | @Override public void selectInitialValue() {
|
---|
145 | valueField.requestFocusInWindow();
|
---|
146 | valueField.selectAll();
|
---|
147 | }
|
---|
148 | };
|
---|
149 | final JDialog dlg = optionPane.createDialog(Main.parent, tr("Change values?"));
|
---|
150 | valueField.addActionListener(new ActionListener(){
|
---|
151 | public void actionPerformed(ActionEvent e) {
|
---|
152 | optionPane.setValue(JOptionPane.OK_OPTION);
|
---|
153 | dlg.setVisible(false);
|
---|
154 | }
|
---|
155 | });
|
---|
156 | dlg.setVisible(true);
|
---|
157 |
|
---|
158 | Object answer = optionPane.getValue();
|
---|
159 | if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE ||
|
---|
160 | (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) {
|
---|
161 | return;
|
---|
162 | }
|
---|
163 |
|
---|
164 | String value = valueField.getText();
|
---|
165 | if (value.equals(tr("<different>")))
|
---|
166 | return;
|
---|
167 | if (value.equals(""))
|
---|
168 | value = null; // delete the key
|
---|
169 | String newkey = keyField.getText();
|
---|
170 | if (newkey.equals("")) {
|
---|
171 | newkey = key;
|
---|
172 | value = null; // delete the key instead
|
---|
173 | }
|
---|
174 | if (key.equals(newkey) || value == null)
|
---|
175 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value));
|
---|
176 | else {
|
---|
177 | Main.main.undoRedo.add(new SequenceCommand(trn("Change properties of {0} object", "Change properties of {0} objects", sel.size(), sel.size()),
|
---|
178 | new ChangePropertyCommand(sel, key, null),
|
---|
179 | new ChangePropertyCommand(sel, newkey, value)));
|
---|
180 | }
|
---|
181 |
|
---|
182 | selectionChanged(sel); // update whole table
|
---|
183 | Main.parent.repaint(); // repaint all - drawing could have been changed
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * This simply fires up an relation editor for the relation shown; everything else
|
---|
188 | * is the editor's business.
|
---|
189 | *
|
---|
190 | * @param row
|
---|
191 | */
|
---|
192 | void membershipEdit(int row) {
|
---|
193 | final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0));
|
---|
194 | editor.setVisible(true);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Open the add selection dialog and add a new key/value to the table (and
|
---|
199 | * to the dataset, of course).
|
---|
200 | */
|
---|
201 | void add() {
|
---|
202 | Collection<OsmPrimitive> sel = Main.ds.getSelected();
|
---|
203 | if (sel.isEmpty()) {
|
---|
204 | JOptionPane.showMessageDialog(Main.parent, tr("Please select objects for which you want to change properties."));
|
---|
205 | return;
|
---|
206 | }
|
---|
207 |
|
---|
208 | JPanel p = new JPanel(new BorderLayout());
|
---|
209 | p.add(new JLabel("<html>"+trn("This will change {0} object.","This will change {0} objects.", sel.size(),sel.size())+"<br><br>"+tr("Please select a key")),
|
---|
210 | BorderLayout.NORTH);
|
---|
211 | final TreeMap<String,TreeSet<String>> allData = new TreeMap<String,TreeSet<String>>();
|
---|
212 | for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {
|
---|
213 | for (String key : osm.keySet()) {
|
---|
214 | TreeSet<String> values = null;
|
---|
215 | if (allData.containsKey(key))
|
---|
216 | values = allData.get(key);
|
---|
217 | else {
|
---|
218 | values = new TreeSet<String>();
|
---|
219 | allData.put(key, values);
|
---|
220 | }
|
---|
221 | values.add(osm.get(key));
|
---|
222 | }
|
---|
223 | }
|
---|
224 | for (int i = 0; i < propertyData.getRowCount(); ++i)
|
---|
225 | allData.remove(propertyData.getValueAt(i, 0));
|
---|
226 | final AutoCompleteComboBox keys = new AutoCompleteComboBox();
|
---|
227 | keys.setPossibleItems(allData.keySet());
|
---|
228 | keys.setEditable(true);
|
---|
229 |
|
---|
230 | p.add(keys, BorderLayout.CENTER);
|
---|
231 |
|
---|
232 | JPanel p2 = new JPanel(new BorderLayout());
|
---|
233 | p.add(p2, BorderLayout.SOUTH);
|
---|
234 | p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH);
|
---|
235 | final AutoCompleteComboBox values = new AutoCompleteComboBox();
|
---|
236 | values.setEditable(true);
|
---|
237 | p2.add(values, BorderLayout.CENTER);
|
---|
238 |
|
---|
239 | // get the combo box' editor component
|
---|
240 | JTextComponent editor = (JTextComponent) values.getEditor().getEditorComponent();
|
---|
241 | // Refresh the values model when focus is gained
|
---|
242 | editor.addFocusListener(new FocusAdapter() {
|
---|
243 | @Override public void focusGained(FocusEvent e) {
|
---|
244 | String key = keys.getEditor().getItem().toString();
|
---|
245 | if (allData.containsKey(key)) {
|
---|
246 | values.setPossibleItems(allData.get(key));
|
---|
247 | } else {
|
---|
248 | values.removeAllItems();
|
---|
249 | }
|
---|
250 | }
|
---|
251 | });
|
---|
252 |
|
---|
253 | JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
|
---|
254 | @Override public void selectInitialValue() {
|
---|
255 | keys.requestFocusInWindow();
|
---|
256 | keys.getEditor().selectAll();
|
---|
257 | }
|
---|
258 | };
|
---|
259 | pane.createDialog(Main.parent, tr("Change values?")).setVisible(true);
|
---|
260 | if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
|
---|
261 | return;
|
---|
262 | String key = keys.getEditor().getItem().toString();
|
---|
263 | String value = values.getEditor().getItem().toString();
|
---|
264 | if (value.equals(""))
|
---|
265 | return;
|
---|
266 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
|
---|
267 | selectionChanged(sel); // update table
|
---|
268 | Main.parent.repaint(); // repaint all - drawing could have been changed
|
---|
269 | }
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Delete the keys from the given row.
|
---|
273 | * @param row The row, which key gets deleted from the dataset.
|
---|
274 | */
|
---|
275 | private void delete(int row) {
|
---|
276 | String key = propertyData.getValueAt(row, 0).toString();
|
---|
277 | Collection<OsmPrimitive> sel = Main.ds.getSelected();
|
---|
278 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
|
---|
279 | selectionChanged(sel); // update table
|
---|
280 | }
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * The property data.
|
---|
284 | */
|
---|
285 | private final DefaultTableModel propertyData = new DefaultTableModel() {
|
---|
286 | @Override public boolean isCellEditable(int row, int column) {
|
---|
287 | return false;
|
---|
288 | }
|
---|
289 | @Override public Class<?> getColumnClass(int columnIndex) {
|
---|
290 | return String.class;
|
---|
291 | }
|
---|
292 | };
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * The membership data.
|
---|
296 | */
|
---|
297 | private final DefaultTableModel membershipData = new DefaultTableModel() {
|
---|
298 | @Override public boolean isCellEditable(int row, int column) {
|
---|
299 | return false;
|
---|
300 | }
|
---|
301 | @Override public Class<?> getColumnClass(int columnIndex) {
|
---|
302 | return columnIndex == 1 ? Relation.class : String.class;
|
---|
303 | }
|
---|
304 | };
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * The properties list.
|
---|
308 | */
|
---|
309 | private final JTable propertyTable = new JTable(propertyData);
|
---|
310 | private final JTable membershipTable = new JTable(membershipData);
|
---|
311 |
|
---|
312 | public JComboBox taggingPresets = new JComboBox();
|
---|
313 |
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Create a new PropertiesDialog
|
---|
317 | */
|
---|
318 | public PropertiesDialog(MapFrame mapFrame) {
|
---|
319 | super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), KeyEvent.VK_P, 150);
|
---|
320 |
|
---|
321 | if (TaggingPresetPreference.taggingPresets.size() > 0) {
|
---|
322 | Vector<ActionListener> allPresets = new Vector<ActionListener>();
|
---|
323 | for (final TaggingPreset p : TaggingPresetPreference.taggingPresets)
|
---|
324 | allPresets.add(new ForwardActionListener(this, p));
|
---|
325 |
|
---|
326 | allPresets.add(0, new ForwardActionListener(this, new TaggingPreset()));
|
---|
327 | taggingPresets.setModel(new DefaultComboBoxModel(allPresets));
|
---|
328 | JPanel north = new JPanel(new GridBagLayout());
|
---|
329 | north.add(getComponent(0),GBC.eol().fill(GBC.HORIZONTAL));
|
---|
330 | north.add(taggingPresets,GBC.eol().fill(GBC.HORIZONTAL));
|
---|
331 | add(north, BorderLayout.NORTH);
|
---|
332 | }
|
---|
333 | taggingPresets.addActionListener(new ActionListener(){
|
---|
334 | public void actionPerformed(ActionEvent e) {
|
---|
335 | TaggingPreset preset = ((ForwardActionListener)taggingPresets.getSelectedItem()).preset;
|
---|
336 | preset.actionPerformed(e);
|
---|
337 | taggingPresets.setSelectedItem(null);
|
---|
338 | }
|
---|
339 | });
|
---|
340 | taggingPresets.setRenderer(new TaggingCellRenderer());
|
---|
341 |
|
---|
342 | // setting up the properties table
|
---|
343 |
|
---|
344 | propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
|
---|
345 | propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
346 |
|
---|
347 | propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){
|
---|
348 | @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
349 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
350 | if (c instanceof JLabel) {
|
---|
351 | String str = (String) value;
|
---|
352 | ((JLabel)c).setText(str);
|
---|
353 | if (str.equals(tr("<different>")))
|
---|
354 | c.setFont(c.getFont().deriveFont(Font.ITALIC));
|
---|
355 | }
|
---|
356 | return c;
|
---|
357 | }
|
---|
358 | });
|
---|
359 |
|
---|
360 | // setting up the membership table
|
---|
361 |
|
---|
362 | membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")});
|
---|
363 | membershipTable.setRowSelectionAllowed(false);
|
---|
364 |
|
---|
365 | membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
|
---|
366 | @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
367 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
368 | if (c instanceof JLabel) {
|
---|
369 | nameVisitor.visit((Relation)value);
|
---|
370 | ((JLabel)c).setText(nameVisitor.name);
|
---|
371 | }
|
---|
372 | return c;
|
---|
373 | }
|
---|
374 | });
|
---|
375 |
|
---|
376 | // combine both tables and wrap them in a scrollPane
|
---|
377 | JPanel bothTables = new JPanel();
|
---|
378 | bothTables.setLayout(new GridBagLayout());
|
---|
379 | bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
380 | bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH));
|
---|
381 | bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
382 | bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH));
|
---|
383 |
|
---|
384 | DblClickWatch dblClickWatch = new DblClickWatch();
|
---|
385 | propertyTable.addMouseListener(dblClickWatch);
|
---|
386 | membershipTable.addMouseListener(dblClickWatch);
|
---|
387 | JScrollPane scrollPane = new JScrollPane(bothTables);
|
---|
388 | scrollPane.addMouseListener(dblClickWatch);
|
---|
389 | add(scrollPane, BorderLayout.CENTER);
|
---|
390 |
|
---|
391 | JPanel buttonPanel = new JPanel(new GridLayout(1,3));
|
---|
392 | ActionListener buttonAction = new ActionListener(){
|
---|
393 | public void actionPerformed(ActionEvent e) {
|
---|
394 | int sel = propertyTable.getSelectedRow();
|
---|
395 | if (e.getActionCommand().equals("Add"))
|
---|
396 | add();
|
---|
397 | else if (e.getActionCommand().equals("Edit")) {
|
---|
398 | if (sel == -1)
|
---|
399 | JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit."));
|
---|
400 | else
|
---|
401 | propertyEdit(sel);
|
---|
402 | } else if (e.getActionCommand().equals("Delete")) {
|
---|
403 | if (sel == -1)
|
---|
404 | JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."));
|
---|
405 | else
|
---|
406 | delete(sel);
|
---|
407 | }
|
---|
408 | }
|
---|
409 | };
|
---|
410 |
|
---|
411 | buttonPanel.add(createButton(marktr("Add"),tr("Add a new key/value pair to all objects"), KeyEvent.VK_A, buttonAction));
|
---|
412 | buttonPanel.add(createButton(marktr("Edit"),tr( "Edit the value of the selected key for all objects"), KeyEvent.VK_E, buttonAction));
|
---|
413 | buttonPanel.add(createButton(marktr("Delete"),tr("Delete the selected key in all objects"), KeyEvent.VK_D, buttonAction));
|
---|
414 | add(buttonPanel, BorderLayout.SOUTH);
|
---|
415 |
|
---|
416 | DataSet.selListeners.add(this);
|
---|
417 | }
|
---|
418 |
|
---|
419 | private JButton createButton(String name, String tooltip, int mnemonic, ActionListener actionListener) {
|
---|
420 | JButton b = new JButton(tr(name), ImageProvider.get("dialogs", name.toLowerCase()));
|
---|
421 | b.setActionCommand(name);
|
---|
422 | b.addActionListener(actionListener);
|
---|
423 | b.setToolTipText(tooltip);
|
---|
424 | b.setMnemonic(mnemonic);
|
---|
425 | b.putClientProperty("help", "Dialog/Properties/"+name);
|
---|
426 | return b;
|
---|
427 | }
|
---|
428 |
|
---|
429 | @Override public void setVisible(boolean b) {
|
---|
430 | super.setVisible(b);
|
---|
431 | if (b)
|
---|
432 | selectionChanged(Main.ds.getSelected());
|
---|
433 | }
|
---|
434 |
|
---|
435 | public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
|
---|
436 | if (!isVisible())
|
---|
437 | return;
|
---|
438 | if (propertyTable == null)
|
---|
439 | return; // selection changed may be received in base class constructor before init
|
---|
440 | if (propertyTable.getCellEditor() != null)
|
---|
441 | propertyTable.getCellEditor().cancelCellEditing();
|
---|
442 |
|
---|
443 | // re-load property data
|
---|
444 |
|
---|
445 | propertyData.setRowCount(0);
|
---|
446 |
|
---|
447 | Map<String, Integer> valueCount = new HashMap<String, Integer>();
|
---|
448 | TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>();
|
---|
449 | for (OsmPrimitive osm : newSelection) {
|
---|
450 | for (Entry<String, String> e : osm.entrySet()) {
|
---|
451 | Collection<String> value = props.get(e.getKey());
|
---|
452 | if (value == null) {
|
---|
453 | value = new TreeSet<String>();
|
---|
454 | props.put(e.getKey(), value);
|
---|
455 | }
|
---|
456 | value.add(e.getValue());
|
---|
457 | valueCount.put(e.getKey(), valueCount.containsKey(e.getKey()) ? valueCount.get(e.getKey())+1 : 1);
|
---|
458 | }
|
---|
459 | }
|
---|
460 | for (Entry<String, Collection<String>> e : props.entrySet()) {
|
---|
461 | String value=(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next());
|
---|
462 | propertyData.addRow(new Object[]{e.getKey(), value});
|
---|
463 | }
|
---|
464 |
|
---|
465 | // re-load membership data
|
---|
466 | // this is rather expensive since we have to walk through all members of all existing relationships.
|
---|
467 | // could use back references here for speed if necessary.
|
---|
468 |
|
---|
469 | membershipData.setRowCount(0);
|
---|
470 |
|
---|
471 | Map<Relation, Integer> valueCountM = new HashMap<Relation, Integer>();
|
---|
472 | TreeMap<Relation, Collection<String>> roles = new TreeMap<Relation, Collection<String>>();
|
---|
473 | for (Relation r : Main.ds.relations) {
|
---|
474 | for (RelationMember m : r.members) {
|
---|
475 | if (newSelection.contains(m.member)) {
|
---|
476 | Collection<String> value = roles.get(r);
|
---|
477 | if (value == null) {
|
---|
478 | value = new TreeSet<String>();
|
---|
479 | roles.put(r, value);
|
---|
480 | }
|
---|
481 | value.add(m.role);
|
---|
482 | valueCountM.put(r, valueCount.containsKey(r) ? valueCount.get(r)+1 : 1);
|
---|
483 | }
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | for (Entry<Relation, Collection<String>> e : roles.entrySet()) {
|
---|
488 | //JComboBox value = new JComboBox(e.getValue().toArray());
|
---|
489 | //value.setEditable(true);
|
---|
490 | //value.getEditor().setItem(e.getValue().size() > 1 || valueCount.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next());
|
---|
491 | String value = e.getValue().size() > 1 || valueCountM.get(e.getKey()) != newSelection.size() ? tr("<different>") : e.getValue().iterator().next();
|
---|
492 | membershipData.addRow(new Object[]{e.getKey(), value});
|
---|
493 | }
|
---|
494 | }
|
---|
495 | }
|
---|