Changeset 12352 in josm


Ignore:
Timestamp:
2017-06-09T00:14:12+02:00 (17 months ago)
Author:
michael2402
Message:

Use new selection interface in ConflictDialog

The dialog is now not confused by any selection changes that happen in the non-edit layers (e.g. because of undo)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r12279 r12352  
    4141import org.openstreetmap.josm.command.Command;
    4242import org.openstreetmap.josm.command.SequenceCommand;
    43 import org.openstreetmap.josm.data.SelectionChangedListener;
    4443import org.openstreetmap.josm.data.conflict.Conflict;
    4544import org.openstreetmap.josm.data.conflict.ConflictCollection;
    4645import org.openstreetmap.josm.data.conflict.IConflictListener;
     46import org.openstreetmap.josm.data.osm.DataSelectionListener;
    4747import org.openstreetmap.josm.data.osm.DataSet;
    4848import org.openstreetmap.josm.data.osm.Node;
     
    7575 * @since 86
    7676 */
    77 public final class ConflictDialog extends ToggleDialog implements ActiveLayerChangeListener, IConflictListener, SelectionChangedListener {
     77public final class ConflictDialog extends ToggleDialog implements ActiveLayerChangeListener, IConflictListener, DataSelectionListener {
    7878
    7979    private static final ColorProperty CONFLICT_COLOR = new ColorProperty(marktr("conflict"), Color.GRAY);
     
    151151    @Override
    152152    public void showNotify() {
    153         DataSet.addSelectionListener(this);
    154153        Main.getLayerManager().addAndFireActiveLayerChangeListener(this);
    155154        refreshView();
     
    159158    public void hideNotify() {
    160159        Main.getLayerManager().removeActiveLayerChangeListener(this);
    161         DataSet.removeSelectionListener(this);
     160        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
     161        removeEditLayerListeners(editLayer);
    162162    }
    163163
     
    259259    @Override
    260260    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    261         OsmDataLayer oldLayer = e.getPreviousEditLayer();
     261        removeEditLayerListeners(e.getPreviousEditLayer());
     262        addEditLayerListeners(e.getSource().getEditLayer());
     263        refreshView();
     264    }
     265
     266    private void addEditLayerListeners(OsmDataLayer newLayer) {
     267        if (newLayer != null) {
     268            newLayer.getConflicts().addConflictListener(this);
     269            newLayer.data.addSelectionListener(this);
     270        }
     271    }
     272
     273    private void removeEditLayerListeners(OsmDataLayer oldLayer) {
    262274        if (oldLayer != null) {
    263275            oldLayer.getConflicts().removeConflictListener(this);
    264         }
    265         OsmDataLayer newLayer = e.getSource().getEditLayer();
    266         if (newLayer != null) {
    267             newLayer.getConflicts().addConflictListener(this);
    268         }
    269         refreshView();
     276            oldLayer.data.removeSelectionListener(this);
     277        }
    270278    }
    271279
     
    310318
    311319    @Override
    312     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     320    public void selectionChanged(SelectionChangeEvent event) {
    313321        lstConflicts.setValueIsAdjusting(true);
    314322        lstConflicts.clearSelection();
    315         for (OsmPrimitive osm : newSelection) {
     323        for (OsmPrimitive osm : event.getSelection()) {
    316324            if (conflicts != null && conflicts.hasConflictForMy(osm)) {
    317325                int pos = model.indexOf(osm);
Note: See TracChangeset for help on using the changeset viewer.