Ticket #12411: AutoUpdateRelationEditor.patch

File AutoUpdateRelationEditor.patch, 7.0 KB (added by kolesar, 9 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
    index 2e0bc2a..e87d5c2 100644
    a b import javax.swing.AbstractAction;  
    3131import javax.swing.BorderFactory;
    3232import javax.swing.InputMap;
    3333import javax.swing.JButton;
     34import javax.swing.JCheckBox;
    3435import javax.swing.JComponent;
    3536import javax.swing.JLabel;
    3637import javax.swing.JMenu;
    import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedAtEndActio  
    6566import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedAtStartAction;
    6667import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedBeforeSelection;
    6768import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction;
     69import org.openstreetmap.josm.gui.dialogs.relation.actions.AutoUpdateAction;
    6870import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction;
    6971import org.openstreetmap.josm.gui.dialogs.relation.actions.CopyMembersAction;
    7072import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction;
    public class GenericRelationEditor extends RelationEditor {  
    130132    /**
    131133     * Action for performing the {@link RefreshAction}
    132134     */
    133     private RefreshAction refreshAction;
     135    public RefreshAction refreshAction;
    134136    /**
    135137     * Action for performing the {@link ApplyAction}
    136138     */
    137     private ApplyAction applyAction;
     139    public ApplyAction applyAction;
     140    /**
     141     * Action for performing the {@link AutoUpdateAction}
     142     */
     143    public AutoUpdateAction autoUpdateAction;
    138144    /**
    139145     * Action for performing the {@link CancelAction}
    140146     */
    141147    private CancelAction cancelAction;
     148    /**
     149     * Flag used by some actions telling that change event comes from here
     150     */
     151    public boolean saving;
    142152
    143153    /**
    144154     * Creates a new relation editor for the given relation. The relation will be saved if the user
    public class GenericRelationEditor extends RelationEditor {  
    291301    }
    292302
    293303    /**
     304     * Check if automatic update is enabled.
     305     * @return true if automatic update is enabled
     306     */
     307    public boolean isAutoUpdate() {
     308        return autoUpdateAction.enabled();
     309    }
     310
     311    /**
     312     * Disable automatic update.
     313     */
     314    public void disableAutoUpdate() {
     315        autoUpdateAction.disable();
     316    }
     317
     318    /**
    294319     * Creates the toolbar
    295320     *
    296321     * @return the toolbar
    public class GenericRelationEditor extends RelationEditor {  
    306331        DeleteCurrentRelationAction deleteAction = new DeleteCurrentRelationAction(getLayer(), this);
    307332        addPropertyChangeListener(deleteAction);
    308333        tb.add(deleteAction);
     334        tb.add(new JCheckBox(autoUpdateAction = new AutoUpdateAction(this)));
    309335        return tb;
    310336    }
    311337
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java
    index d2c5a34..5aca055 100644
    a b public class ApplyAction extends SavingAction implements PropertyChangeListener,  
    5050    }
    5151
    5252    @Override
    53     protected void updateEnabledState() {
    54         setEnabled(isEditorDirty());
    55     }
     53    public void updateEnabledState() {
     54        if (getEditor().saving) return;
     55        boolean enable = isEditorDirty();
     56        if (enable && getEditor().isAutoUpdate()) {
     57            actionPerformed(null);
     58        } else {
     59            setEnabled(enable);
     60        }
     61     }
    5662
    5763    @Override
    5864    public void propertyChange(PropertyChangeEvent evt) {
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java
    index 9abdce4..d36016c 100644
    a b public class RefreshAction extends SavingAction implements CommandQueueListener  
    6464            }
    6565            return;
    6666        }
    67         if (isEditorDirty() && confirmDiscardDirtyData() != 0)
     67        if (isEditorDirty() && confirmDiscardDirtyData() != 0) {
     68            getEditor().disableAutoUpdate();
    6869            return;
     70        }
    6971        editor.reloadDataFromRelation();
    7072    }
    7173
    7274    @Override
    7375    public void updateEnabledState() {
     76        if (getEditor().saving) return;
    7477        Relation relation = editor.getRelation();
    7578        Relation snapshot = editor.getRelationSnapshot();
    76         setEnabled(snapshot != null && (
     79        boolean enable = snapshot != null && (
    7780            !relation.hasEqualTechnicalAttributes(snapshot) ||
    7881            !relation.hasEqualSemanticAttributes(snapshot)
    79         ));
     82        );
     83        if (enable && getEditor().isAutoUpdate()) {
     84            actionPerformed(null);
     85        } else {
     86            setEnabled(enable);
     87        }
    8088    }
    8189
    8290    protected int confirmDiscardDirtyData() {
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
    index d7371ec..ac06935 100644
    a b import org.openstreetmap.josm.data.osm.RelationMember;  
    2020import org.openstreetmap.josm.gui.DefaultNameFormatter;
    2121import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2222import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
     23import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
    2324import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    2425import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    2526import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    abstract class SavingAction extends AbstractRelationEditorAction {  
    165166    }
    166167
    167168    protected boolean applyChanges() {
     169        GenericRelationEditor editor = getEditor();
     170        editor.saving = true;
     171        boolean ret = doApplyChanges();
     172        editor.saving = false;
     173        if (!ret) editor.disableAutoUpdate();
     174        return ret;
     175    }
     176
     177    protected boolean doApplyChanges() {
    168178        if (editor.getRelation() == null) {
    169179            applyNewRelation(tagModel);
    170180        } else if (isEditorDirty()) {
    abstract class SavingAction extends AbstractRelationEditorAction {  
    196206        Relation snapshot = editor.getRelationSnapshot();
    197207        return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) || tagModel.isDirty();
    198208    }
     209
     210    protected GenericRelationEditor getEditor() {
     211        return (GenericRelationEditor) editor;
     212    }
    199213}