Changeset 1795 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-07-15T18:44:58+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #2901: Relation editor producing errors

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

Legend:

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

    r1794 r1795  
    4545import org.openstreetmap.josm.command.AddCommand;
    4646import org.openstreetmap.josm.command.ChangeCommand;
     47import org.openstreetmap.josm.data.conflict.Conflict;
    4748import org.openstreetmap.josm.data.osm.DataSet;
    4849import org.openstreetmap.josm.data.osm.DataSource;
     
    534535     * This function saves the user's changes. Must be invoked manually.
    535536     */
    536     private void applyChanges() {
     537    protected void applyChanges() {
    537538        if (getRelation()== null) {
    538539            // If the user wanted to create a new relation, but hasn't added any members or
     
    546547            DataSet.fireSelectionChanged(Main.ds.getSelected());
    547548        } else if (! memberTableModel.hasSameMembersAs(getRelation()) || tagEditorModel.isDirty()) {
    548             Relation clone = new Relation(getRelation());
    549             tagEditorModel.applyToPrimitive(clone);
    550             memberTableModel.applyToRelation(clone);
    551             Main.main.undoRedo.add(new ChangeCommand(getRelation(), clone));
    552             DataSet.fireSelectionChanged(Main.ds.getSelected());
     549            Relation editedRelation = new Relation(getRelation());
     550            tagEditorModel.applyToPrimitive(editedRelation);
     551            memberTableModel.applyToRelation(editedRelation);
     552            if (isDirtyRelation()) {
     553                Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation);
     554                getLayer().getConflicts().add(conflict);
     555                JOptionPane op = new JOptionPane(
     556                        tr("<html>The relation has changed outside of the editor.<br>"
     557                                + "Your edit can't be applied directly, a conflict has been created instead.</html>"
     558                        ),
     559                        JOptionPane.WARNING_MESSAGE
     560                );
     561                JDialog dialog = op.createDialog(Main.pleaseWaitDlg, tr("Conflict created"));
     562                dialog.setAlwaysOnTop(true);
     563                dialog.setModal(true);
     564                dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     565                dialog.setVisible(true);
     566            } else {
     567                Relation clone = new Relation(getRelation());
     568                tagEditorModel.applyToPrimitive(clone);
     569                memberTableModel.applyToRelation(clone);
     570                Main.main.undoRedo.add(new ChangeCommand(getRelation(), clone));
     571                DataSet.fireSelectionChanged(Main.ds.getSelected());
     572            }
    553573        }
    554574    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    r1790 r1795  
    3737
    3838    /**
    39      * The relation that this editor is working on, and the clone made for
    40      * editing.
     39     * The relation that this editor is working on.
    4140     */
    4241    private Relation relation;
     42
     43    /** The version of the relation when editing is started. */
     44    private Relation relationSnapshot;
    4345
    4446    /** the data layer the relation belongs to */
     
    100102        );
    101103
     104        this.relationSnapshot = new Relation(relation);
    102105        this.relation = relation;
    103106        this.layer = layer;
     
    111114        return layer;
    112115    }
     116
     117    protected Relation getRelationSnapshot() {
     118        return relationSnapshot;
     119    }
     120
     121    /**
     122     * Replies true if the currently edited relation has been changed elsewhere.
     123     *
     124     * In this case a relation editor can't apply updates to the relation directly. Rather,
     125     * it has to create a conflict.
     126     *
     127     * @return true if the currently edited relation has been changed elsewhere.
     128     */
     129    protected boolean isDirtyRelation() {
     130        return ! relation.hasEqualSemanticAttributes(relationSnapshot);
     131    }
    113132}
Note: See TracChangeset for help on using the changeset viewer.