Changeset 1904 in josm


Ignore:
Timestamp:
2009-08-04T09:32:43+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3141: conflict resolution: "apply partial resolution" doesn't work

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

Legend:

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

    r1690 r1904  
    77import java.beans.PropertyChangeEvent;
    88import java.beans.PropertyChangeListener;
     9import java.beans.PropertyChangeSupport;
    910import java.util.ArrayList;
    1011import java.util.logging.Logger;
     
    3536 * An UI component for resolving conflicts between two {@see OsmPrimitive}s.
    3637 *
     38 * This component emits {@see PropertyChangeEvent}s for three properties:
     39 * <ul>
     40 *   <li>{@see #RESOLVED_COMPLETELY_PROP} - new value is <code>true</code>, if the conflict is
     41 *   completely resolved</li>
     42 *   <li>{@see #MY_PRIMITIVE_PROP} - new value is the {@see OsmPrimitive} in the role of
     43 *   my primitive</li>
     44 *   <li>{@see #THEIR_PRIMITIVE_PROP} - new value is the {@see OsmPrimitive} in the role of
     45 *   their primitive</li>
     46 * </ul>
     47 *
    3748 */
    3849public class ConflictResolver extends JPanel implements PropertyChangeListener  {
     50    static public final String RESOLVED_COMPLETELY_PROP = ConflictResolver.class.getName() + ".resolvedCompletely";
     51    static public final String MY_PRIMITIVE_PROP = ConflictResolver.class.getName() + ".myPrimitive";
     52    static public final String THEIR_PRIMITIVE_PROP = ConflictResolver.class.getName() + ".theirPrimitive";
     53
    3954
    4055    private static final Logger logger = Logger.getLogger(ConflictResolver.class.getName());
     
    5166    private ImageIcon mergeIncomplete;
    5267
     68    /** the property change listeners */
     69    private PropertyChangeSupport listeners;
     70
     71    /** indicates whether the current conflict is resolved completely */
     72    private boolean resolvedCompletely;
     73
    5374    protected void loadIcons() {
    5475        mergeComplete = ImageProvider.get("dialogs/conflict","mergecomplete.png" );
     
    83104    }
    84105
     106
    85107    public ConflictResolver() {
     108        listeners = new PropertyChangeSupport(this);
     109        resolvedCompletely = false;
    86110        build();
    87111        loadIcons();
     112    }
     113
     114
     115    protected void setMy(OsmPrimitive my) {
     116        OsmPrimitive old = this.my;
     117        this.my = my;
     118        if (old != this.my) {
     119            fireMyPrimitive(old, this.my);
     120        }
     121    }
     122
     123    protected void setTheir(OsmPrimitive their) {
     124        OsmPrimitive old = this.their;
     125        this.their = their;
     126        if (old != this.their) {
     127            fireTheirPrimitive(old, this.their);
     128        }
     129    }
     130
     131    protected void fireResolvedCompletely(boolean oldValue,boolean newValue) {
     132        if (listeners == null) return;
     133        listeners.firePropertyChange(RESOLVED_COMPLETELY_PROP, oldValue, newValue);
     134    }
     135
     136    protected void fireMyPrimitive(OsmPrimitive oldValue,OsmPrimitive newValue) {
     137        if (listeners == null) return;
     138        listeners.firePropertyChange(MY_PRIMITIVE_PROP, oldValue, newValue);
     139    }
     140
     141    protected void fireTheirPrimitive(OsmPrimitive oldValue,OsmPrimitive newValue) {
     142        if (listeners == null) return;
     143        listeners.firePropertyChange(THEIR_PRIMITIVE_PROP, oldValue, newValue);
     144    }
     145
     146    /**
     147     * Adds a property change listener
     148     *
     149     *  @param listener the listener
     150     */
     151    @Override
     152    public void addPropertyChangeListener(PropertyChangeListener listener) {
     153        listeners.addPropertyChangeListener(listener);
     154    }
     155
     156    /**
     157     * Removes a property change listener
     158     *
     159     *  @param listener the listener
     160     */
     161
     162    @Override
     163    public void removePropertyChangeListener(PropertyChangeListener listener) {
     164        listeners.removePropertyChangeListener(listener);
    88165    }
    89166
     
    100177                tabbedPane.setIconAt(1, mergeIncomplete);
    101178            }
     179            updateResolvedCompletely();
    102180        } else if (evt.getPropertyName().equals(ListMergeModel.FROZEN_PROP)) {
    103181            boolean frozen = (Boolean)evt.getNewValue();
     
    120198                tabbedPane.setIconAt(3, mergeIncomplete);
    121199            }
     200            updateResolvedCompletely();
    122201        } else if (evt.getPropertyName().equals(PropertiesMergeModel.RESOLVED_COMPLETELY_PROP)) {
    123202            boolean resolved = (Boolean)evt.getNewValue();
     
    131210                tabbedPane.setIconAt(0, mergeIncomplete);
    132211            }
     212            updateResolvedCompletely();
    133213        }
    134214    }
     
    143223     */
    144224    public void populate(OsmPrimitive my, OsmPrimitive their) {
    145         this.my = my;
    146         this.their =  their;
     225        setMy(my);
     226        setTheir(their);
    147227        propertiesMerger.getModel().populate(my, their);
    148228        if (propertiesMerger.getModel().hasVisibleStateConflict()) {
     
    172252            tabbedPane.setEnabledAt(3, true);
    173253        }
    174 
    175     }
    176 
    177     /**
    178      * Builds the resolution command(s) for for the resolved conflicts in this
     254        updateResolvedCompletely();
     255    }
     256
     257    /**
     258     * Builds the resolution command(s) for the resolved conflicts in this
    179259     * ConflictResolver
    180260     *
     
    208288    }
    209289
    210     public boolean isResolvedCompletely() {
     290    protected void updateResolvedCompletely() {
     291        boolean oldValueResolvedCompletely = resolvedCompletely;
    211292        if (my instanceof Node) {
    212293            // resolve the version conflict if this is a node and all tag
    213294            // conflicts have been resolved
    214295            //
    215             if (tagMerger.getModel().isResolvedCompletely()
    216                     && propertiesMerger.getModel().isResolvedCompletely())
    217                 return true;
     296            this.resolvedCompletely =
     297                tagMerger.getModel().isResolvedCompletely()
     298                && propertiesMerger.getModel().isResolvedCompletely();
    218299        } else if (my instanceof Way) {
    219300            // resolve the version conflict if this is a way, all tag
     
    221302            // have been resolved
    222303            //
    223             if (tagMerger.getModel().isResolvedCompletely()
    224                     &&  propertiesMerger.getModel().isResolvedCompletely()
    225                     && nodeListMerger.getModel().isFrozen())
    226                 return true;
     304            this.resolvedCompletely =
     305                tagMerger.getModel().isResolvedCompletely()
     306                &&  propertiesMerger.getModel().isResolvedCompletely()
     307                && nodeListMerger.getModel().isFrozen();
    227308        }  else if (my instanceof Relation) {
    228309            // resolve the version conflict if this is a relation, all tag
     
    230311            // have been resolved
    231312            //
    232             if (tagMerger.getModel().isResolvedCompletely()
    233                     &&  propertiesMerger.getModel().isResolvedCompletely()
    234                     && relationMemberMerger.getModel().isFrozen())
    235                 return true;
    236         }
    237         return false;
     313            this.resolvedCompletely =
     314                tagMerger.getModel().isResolvedCompletely()
     315                &&  propertiesMerger.getModel().isResolvedCompletely()
     316                && relationMemberMerger.getModel().isFrozen();
     317        }
     318        if (this.resolvedCompletely != oldValueResolvedCompletely) {
     319            fireResolvedCompletely(oldValueResolvedCompletely, this.resolvedCompletely);
     320        }
     321    }
     322
     323    /**
     324     * Replies true all differences in this conflicts are resolved
     325     *
     326     * @return true all differences in this conflicts are resolved
     327     */
     328    public boolean isResolvedCompletely() {
     329        return resolvedCompletely;
    238330    }
    239331}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java

    r1857 r1904  
    1010import java.awt.Point;
    1111import java.awt.event.ActionEvent;
     12import java.beans.PropertyChangeEvent;
     13import java.beans.PropertyChangeListener;
    1214import java.util.logging.Logger;
    1315
     
    2224import org.openstreetmap.josm.Main;
    2325import org.openstreetmap.josm.command.Command;
     26import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2427import org.openstreetmap.josm.gui.OptionPaneUtil;
     28import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
    2529import org.openstreetmap.josm.gui.conflict.ConflictResolver;
    2630import org.openstreetmap.josm.gui.conflict.properties.OperationCancelledException;
     
    2832
    2933/**
    30  * This is an extended dialog for resolving conflict between {@see OsmPrimitive}.
    31  *
     34 * This is an extended dialog for resolving conflict between {@see OsmPrimitive}s.
    3235 *
    3336 */
    34 public class ConflictResolutionDialog extends JDialog {
     37public class ConflictResolutionDialog extends JDialog implements PropertyChangeListener {
    3538    private static final Logger logger = Logger.getLogger(ConflictResolutionDialog.class.getName());
    3639    public final static Dimension DEFAULT_SIZE = new Dimension(600,400);
     
    114117        pnl.setLayout(new FlowLayout(FlowLayout.CENTER));
    115118
    116         JButton btn = new JButton(new ApplyResolutionAction());
     119        ApplyResolutionAction applyResolutionAction = new ApplyResolutionAction();
     120        resolver.addPropertyChangeListener(applyResolutionAction);
     121        JButton btn = new JButton(applyResolutionAction);
    117122        btn.setName("button.apply");
    118123        pnl.add(btn);
     
    130135     */
    131136    protected void build() {
    132         setTitle(tr("Resolve conflicts"));
     137        updateTitle();
    133138        try {
    134139            setAlwaysOnTop(true);
     
    142147        getContentPane().add(resolver, BorderLayout.CENTER);
    143148        getContentPane().add(buildButtonRow(), BorderLayout.SOUTH);
     149
     150        resolver.addPropertyChangeListener(this);
    144151    }
    145152
     
    154161    }
    155162
     163    /**
     164     * Action for canceling conflict resolution
     165     */
    156166    class CancelAction extends AbstractAction {
    157167        public CancelAction() {
     
    168178    }
    169179
    170     class ApplyResolutionAction extends AbstractAction {
     180    /**
     181     * Action for applying resolved differences in a conflict
     182     *
     183     */
     184    class ApplyResolutionAction extends AbstractAction implements PropertyChangeListener {
    171185        public ApplyResolutionAction() {
    172186            putValue(Action.SHORT_DESCRIPTION, tr("Apply resolved conflicts and close the dialog"));
    173187            putValue(Action.NAME, tr("Apply Resolution"));
    174188            putValue(Action.SMALL_ICON, ImageProvider.get("dialogs", "conflict"));
    175             setEnabled(true);
     189            updateEnabledState();
     190        }
     191
     192        protected void updateEnabledState() {
     193            setEnabled(resolver.isResolvedCompletely());
    176194        }
    177195
     
    179197            if (! resolver.isResolvedCompletely()) {
    180198                Object[] options = {
    181                         tr("Apply partial resolutions"),
     199                        tr("Close anyway"),
    182200                        tr("Continue resolving")};
    183                 int n = OptionPaneUtil.showOptionDialog(null,
    184                         tr("<html>You didn''t finish to resolve all conflicts.<br>"
    185                                 + "Click <strong>{0}</strong> to apply already resolved conflicts anyway.<br>"
    186                                 + "You can resolve the remaining conflicts later.<br>"
     201                int ret = OptionPaneUtil.showOptionDialog(Main.parent,
     202                        tr("<html>You didn''t finish to merge the differences in this conflict.<br>"
     203                                + "Conflict resolutions won't be applied unless all differences<br>"
     204                                + "are resolved."
     205                                + "Click <strong>{0}</strong> to close anyway.<strong>Already<br>"
     206                                + "resolved differences won't be applied.</strong><br>"
    187207                                + "Click <strong>{1}</strong> to return to resolving conflicts.</html>"
    188208                                , options[0].toString(), options[1].toString()
    189209                        ),
    190                         tr("Warning"),
     210                        tr("Conflict not resolved completely"),
    191211                        JOptionPane.YES_NO_OPTION,
    192212                        JOptionPane.WARNING_MESSAGE,
     
    194214                        options[1]
    195215                );
    196                 if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION)
     216                switch(ret) {
     217                case JOptionPane.YES_OPTION:
     218                    setVisible(false);
     219                    break;
     220                default:
    197221                    return;
     222                }
    198223            }
    199224            try {
    200225                Command cmd = resolver.buildResolveCommand();
    201226                Main.main.undoRedo.add(cmd);
     227                setVisible(false);
    202228            } catch(OperationCancelledException e) {
    203229                // do nothing. Exception already reported
    204230            }
    205             setVisible(false);
     231        }
     232
     233        public void propertyChange(PropertyChangeEvent evt) {
     234            if (evt.getPropertyName().equals(ConflictResolver.RESOLVED_COMPLETELY_PROP)) {
     235                updateEnabledState();
     236            }
     237        }
     238    }
     239
     240    protected void updateTitle() {
     241        updateTitle(null);
     242    }
     243
     244    protected void updateTitle(OsmPrimitive my) {
     245        if (my == null) {
     246            setTitle(tr("Resolve conflicts"));
     247        } else {
     248            PrimitiveNameFormatter formatter = new PrimitiveNameFormatter();
     249            setTitle(tr("Resolve conflicts for ''{0}''", formatter.getName(my)));
     250        }
     251    }
     252
     253    public void propertyChange(PropertyChangeEvent evt) {
     254        if (evt.getPropertyName().equals(ConflictResolver.MY_PRIMITIVE_PROP)) {
     255            updateTitle((OsmPrimitive)evt.getNewValue());
    206256        }
    207257    }
Note: See TracChangeset for help on using the changeset viewer.