1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.pair;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.awt.FlowLayout;
|
---|
8 | import java.awt.GridBagConstraints;
|
---|
9 | import java.awt.GridBagLayout;
|
---|
10 | import java.awt.Insets;
|
---|
11 | import java.awt.event.ActionEvent;
|
---|
12 | import java.awt.event.ItemEvent;
|
---|
13 | import java.awt.event.ItemListener;
|
---|
14 | import java.beans.PropertyChangeEvent;
|
---|
15 | import java.beans.PropertyChangeListener;
|
---|
16 | import java.util.Collection;
|
---|
17 | import java.util.Observable;
|
---|
18 | import java.util.Observer;
|
---|
19 |
|
---|
20 | import javax.swing.AbstractAction;
|
---|
21 | import javax.swing.Action;
|
---|
22 | import javax.swing.ImageIcon;
|
---|
23 | import javax.swing.JButton;
|
---|
24 | import javax.swing.JCheckBox;
|
---|
25 | import javax.swing.JLabel;
|
---|
26 | import javax.swing.JPanel;
|
---|
27 | import javax.swing.JScrollPane;
|
---|
28 | import javax.swing.JTable;
|
---|
29 | import javax.swing.JToggleButton;
|
---|
30 | import javax.swing.event.ListSelectionEvent;
|
---|
31 | import javax.swing.event.ListSelectionListener;
|
---|
32 |
|
---|
33 | import org.openstreetmap.josm.Main;
|
---|
34 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
35 | import org.openstreetmap.josm.data.osm.PrimitiveId;
|
---|
36 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
37 | import org.openstreetmap.josm.data.osm.Way;
|
---|
38 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
39 | import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
|
---|
40 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
41 | import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTable;
|
---|
42 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * A UI component for resolving conflicts in two lists of entries of type T.
|
---|
46 | *
|
---|
47 | * @param <T> the type of the entries
|
---|
48 | * @see ListMergeModel
|
---|
49 | * @since 1631
|
---|
50 | */
|
---|
51 | public abstract class ListMerger<T extends PrimitiveId> extends JPanel implements PropertyChangeListener, Observer {
|
---|
52 | protected OsmPrimitivesTable myEntriesTable;
|
---|
53 | protected OsmPrimitivesTable mergedEntriesTable;
|
---|
54 | protected OsmPrimitivesTable theirEntriesTable;
|
---|
55 |
|
---|
56 | protected transient ListMergeModel<T> model;
|
---|
57 |
|
---|
58 | private CopyStartLeftAction copyStartLeftAction;
|
---|
59 | private CopyBeforeCurrentLeftAction copyBeforeCurrentLeftAction;
|
---|
60 | private CopyAfterCurrentLeftAction copyAfterCurrentLeftAction;
|
---|
61 | private CopyEndLeftAction copyEndLeftAction;
|
---|
62 | private CopyAllLeft copyAllLeft;
|
---|
63 |
|
---|
64 | private CopyStartRightAction copyStartRightAction;
|
---|
65 | private CopyBeforeCurrentRightAction copyBeforeCurrentRightAction;
|
---|
66 | private CopyAfterCurrentRightAction copyAfterCurrentRightAction;
|
---|
67 | private CopyEndRightAction copyEndRightAction;
|
---|
68 | private CopyAllRight copyAllRight;
|
---|
69 |
|
---|
70 | private MoveUpMergedAction moveUpMergedAction;
|
---|
71 | private MoveDownMergedAction moveDownMergedAction;
|
---|
72 | private RemoveMergedAction removeMergedAction;
|
---|
73 | private FreezeAction freezeAction;
|
---|
74 |
|
---|
75 | private transient AdjustmentSynchronizer adjustmentSynchronizer;
|
---|
76 |
|
---|
77 | private JLabel lblMyVersion;
|
---|
78 | private JLabel lblMergedVersion;
|
---|
79 | private JLabel lblTheirVersion;
|
---|
80 |
|
---|
81 | private JLabel lblFrozenState;
|
---|
82 |
|
---|
83 | protected abstract JScrollPane buildMyElementsTable();
|
---|
84 | protected abstract JScrollPane buildMergedElementsTable();
|
---|
85 | protected abstract JScrollPane buildTheirElementsTable();
|
---|
86 |
|
---|
87 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
88 | JScrollPane pane = new JScrollPane(table);
|
---|
89 | if (adjustmentSynchronizer == null) {
|
---|
90 | adjustmentSynchronizer = new AdjustmentSynchronizer();
|
---|
91 | }
|
---|
92 | return pane;
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected void wireActionsToSelectionModels() {
|
---|
96 | myEntriesTable.getSelectionModel().addListSelectionListener(copyStartLeftAction);
|
---|
97 |
|
---|
98 | myEntriesTable.getSelectionModel().addListSelectionListener(copyBeforeCurrentLeftAction);
|
---|
99 | mergedEntriesTable.getSelectionModel().addListSelectionListener(copyBeforeCurrentLeftAction);
|
---|
100 |
|
---|
101 | myEntriesTable.getSelectionModel().addListSelectionListener(copyAfterCurrentLeftAction);
|
---|
102 | mergedEntriesTable.getSelectionModel().addListSelectionListener(copyAfterCurrentLeftAction);
|
---|
103 |
|
---|
104 | myEntriesTable.getSelectionModel().addListSelectionListener(copyEndLeftAction);
|
---|
105 |
|
---|
106 | theirEntriesTable.getSelectionModel().addListSelectionListener(copyStartRightAction);
|
---|
107 |
|
---|
108 | theirEntriesTable.getSelectionModel().addListSelectionListener(copyBeforeCurrentRightAction);
|
---|
109 | mergedEntriesTable.getSelectionModel().addListSelectionListener(copyBeforeCurrentRightAction);
|
---|
110 |
|
---|
111 | theirEntriesTable.getSelectionModel().addListSelectionListener(copyAfterCurrentRightAction);
|
---|
112 | mergedEntriesTable.getSelectionModel().addListSelectionListener(copyAfterCurrentRightAction);
|
---|
113 |
|
---|
114 | theirEntriesTable.getSelectionModel().addListSelectionListener(copyEndRightAction);
|
---|
115 |
|
---|
116 | mergedEntriesTable.getSelectionModel().addListSelectionListener(moveUpMergedAction);
|
---|
117 | mergedEntriesTable.getSelectionModel().addListSelectionListener(moveDownMergedAction);
|
---|
118 | mergedEntriesTable.getSelectionModel().addListSelectionListener(removeMergedAction);
|
---|
119 |
|
---|
120 | model.addObserver(copyAllLeft);
|
---|
121 | model.addObserver(copyAllRight);
|
---|
122 | model.addPropertyChangeListener(copyAllLeft);
|
---|
123 | model.addPropertyChangeListener(copyAllRight);
|
---|
124 | }
|
---|
125 |
|
---|
126 | protected JPanel buildLeftButtonPanel() {
|
---|
127 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
128 | GridBagConstraints gc = new GridBagConstraints();
|
---|
129 |
|
---|
130 | gc.gridx = 0;
|
---|
131 | gc.gridy = 0;
|
---|
132 | copyStartLeftAction = new CopyStartLeftAction();
|
---|
133 | JButton btn = new JButton(copyStartLeftAction);
|
---|
134 | btn.setName("button.copystartleft");
|
---|
135 | pnl.add(btn, gc);
|
---|
136 |
|
---|
137 | gc.gridx = 0;
|
---|
138 | gc.gridy = 1;
|
---|
139 | copyBeforeCurrentLeftAction = new CopyBeforeCurrentLeftAction();
|
---|
140 | btn = new JButton(copyBeforeCurrentLeftAction);
|
---|
141 | btn.setName("button.copybeforecurrentleft");
|
---|
142 | pnl.add(btn, gc);
|
---|
143 |
|
---|
144 | gc.gridx = 0;
|
---|
145 | gc.gridy = 2;
|
---|
146 | copyAfterCurrentLeftAction = new CopyAfterCurrentLeftAction();
|
---|
147 | btn = new JButton(copyAfterCurrentLeftAction);
|
---|
148 | btn.setName("button.copyaftercurrentleft");
|
---|
149 | pnl.add(btn, gc);
|
---|
150 |
|
---|
151 | gc.gridx = 0;
|
---|
152 | gc.gridy = 3;
|
---|
153 | copyEndLeftAction = new CopyEndLeftAction();
|
---|
154 | btn = new JButton(copyEndLeftAction);
|
---|
155 | btn.setName("button.copyendleft");
|
---|
156 | pnl.add(btn, gc);
|
---|
157 |
|
---|
158 | gc.gridx = 0;
|
---|
159 | gc.gridy = 4;
|
---|
160 | copyAllLeft = new CopyAllLeft();
|
---|
161 | btn = new JButton(copyAllLeft);
|
---|
162 | btn.setName("button.copyallleft");
|
---|
163 | pnl.add(btn, gc);
|
---|
164 |
|
---|
165 | return pnl;
|
---|
166 | }
|
---|
167 |
|
---|
168 | protected JPanel buildRightButtonPanel() {
|
---|
169 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
170 | GridBagConstraints gc = new GridBagConstraints();
|
---|
171 |
|
---|
172 | gc.gridx = 0;
|
---|
173 | gc.gridy = 0;
|
---|
174 | copyStartRightAction = new CopyStartRightAction();
|
---|
175 | pnl.add(new JButton(copyStartRightAction), gc);
|
---|
176 |
|
---|
177 | gc.gridx = 0;
|
---|
178 | gc.gridy = 1;
|
---|
179 | copyBeforeCurrentRightAction = new CopyBeforeCurrentRightAction();
|
---|
180 | pnl.add(new JButton(copyBeforeCurrentRightAction), gc);
|
---|
181 |
|
---|
182 | gc.gridx = 0;
|
---|
183 | gc.gridy = 2;
|
---|
184 | copyAfterCurrentRightAction = new CopyAfterCurrentRightAction();
|
---|
185 | pnl.add(new JButton(copyAfterCurrentRightAction), gc);
|
---|
186 |
|
---|
187 | gc.gridx = 0;
|
---|
188 | gc.gridy = 3;
|
---|
189 | copyEndRightAction = new CopyEndRightAction();
|
---|
190 | pnl.add(new JButton(copyEndRightAction), gc);
|
---|
191 |
|
---|
192 | gc.gridx = 0;
|
---|
193 | gc.gridy = 4;
|
---|
194 | copyAllRight = new CopyAllRight();
|
---|
195 | pnl.add(new JButton(copyAllRight), gc);
|
---|
196 |
|
---|
197 | return pnl;
|
---|
198 | }
|
---|
199 |
|
---|
200 | protected JPanel buildMergedListControlButtons() {
|
---|
201 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
202 | GridBagConstraints gc = new GridBagConstraints();
|
---|
203 |
|
---|
204 | gc.gridx = 0;
|
---|
205 | gc.gridy = 0;
|
---|
206 | gc.gridwidth = 1;
|
---|
207 | gc.gridheight = 1;
|
---|
208 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
209 | gc.anchor = GridBagConstraints.CENTER;
|
---|
210 | gc.weightx = 0.3;
|
---|
211 | gc.weighty = 0.0;
|
---|
212 | moveUpMergedAction = new MoveUpMergedAction();
|
---|
213 | pnl.add(new JButton(moveUpMergedAction), gc);
|
---|
214 |
|
---|
215 | gc.gridx = 1;
|
---|
216 | gc.gridy = 0;
|
---|
217 | moveDownMergedAction = new MoveDownMergedAction();
|
---|
218 | pnl.add(new JButton(moveDownMergedAction), gc);
|
---|
219 |
|
---|
220 | gc.gridx = 2;
|
---|
221 | gc.gridy = 0;
|
---|
222 | removeMergedAction = new RemoveMergedAction();
|
---|
223 | pnl.add(new JButton(removeMergedAction), gc);
|
---|
224 |
|
---|
225 | return pnl;
|
---|
226 | }
|
---|
227 |
|
---|
228 | protected JPanel buildAdjustmentLockControlPanel(JCheckBox cb) {
|
---|
229 | JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
---|
230 | panel.add(new JLabel(tr("lock scrolling")));
|
---|
231 | panel.add(cb);
|
---|
232 | return panel;
|
---|
233 | }
|
---|
234 |
|
---|
235 | protected JPanel buildComparePairSelectionPanel() {
|
---|
236 | JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
---|
237 | p.add(new JLabel(tr("Compare ")));
|
---|
238 | JosmComboBox<ComparePairType> cbComparePair = new JosmComboBox<>(model.getComparePairListModel());
|
---|
239 | cbComparePair.setRenderer(new ComparePairListCellRenderer());
|
---|
240 | p.add(cbComparePair);
|
---|
241 | return p;
|
---|
242 | }
|
---|
243 |
|
---|
244 | protected JPanel buildFrozeStateControlPanel() {
|
---|
245 | JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
---|
246 | lblFrozenState = new JLabel();
|
---|
247 | p.add(lblFrozenState);
|
---|
248 | freezeAction = new FreezeAction();
|
---|
249 | JToggleButton btn = new JToggleButton(freezeAction);
|
---|
250 | freezeAction.adapt(btn);
|
---|
251 | btn.setName("button.freeze");
|
---|
252 | p.add(btn);
|
---|
253 |
|
---|
254 | return p;
|
---|
255 | }
|
---|
256 |
|
---|
257 | protected final void build() {
|
---|
258 | setLayout(new GridBagLayout());
|
---|
259 | GridBagConstraints gc = new GridBagConstraints();
|
---|
260 |
|
---|
261 | // ------------------
|
---|
262 | gc.gridx = 0;
|
---|
263 | gc.gridy = 0;
|
---|
264 | gc.gridwidth = 1;
|
---|
265 | gc.gridheight = 1;
|
---|
266 | gc.fill = GridBagConstraints.NONE;
|
---|
267 | gc.anchor = GridBagConstraints.CENTER;
|
---|
268 | gc.weightx = 0.0;
|
---|
269 | gc.weighty = 0.0;
|
---|
270 | gc.insets = new Insets(10,0,0,0);
|
---|
271 | lblMyVersion = new JLabel(tr("My version"));
|
---|
272 | lblMyVersion.setToolTipText(tr("List of elements in my dataset, i.e. the local dataset"));
|
---|
273 | add(lblMyVersion, gc);
|
---|
274 |
|
---|
275 | gc.gridx = 2;
|
---|
276 | gc.gridy = 0;
|
---|
277 | lblMergedVersion = new JLabel(tr("Merged version"));
|
---|
278 | lblMergedVersion.setToolTipText(tr("List of merged elements. They will replace the list of my elements when the merge decisions are applied."));
|
---|
279 | add(lblMergedVersion, gc);
|
---|
280 |
|
---|
281 | gc.gridx = 4;
|
---|
282 | gc.gridy = 0;
|
---|
283 | lblTheirVersion = new JLabel(tr("Their version"));
|
---|
284 | lblTheirVersion.setToolTipText(tr("List of elements in their dataset, i.e. the server dataset"));
|
---|
285 | add(lblTheirVersion, gc);
|
---|
286 |
|
---|
287 | // ------------------------------
|
---|
288 | gc.gridx = 0;
|
---|
289 | gc.gridy = 1;
|
---|
290 | gc.gridwidth = 1;
|
---|
291 | gc.gridheight = 1;
|
---|
292 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
293 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
294 | gc.weightx = 0.33;
|
---|
295 | gc.weighty = 0.0;
|
---|
296 | gc.insets = new Insets(0,0,0,0);
|
---|
297 | JCheckBox cbLockMyScrolling = new JCheckBox();
|
---|
298 | cbLockMyScrolling.setName("checkbox.lockmyscrolling");
|
---|
299 | add(buildAdjustmentLockControlPanel(cbLockMyScrolling), gc);
|
---|
300 |
|
---|
301 | gc.gridx = 2;
|
---|
302 | gc.gridy = 1;
|
---|
303 | JCheckBox cbLockMergedScrolling = new JCheckBox();
|
---|
304 | cbLockMergedScrolling.setName("checkbox.lockmergedscrolling");
|
---|
305 | add(buildAdjustmentLockControlPanel(cbLockMergedScrolling), gc);
|
---|
306 |
|
---|
307 | gc.gridx = 4;
|
---|
308 | gc.gridy = 1;
|
---|
309 | JCheckBox cbLockTheirScrolling = new JCheckBox();
|
---|
310 | cbLockTheirScrolling.setName("checkbox.locktheirscrolling");
|
---|
311 | add(buildAdjustmentLockControlPanel(cbLockTheirScrolling), gc);
|
---|
312 |
|
---|
313 | // --------------------------------
|
---|
314 | gc.gridx = 0;
|
---|
315 | gc.gridy = 2;
|
---|
316 | gc.gridwidth = 1;
|
---|
317 | gc.gridheight = 1;
|
---|
318 | gc.fill = GridBagConstraints.BOTH;
|
---|
319 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
320 | gc.weightx = 0.33;
|
---|
321 | gc.weighty = 1.0;
|
---|
322 | gc.insets = new Insets(0,0,0,0);
|
---|
323 | JScrollPane pane = buildMyElementsTable();
|
---|
324 | lblMyVersion.setLabelFor(pane);
|
---|
325 | adjustmentSynchronizer.adapt(cbLockMyScrolling, pane.getVerticalScrollBar());
|
---|
326 | add(pane, gc);
|
---|
327 |
|
---|
328 | gc.gridx = 1;
|
---|
329 | gc.gridy = 2;
|
---|
330 | gc.fill = GridBagConstraints.NONE;
|
---|
331 | gc.anchor = GridBagConstraints.CENTER;
|
---|
332 | gc.weightx = 0.0;
|
---|
333 | gc.weighty = 0.0;
|
---|
334 | add(buildLeftButtonPanel(), gc);
|
---|
335 |
|
---|
336 | gc.gridx = 2;
|
---|
337 | gc.gridy = 2;
|
---|
338 | gc.fill = GridBagConstraints.BOTH;
|
---|
339 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
340 | gc.weightx = 0.33;
|
---|
341 | gc.weighty = 0.0;
|
---|
342 | pane = buildMergedElementsTable();
|
---|
343 | lblMergedVersion.setLabelFor(pane);
|
---|
344 | adjustmentSynchronizer.adapt(cbLockMergedScrolling, pane.getVerticalScrollBar());
|
---|
345 | add(pane, gc);
|
---|
346 |
|
---|
347 | gc.gridx = 3;
|
---|
348 | gc.gridy = 2;
|
---|
349 | gc.fill = GridBagConstraints.NONE;
|
---|
350 | gc.anchor = GridBagConstraints.CENTER;
|
---|
351 | gc.weightx = 0.0;
|
---|
352 | gc.weighty = 0.0;
|
---|
353 | add(buildRightButtonPanel(), gc);
|
---|
354 |
|
---|
355 | gc.gridx = 4;
|
---|
356 | gc.gridy = 2;
|
---|
357 | gc.fill = GridBagConstraints.BOTH;
|
---|
358 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
359 | gc.weightx = 0.33;
|
---|
360 | gc.weighty = 0.0;
|
---|
361 | pane = buildTheirElementsTable();
|
---|
362 | lblTheirVersion.setLabelFor(pane);
|
---|
363 | adjustmentSynchronizer.adapt(cbLockTheirScrolling, pane.getVerticalScrollBar());
|
---|
364 | add(pane, gc);
|
---|
365 |
|
---|
366 | // ----------------------------------
|
---|
367 | gc.gridx = 2;
|
---|
368 | gc.gridy = 3;
|
---|
369 | gc.gridwidth = 1;
|
---|
370 | gc.gridheight = 1;
|
---|
371 | gc.fill = GridBagConstraints.BOTH;
|
---|
372 | gc.anchor = GridBagConstraints.CENTER;
|
---|
373 | gc.weightx = 0.0;
|
---|
374 | gc.weighty = 0.0;
|
---|
375 | add(buildMergedListControlButtons(), gc);
|
---|
376 |
|
---|
377 | // -----------------------------------
|
---|
378 | gc.gridx = 0;
|
---|
379 | gc.gridy = 4;
|
---|
380 | gc.gridwidth = 2;
|
---|
381 | gc.gridheight = 1;
|
---|
382 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
383 | gc.anchor = GridBagConstraints.LINE_START;
|
---|
384 | gc.weightx = 0.0;
|
---|
385 | gc.weighty = 0.0;
|
---|
386 | add(buildComparePairSelectionPanel(), gc);
|
---|
387 |
|
---|
388 | gc.gridx = 2;
|
---|
389 | gc.gridy = 4;
|
---|
390 | gc.gridwidth = 3;
|
---|
391 | gc.gridheight = 1;
|
---|
392 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
393 | gc.anchor = GridBagConstraints.LINE_START;
|
---|
394 | gc.weightx = 0.0;
|
---|
395 | gc.weighty = 0.0;
|
---|
396 | add(buildFrozeStateControlPanel(), gc);
|
---|
397 |
|
---|
398 | wireActionsToSelectionModels();
|
---|
399 | }
|
---|
400 |
|
---|
401 | /**
|
---|
402 | * Constructs a new {@code ListMerger}.
|
---|
403 | * @param model list merger model
|
---|
404 | */
|
---|
405 | public ListMerger(ListMergeModel<T> model) {
|
---|
406 | this.model = model;
|
---|
407 | model.addObserver(this);
|
---|
408 | build();
|
---|
409 | model.addPropertyChangeListener(this);
|
---|
410 | }
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * Base class of all other Copy* inner classes.
|
---|
414 | */
|
---|
415 | abstract class CopyAction extends AbstractAction implements ListSelectionListener {
|
---|
416 |
|
---|
417 | protected CopyAction(String icon_name, String action_name, String short_description) {
|
---|
418 | ImageIcon icon = ImageProvider.get("dialogs/conflict", icon_name);
|
---|
419 | putValue(Action.SMALL_ICON, icon);
|
---|
420 | if (icon == null) {
|
---|
421 | putValue(Action.NAME, action_name);
|
---|
422 | }
|
---|
423 | putValue(Action.SHORT_DESCRIPTION, short_description);
|
---|
424 | setEnabled(false);
|
---|
425 | }
|
---|
426 | }
|
---|
427 |
|
---|
428 | /**
|
---|
429 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
430 | * nodes. Inserts the nodes at the beginning of the list of merged nodes.
|
---|
431 | */
|
---|
432 | class CopyStartLeftAction extends CopyAction {
|
---|
433 |
|
---|
434 | public CopyStartLeftAction() {
|
---|
435 | super(/* ICON(dialogs/conflict/)*/ "copystartleft", tr("> top"),
|
---|
436 | tr("Copy my selected nodes to the start of the merged node list"));
|
---|
437 | }
|
---|
438 |
|
---|
439 | @Override
|
---|
440 | public void actionPerformed(ActionEvent e) {
|
---|
441 | model.copyMyToTop(myEntriesTable.getSelectedRows());
|
---|
442 | }
|
---|
443 |
|
---|
444 | @Override
|
---|
445 | public void valueChanged(ListSelectionEvent e) {
|
---|
446 | setEnabled(!myEntriesTable.getSelectionModel().isSelectionEmpty());
|
---|
447 | }
|
---|
448 | }
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
452 | * nodes. Inserts the nodes at the end of the list of merged nodes.
|
---|
453 | */
|
---|
454 | class CopyEndLeftAction extends CopyAction {
|
---|
455 |
|
---|
456 | public CopyEndLeftAction() {
|
---|
457 | super(/* ICON(dialogs/conflict/)*/ "copyendleft", tr("> bottom"),
|
---|
458 | tr("Copy my selected elements to the end of the list of merged elements."));
|
---|
459 | }
|
---|
460 |
|
---|
461 | @Override
|
---|
462 | public void actionPerformed(ActionEvent e) {
|
---|
463 | model.copyMyToEnd(myEntriesTable.getSelectedRows());
|
---|
464 | }
|
---|
465 |
|
---|
466 | @Override
|
---|
467 | public void valueChanged(ListSelectionEvent e) {
|
---|
468 | setEnabled(!myEntriesTable.getSelectionModel().isSelectionEmpty());
|
---|
469 | }
|
---|
470 | }
|
---|
471 |
|
---|
472 | /**
|
---|
473 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
474 | * nodes. Inserts the nodes before the first selected row in the list of merged nodes.
|
---|
475 | */
|
---|
476 | class CopyBeforeCurrentLeftAction extends CopyAction {
|
---|
477 |
|
---|
478 | public CopyBeforeCurrentLeftAction() {
|
---|
479 | super(/* ICON(dialogs/conflict/)*/ "copybeforecurrentleft", tr("> before"),
|
---|
480 | tr("Copy my selected elements before the first selected element in the list of merged elements."));
|
---|
481 | }
|
---|
482 |
|
---|
483 | @Override
|
---|
484 | public void actionPerformed(ActionEvent e) {
|
---|
485 | int[] mergedRows = mergedEntriesTable.getSelectedRows();
|
---|
486 | if (mergedRows == null || mergedRows.length == 0)
|
---|
487 | return;
|
---|
488 | int[] myRows = myEntriesTable.getSelectedRows();
|
---|
489 | int current = mergedRows[0];
|
---|
490 | model.copyMyBeforeCurrent(myRows, current);
|
---|
491 | }
|
---|
492 |
|
---|
493 | @Override
|
---|
494 | public void valueChanged(ListSelectionEvent e) {
|
---|
495 | setEnabled(
|
---|
496 | !myEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
497 | && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
498 | );
|
---|
499 | }
|
---|
500 | }
|
---|
501 |
|
---|
502 | /**
|
---|
503 | * Action for copying selected nodes in the list of my nodes to the list of merged
|
---|
504 | * nodes. Inserts the nodes after the first selected row in the list of merged nodes.
|
---|
505 | */
|
---|
506 | class CopyAfterCurrentLeftAction extends CopyAction {
|
---|
507 |
|
---|
508 | public CopyAfterCurrentLeftAction() {
|
---|
509 | super(/* ICON(dialogs/conflict/)*/ "copyaftercurrentleft", tr("> after"),
|
---|
510 | tr("Copy my selected elements after the first selected element in the list of merged elements."));
|
---|
511 | }
|
---|
512 |
|
---|
513 | @Override
|
---|
514 | public void actionPerformed(ActionEvent e) {
|
---|
515 | int[] mergedRows = mergedEntriesTable.getSelectedRows();
|
---|
516 | if (mergedRows == null || mergedRows.length == 0)
|
---|
517 | return;
|
---|
518 | int[] myRows = myEntriesTable.getSelectedRows();
|
---|
519 | int current = mergedRows[0];
|
---|
520 | model.copyMyAfterCurrent(myRows, current);
|
---|
521 | }
|
---|
522 |
|
---|
523 | @Override
|
---|
524 | public void valueChanged(ListSelectionEvent e) {
|
---|
525 | setEnabled(
|
---|
526 | !myEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
527 | && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
528 | );
|
---|
529 | }
|
---|
530 | }
|
---|
531 |
|
---|
532 | class CopyStartRightAction extends CopyAction {
|
---|
533 |
|
---|
534 | public CopyStartRightAction() {
|
---|
535 | super(/* ICON(dialogs/conflict/)*/ "copystartright", tr("< top"),
|
---|
536 | tr("Copy their selected element to the start of the list of merged elements."));
|
---|
537 | }
|
---|
538 |
|
---|
539 | @Override
|
---|
540 | public void actionPerformed(ActionEvent e) {
|
---|
541 | model.copyTheirToTop(theirEntriesTable.getSelectedRows());
|
---|
542 | }
|
---|
543 |
|
---|
544 | @Override
|
---|
545 | public void valueChanged(ListSelectionEvent e) {
|
---|
546 | setEnabled(!theirEntriesTable.getSelectionModel().isSelectionEmpty());
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | class CopyEndRightAction extends CopyAction {
|
---|
551 |
|
---|
552 | public CopyEndRightAction() {
|
---|
553 | super(/* ICON(dialogs/conflict/)*/ "copyendright", tr("< bottom"),
|
---|
554 | tr("Copy their selected elements to the end of the list of merged elements."));
|
---|
555 | }
|
---|
556 |
|
---|
557 | @Override
|
---|
558 | public void actionPerformed(ActionEvent arg0) {
|
---|
559 | model.copyTheirToEnd(theirEntriesTable.getSelectedRows());
|
---|
560 | }
|
---|
561 |
|
---|
562 | @Override
|
---|
563 | public void valueChanged(ListSelectionEvent e) {
|
---|
564 | setEnabled(!theirEntriesTable.getSelectionModel().isSelectionEmpty());
|
---|
565 | }
|
---|
566 | }
|
---|
567 |
|
---|
568 | class CopyBeforeCurrentRightAction extends CopyAction {
|
---|
569 |
|
---|
570 | public CopyBeforeCurrentRightAction() {
|
---|
571 | super(/* ICON(dialogs/conflict/)*/ "copybeforecurrentright", tr("< before"),
|
---|
572 | tr("Copy their selected elements before the first selected element in the list of merged elements."));
|
---|
573 | }
|
---|
574 |
|
---|
575 | @Override
|
---|
576 | public void actionPerformed(ActionEvent e) {
|
---|
577 | int[] mergedRows = mergedEntriesTable.getSelectedRows();
|
---|
578 | if (mergedRows == null || mergedRows.length == 0)
|
---|
579 | return;
|
---|
580 | int[] myRows = theirEntriesTable.getSelectedRows();
|
---|
581 | int current = mergedRows[0];
|
---|
582 | model.copyTheirBeforeCurrent(myRows, current);
|
---|
583 | }
|
---|
584 |
|
---|
585 | @Override
|
---|
586 | public void valueChanged(ListSelectionEvent e) {
|
---|
587 | setEnabled(
|
---|
588 | !theirEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
589 | && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
590 | );
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|
594 | class CopyAfterCurrentRightAction extends CopyAction {
|
---|
595 |
|
---|
596 | public CopyAfterCurrentRightAction() {
|
---|
597 | super(/* ICON(dialogs/conflict/)*/ "copyaftercurrentright", tr("< after"),
|
---|
598 | tr("Copy their selected element after the first selected element in the list of merged elements"));
|
---|
599 | }
|
---|
600 |
|
---|
601 | @Override
|
---|
602 | public void actionPerformed(ActionEvent e) {
|
---|
603 | int[] mergedRows = mergedEntriesTable.getSelectedRows();
|
---|
604 | if (mergedRows == null || mergedRows.length == 0)
|
---|
605 | return;
|
---|
606 | int[] myRows = theirEntriesTable.getSelectedRows();
|
---|
607 | int current = mergedRows[0];
|
---|
608 | model.copyTheirAfterCurrent(myRows, current);
|
---|
609 | }
|
---|
610 |
|
---|
611 | @Override
|
---|
612 | public void valueChanged(ListSelectionEvent e) {
|
---|
613 | setEnabled(
|
---|
614 | !theirEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
615 | && !mergedEntriesTable.getSelectionModel().isSelectionEmpty()
|
---|
616 | );
|
---|
617 | }
|
---|
618 | }
|
---|
619 |
|
---|
620 | class CopyAllLeft extends AbstractAction implements Observer, PropertyChangeListener {
|
---|
621 |
|
---|
622 | public CopyAllLeft() {
|
---|
623 | ImageIcon icon = ImageProvider.get("dialogs/conflict", "useallleft");
|
---|
624 | putValue(Action.SMALL_ICON, icon);
|
---|
625 | putValue(Action.SHORT_DESCRIPTION, tr("Copy all my elements to the target"));
|
---|
626 | }
|
---|
627 |
|
---|
628 | @Override
|
---|
629 | public void actionPerformed(ActionEvent arg0) {
|
---|
630 | model.copyAll(ListRole.MY_ENTRIES);
|
---|
631 | model.setFrozen(true);
|
---|
632 | }
|
---|
633 |
|
---|
634 | private void updateEnabledState() {
|
---|
635 | setEnabled(model.getMergedEntries().isEmpty() && !model.isFrozen());
|
---|
636 | }
|
---|
637 |
|
---|
638 | @Override
|
---|
639 | public void update(Observable o, Object arg) {
|
---|
640 | updateEnabledState();
|
---|
641 | }
|
---|
642 |
|
---|
643 | @Override
|
---|
644 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
645 | updateEnabledState();
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 | class CopyAllRight extends AbstractAction implements Observer, PropertyChangeListener {
|
---|
650 |
|
---|
651 | public CopyAllRight() {
|
---|
652 | ImageIcon icon = ImageProvider.get("dialogs/conflict", "useallright");
|
---|
653 | putValue(Action.SMALL_ICON, icon);
|
---|
654 | putValue(Action.SHORT_DESCRIPTION, tr("Copy all their elements to the target"));
|
---|
655 | }
|
---|
656 |
|
---|
657 | @Override
|
---|
658 | public void actionPerformed(ActionEvent arg0) {
|
---|
659 | model.copyAll(ListRole.THEIR_ENTRIES);
|
---|
660 | model.setFrozen(true);
|
---|
661 | }
|
---|
662 |
|
---|
663 | private void updateEnabledState() {
|
---|
664 | setEnabled(model.getMergedEntries().isEmpty() && !model.isFrozen());
|
---|
665 | }
|
---|
666 |
|
---|
667 | @Override
|
---|
668 | public void update(Observable o, Object arg) {
|
---|
669 | updateEnabledState();
|
---|
670 | }
|
---|
671 |
|
---|
672 | @Override
|
---|
673 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
674 | updateEnabledState();
|
---|
675 | }
|
---|
676 | }
|
---|
677 |
|
---|
678 | class MoveUpMergedAction extends AbstractAction implements ListSelectionListener {
|
---|
679 |
|
---|
680 | public MoveUpMergedAction() {
|
---|
681 | ImageIcon icon = ImageProvider.get("dialogs/conflict", "moveup");
|
---|
682 | putValue(Action.SMALL_ICON, icon);
|
---|
683 | if (icon == null) {
|
---|
684 | putValue(Action.NAME, tr("Up"));
|
---|
685 | }
|
---|
686 | putValue(Action.SHORT_DESCRIPTION, tr("Move up the selected entries by one position."));
|
---|
687 | setEnabled(false);
|
---|
688 | }
|
---|
689 |
|
---|
690 | @Override
|
---|
691 | public void actionPerformed(ActionEvent arg0) {
|
---|
692 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
693 | model.moveUpMerged(rows);
|
---|
694 | }
|
---|
695 |
|
---|
696 | @Override
|
---|
697 | public void valueChanged(ListSelectionEvent e) {
|
---|
698 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
699 | setEnabled(
|
---|
700 | rows != null
|
---|
701 | && rows.length > 0
|
---|
702 | && rows[0] != 0
|
---|
703 | );
|
---|
704 | }
|
---|
705 | }
|
---|
706 |
|
---|
707 | /**
|
---|
708 | * Action for moving the currently selected entries in the list of merged entries
|
---|
709 | * one position down
|
---|
710 | *
|
---|
711 | */
|
---|
712 | class MoveDownMergedAction extends AbstractAction implements ListSelectionListener {
|
---|
713 |
|
---|
714 | public MoveDownMergedAction() {
|
---|
715 | ImageIcon icon = ImageProvider.get("dialogs/conflict", "movedown");
|
---|
716 | putValue(Action.SMALL_ICON, icon);
|
---|
717 | if (icon == null) {
|
---|
718 | putValue(Action.NAME, tr("Down"));
|
---|
719 | }
|
---|
720 | putValue(Action.SHORT_DESCRIPTION, tr("Move down the selected entries by one position."));
|
---|
721 | setEnabled(false);
|
---|
722 | }
|
---|
723 |
|
---|
724 | @Override
|
---|
725 | public void actionPerformed(ActionEvent arg0) {
|
---|
726 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
727 | model.moveDownMerged(rows);
|
---|
728 | }
|
---|
729 |
|
---|
730 | @Override
|
---|
731 | public void valueChanged(ListSelectionEvent e) {
|
---|
732 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
733 | setEnabled(
|
---|
734 | rows != null
|
---|
735 | && rows.length > 0
|
---|
736 | && rows[rows.length -1] != mergedEntriesTable.getRowCount() -1
|
---|
737 | );
|
---|
738 | }
|
---|
739 | }
|
---|
740 |
|
---|
741 | /**
|
---|
742 | * Action for removing the selected entries in the list of merged entries
|
---|
743 | * from the list of merged entries.
|
---|
744 | *
|
---|
745 | */
|
---|
746 | class RemoveMergedAction extends AbstractAction implements ListSelectionListener {
|
---|
747 |
|
---|
748 | public RemoveMergedAction() {
|
---|
749 | ImageIcon icon = ImageProvider.get("dialogs/conflict", "remove");
|
---|
750 | putValue(Action.SMALL_ICON, icon);
|
---|
751 | if (icon == null) {
|
---|
752 | putValue(Action.NAME, tr("Remove"));
|
---|
753 | }
|
---|
754 | putValue(Action.SHORT_DESCRIPTION, tr("Remove the selected entries from the list of merged elements."));
|
---|
755 | setEnabled(false);
|
---|
756 | }
|
---|
757 |
|
---|
758 | @Override
|
---|
759 | public void actionPerformed(ActionEvent arg0) {
|
---|
760 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
761 | model.removeMerged(rows);
|
---|
762 | }
|
---|
763 |
|
---|
764 | @Override
|
---|
765 | public void valueChanged(ListSelectionEvent e) {
|
---|
766 | int[] rows = mergedEntriesTable.getSelectedRows();
|
---|
767 | setEnabled(
|
---|
768 | rows != null
|
---|
769 | && rows.length > 0
|
---|
770 | );
|
---|
771 | }
|
---|
772 | }
|
---|
773 |
|
---|
774 | private static interface FreezeActionProperties {
|
---|
775 | String PROP_SELECTED = FreezeActionProperties.class.getName() + ".selected";
|
---|
776 | }
|
---|
777 |
|
---|
778 | /**
|
---|
779 | * Action for freezing the current state of the list merger
|
---|
780 | *
|
---|
781 | */
|
---|
782 | private final class FreezeAction extends AbstractAction implements ItemListener, FreezeActionProperties {
|
---|
783 |
|
---|
784 | private FreezeAction() {
|
---|
785 | putValue(Action.NAME, tr("Freeze"));
|
---|
786 | putValue(Action.SHORT_DESCRIPTION, tr("Freeze the current list of merged elements."));
|
---|
787 | putValue(PROP_SELECTED, Boolean.FALSE);
|
---|
788 | setEnabled(true);
|
---|
789 | }
|
---|
790 |
|
---|
791 | @Override
|
---|
792 | public void actionPerformed(ActionEvent arg0) {
|
---|
793 | // do nothing
|
---|
794 | }
|
---|
795 |
|
---|
796 | /**
|
---|
797 | * Java 1.5 doesn't known Action.SELECT_KEY. Wires a toggle button to this action
|
---|
798 | * such that the action gets notified about item state changes and the button gets
|
---|
799 | * notified about selection state changes of the action.
|
---|
800 | *
|
---|
801 | * @param btn a toggle button
|
---|
802 | */
|
---|
803 | public void adapt(final JToggleButton btn) {
|
---|
804 | btn.addItemListener(this);
|
---|
805 | addPropertyChangeListener(
|
---|
806 | new PropertyChangeListener() {
|
---|
807 | @Override
|
---|
808 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
809 | if (evt.getPropertyName().equals(PROP_SELECTED)) {
|
---|
810 | btn.setSelected((Boolean)evt.getNewValue());
|
---|
811 | }
|
---|
812 | }
|
---|
813 | }
|
---|
814 | );
|
---|
815 | }
|
---|
816 |
|
---|
817 | @Override
|
---|
818 | public void itemStateChanged(ItemEvent e) {
|
---|
819 | int state = e.getStateChange();
|
---|
820 | if (state == ItemEvent.SELECTED) {
|
---|
821 | putValue(Action.NAME, tr("Unfreeze"));
|
---|
822 | putValue(Action.SHORT_DESCRIPTION, tr("Unfreeze the list of merged elements and start merging."));
|
---|
823 | model.setFrozen(true);
|
---|
824 | } else if (state == ItemEvent.DESELECTED) {
|
---|
825 | putValue(Action.NAME, tr("Freeze"));
|
---|
826 | putValue(Action.SHORT_DESCRIPTION, tr("Freeze the current list of merged elements."));
|
---|
827 | model.setFrozen(false);
|
---|
828 | }
|
---|
829 | boolean isSelected = (Boolean)getValue(PROP_SELECTED);
|
---|
830 | if (isSelected != (e.getStateChange() == ItemEvent.SELECTED)) {
|
---|
831 | putValue(PROP_SELECTED, e.getStateChange() == ItemEvent.SELECTED);
|
---|
832 | }
|
---|
833 |
|
---|
834 | }
|
---|
835 | }
|
---|
836 |
|
---|
837 | protected void handlePropertyChangeFrozen(boolean oldValue, boolean newValue) {
|
---|
838 | myEntriesTable.getSelectionModel().clearSelection();
|
---|
839 | myEntriesTable.setEnabled(!newValue);
|
---|
840 | theirEntriesTable.getSelectionModel().clearSelection();
|
---|
841 | theirEntriesTable.setEnabled(!newValue);
|
---|
842 | mergedEntriesTable.getSelectionModel().clearSelection();
|
---|
843 | mergedEntriesTable.setEnabled(!newValue);
|
---|
844 | freezeAction.putValue(FreezeActionProperties.PROP_SELECTED, newValue);
|
---|
845 | if (newValue) {
|
---|
846 | lblFrozenState.setText(
|
---|
847 | tr("<html>Click <strong>{0}</strong> to start merging my and their entries.</html>",
|
---|
848 | freezeAction.getValue(Action.NAME))
|
---|
849 | );
|
---|
850 | } else {
|
---|
851 | lblFrozenState.setText(
|
---|
852 | tr("<html>Click <strong>{0}</strong> to finish merging my and their entries.</html>",
|
---|
853 | freezeAction.getValue(Action.NAME))
|
---|
854 | );
|
---|
855 | }
|
---|
856 | }
|
---|
857 |
|
---|
858 | @Override
|
---|
859 | public void propertyChange(PropertyChangeEvent evt) {
|
---|
860 | if (evt.getPropertyName().equals(ListMergeModel.FROZEN_PROP)) {
|
---|
861 | handlePropertyChangeFrozen((Boolean)evt.getOldValue(), (Boolean)evt.getNewValue());
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | public ListMergeModel<T> getModel() {
|
---|
866 | return model;
|
---|
867 | }
|
---|
868 |
|
---|
869 | @Override
|
---|
870 | public void update(Observable o, Object arg) {
|
---|
871 | lblMyVersion.setText(
|
---|
872 | trn("My version ({0} entry)", "My version ({0} entries)", model.getMyEntriesSize(), model.getMyEntriesSize())
|
---|
873 | );
|
---|
874 | lblMergedVersion.setText(
|
---|
875 | trn("Merged version ({0} entry)", "Merged version ({0} entries)", model.getMergedEntriesSize(), model.getMergedEntriesSize())
|
---|
876 | );
|
---|
877 | lblTheirVersion.setText(
|
---|
878 | trn("Their version ({0} entry)", "Their version ({0} entries)", model.getTheirEntriesSize(), model.getTheirEntriesSize())
|
---|
879 | );
|
---|
880 | }
|
---|
881 |
|
---|
882 | public void unlinkAsListener() {
|
---|
883 | myEntriesTable.unlinkAsListener();
|
---|
884 | mergedEntriesTable.unlinkAsListener();
|
---|
885 | theirEntriesTable.unlinkAsListener();
|
---|
886 | }
|
---|
887 |
|
---|
888 | protected final <P extends OsmPrimitive> OsmDataLayer findLayerFor(P primitive) {
|
---|
889 | if (primitive != null) {
|
---|
890 | Iterable<OsmDataLayer> layers = Main.map.mapView.getLayersOfType(OsmDataLayer.class);
|
---|
891 | // Find layer with same dataset
|
---|
892 | for (OsmDataLayer layer : layers) {
|
---|
893 | if (layer.data == primitive.getDataSet()) {
|
---|
894 | return layer;
|
---|
895 | }
|
---|
896 | }
|
---|
897 | // Conflict after merging layers: a dataset could be no more in any layer, try to find another layer with same primitive
|
---|
898 | for (OsmDataLayer layer : layers) {
|
---|
899 | final Collection<? extends OsmPrimitive> collection;
|
---|
900 | if (primitive instanceof Way) {
|
---|
901 | collection = layer.data.getWays();
|
---|
902 | } else if (primitive instanceof Relation) {
|
---|
903 | collection = layer.data.getRelations();
|
---|
904 | } else {
|
---|
905 | collection = layer.data.allPrimitives();
|
---|
906 | }
|
---|
907 | for (OsmPrimitive p : collection) {
|
---|
908 | if (p.getPrimitiveId().equals(primitive.getPrimitiveId())) {
|
---|
909 | return layer;
|
---|
910 | }
|
---|
911 | }
|
---|
912 | }
|
---|
913 | }
|
---|
914 | return null;
|
---|
915 | }
|
---|
916 | }
|
---|