Changeset 9440 in josm


Ignore:
Timestamp:
2016-01-14T16:42:50+01:00 (4 years ago)
Author:
simon04
Message:

see #12338 - Conflict resolution: add expert actions "Resolve to my/their versions" in popup menu

This resolves all selected conflicts to my/their versions.

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ConflictResolver.java

    r8840 r9440  
    347347        relationMemberMerger.unlinkAsListener();
    348348    }
     349
     350    public void decideRemaining(MergeDecisionType decision) {
     351        propertiesMerger.decideRemaining(decision);
     352        tagMerger.decideRemaining(decision);
     353        if (my instanceof Way) {
     354            nodeListMerger.decideRemaining(decision);
     355        } else if (my instanceof Relation) {
     356            relationMemberMerger.decideRemaining(decision);
     357        }
     358        updateResolvedCompletely();
     359        if (!isResolvedCompletely()) {
     360            throw new AssertionError();
     361        }
     362    }
    349363}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/IConflictResolver.java

    r8510 r9440  
    1010
    1111    void populate(Conflict<? extends OsmPrimitive> conflict);
     12
     13    void decideRemaining(MergeDecisionType decision);
    1214}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMerger.java

    r8836 r9440  
    917917        return null;
    918918    }
     919
     920    public void decideRemaining(MergeDecisionType decision) {
     921        if (!model.isFrozen()) {
     922            model.copyAll(MergeDecisionType.KEEP_MINE.equals(decision) ? ListRole.MY_ENTRIES : ListRole.THEIR_ENTRIES);
     923        }
     924    }
    919925}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java

    r8836 r9440  
    508508        model.populate(conflict);
    509509    }
     510
     511    @Override
     512    public void decideRemaining(MergeDecisionType decision) {
     513        if (!model.isDecidedCoord()) {
     514            model.decideDeletedStateConflict(decision);
     515        }
     516        if (!model.isDecidedCoord()) {
     517            model.decideCoordsConflict(decision);
     518        }
     519    }
    510520}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMergeModel.java

    r8840 r9440  
    202202    }
    203203
     204    public void decideRemaining(MergeDecisionType decision) {
     205        for (TagMergeItem item: tagMergeItems) {
     206            if (item.getMergeDecision().equals(MergeDecisionType.UNDECIDED))
     207                item.decide(decision);
     208        }
     209    }
     210
    204211    public int getNumResolvedConflicts() {
    205212        int n = 0;
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMerger.java

    r8836 r9440  
    443443        }
    444444    }
     445
     446    @Override
     447    public void decideRemaining(MergeDecisionType decision) {
     448        model.decideRemaining(decision);
     449    }
    445450}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r9059 r9440  
    1313import java.awt.event.KeyEvent;
    1414import java.awt.event.MouseEvent;
     15import java.util.ArrayList;
    1516import java.util.Arrays;
    1617import java.util.Collection;
    1718import java.util.HashSet;
    1819import java.util.LinkedList;
     20import java.util.List;
    1921import java.util.Set;
    2022import java.util.concurrent.CopyOnWriteArrayList;
     
    2224import javax.swing.AbstractAction;
    2325import javax.swing.JList;
     26import javax.swing.JMenuItem;
    2427import javax.swing.JOptionPane;
    2528import javax.swing.JPopupMenu;
     
    3033import javax.swing.event.ListSelectionEvent;
    3134import javax.swing.event.ListSelectionListener;
     35import javax.swing.event.PopupMenuEvent;
     36import javax.swing.event.PopupMenuListener;
    3237
    3338import org.openstreetmap.josm.Main;
    3439import org.openstreetmap.josm.actions.AbstractSelectAction;
     40import org.openstreetmap.josm.actions.ExpertToggleAction;
     41import org.openstreetmap.josm.command.Command;
     42import org.openstreetmap.josm.command.SequenceCommand;
    3543import org.openstreetmap.josm.data.SelectionChangedListener;
    3644import org.openstreetmap.josm.data.conflict.Conflict;
     
    5260import org.openstreetmap.josm.gui.PopupMenuHandler;
    5361import org.openstreetmap.josm.gui.SideButton;
     62import org.openstreetmap.josm.gui.conflict.pair.ConflictResolver;
     63import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    5464import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5565import org.openstreetmap.josm.gui.util.GuiHelper;
     
    118128
    119129        popupMenuHandler.addAction(Main.main.menu.autoScaleActions.get("conflict"));
     130
     131        final ResolveTpMyVersionAction resolveTpMyVersionAction = new ResolveTpMyVersionAction();
     132        final ResolveToTheirVersionAction resolveToTheirVersionAction = new ResolveToTheirVersionAction();
     133        addListSelectionListener(resolveTpMyVersionAction);
     134        addListSelectionListener(resolveToTheirVersionAction);
     135        final JMenuItem btnResolveMy = popupMenuHandler.addAction(resolveTpMyVersionAction);
     136        final JMenuItem btnResolveTheir = popupMenuHandler.addAction(resolveToTheirVersionAction);
     137
     138        popupMenuHandler.addListener(new PopupMenuListener() {
     139            @Override
     140            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     141                btnResolveMy.setVisible(ExpertToggleAction.isExpert());
     142                btnResolveTheir.setVisible(ExpertToggleAction.isExpert());
     143            }
     144
     145            @Override
     146            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
     147                // Do nothing
     148            }
     149
     150            @Override
     151            public void popupMenuCanceled(PopupMenuEvent e) {
     152                // Do nothing
     153            }
     154        });
    120155    }
    121156
     
    319354    }
    320355
     356    private boolean isConflictSelected() {
     357        final ListSelectionModel model = lstConflicts.getSelectionModel();
     358        return model.getMinSelectionIndex() >= 0 && model.getMaxSelectionIndex() >= model.getMinSelectionIndex();
     359    }
     360
    321361    @Override
    322362    public void onConflictsAdded(ConflictCollection conflicts) {
     
    445485        @Override
    446486        public void valueChanged(ListSelectionEvent e) {
    447             ListSelectionModel model = (ListSelectionModel) e.getSource();
    448             boolean enabled = model.getMinSelectionIndex() >= 0
    449             && model.getMaxSelectionIndex() >= model.getMinSelectionIndex();
    450             setEnabled(enabled);
     487            setEnabled(isConflictSelected());
    451488        }
    452489    }
     
    471508        @Override
    472509        public void valueChanged(ListSelectionEvent e) {
    473             ListSelectionModel model = (ListSelectionModel) e.getSource();
    474             boolean enabled = model.getMinSelectionIndex() >= 0
    475             && model.getMaxSelectionIndex() >= model.getMinSelectionIndex();
    476             setEnabled(enabled);
     510            setEnabled(isConflictSelected());
     511        }
     512    }
     513
     514    abstract class ResolveToAction extends ResolveAction {
     515        private final String name;
     516        private final MergeDecisionType type;
     517
     518        ResolveToAction(String name, String description, MergeDecisionType type) {
     519            this.name = name;
     520            this.type = type;
     521            putValue(NAME, name);
     522            putValue(SHORT_DESCRIPTION,  description);
     523        }
     524
     525        @Override
     526        public void actionPerformed(ActionEvent e) {
     527            final ConflictResolver resolver = new ConflictResolver();
     528            final List<Command> commands = new ArrayList<>();
     529            for (OsmPrimitive osmPrimitive : lstConflicts.getSelectedValuesList()) {
     530                Conflict<? extends OsmPrimitive> c = conflicts.getConflictForMy(osmPrimitive);
     531                resolver.populate(c);
     532                resolver.decideRemaining(type);
     533                commands.add(resolver.buildResolveCommand());
     534            }
     535            Main.main.undoRedo.add(new SequenceCommand(name, commands));
     536            refreshView();
     537            Main.map.mapView.repaint();
     538        }
     539    }
     540
     541    class ResolveTpMyVersionAction extends ResolveToAction {
     542        public ResolveTpMyVersionAction() {
     543            super(tr("Resolve to my versions"), tr("Resolves all unresolved conflicts to ''my'' version"),
     544                    MergeDecisionType.KEEP_MINE);
     545        }
     546    }
     547
     548    class ResolveToTheirVersionAction extends ResolveToAction {
     549        public ResolveToTheirVersionAction() {
     550            super(tr("Resolve to their versions"), tr("Resolves all unresolved conflicts to ''their'' version"),
     551                    MergeDecisionType.KEEP_THEIR);
    477552        }
    478553    }
Note: See TracChangeset for help on using the changeset viewer.