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;
|
| 31 | 31 | import javax.swing.BorderFactory; |
| 32 | 32 | import javax.swing.InputMap; |
| 33 | 33 | import javax.swing.JButton; |
| | 34 | import javax.swing.JCheckBox; |
| 34 | 35 | import javax.swing.JComponent; |
| 35 | 36 | import javax.swing.JLabel; |
| 36 | 37 | import javax.swing.JMenu; |
| … |
… |
import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedAtEndActio
|
| 65 | 66 | import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedAtStartAction; |
| 66 | 67 | import org.openstreetmap.josm.gui.dialogs.relation.actions.AddSelectedBeforeSelection; |
| 67 | 68 | import org.openstreetmap.josm.gui.dialogs.relation.actions.ApplyAction; |
| | 69 | import org.openstreetmap.josm.gui.dialogs.relation.actions.AutoUpdateAction; |
| 68 | 70 | import org.openstreetmap.josm.gui.dialogs.relation.actions.CancelAction; |
| 69 | 71 | import org.openstreetmap.josm.gui.dialogs.relation.actions.CopyMembersAction; |
| 70 | 72 | import org.openstreetmap.josm.gui.dialogs.relation.actions.DeleteCurrentRelationAction; |
| … |
… |
public class GenericRelationEditor extends RelationEditor {
|
| 130 | 132 | /** |
| 131 | 133 | * Action for performing the {@link RefreshAction} |
| 132 | 134 | */ |
| 133 | | private RefreshAction refreshAction; |
| | 135 | public RefreshAction refreshAction; |
| 134 | 136 | /** |
| 135 | 137 | * Action for performing the {@link ApplyAction} |
| 136 | 138 | */ |
| 137 | | private ApplyAction applyAction; |
| | 139 | public ApplyAction applyAction; |
| | 140 | /** |
| | 141 | * Action for performing the {@link AutoUpdateAction} |
| | 142 | */ |
| | 143 | public AutoUpdateAction autoUpdateAction; |
| 138 | 144 | /** |
| 139 | 145 | * Action for performing the {@link CancelAction} |
| 140 | 146 | */ |
| 141 | 147 | private CancelAction cancelAction; |
| | 148 | /** |
| | 149 | * Flag used by some actions telling that change event comes from here |
| | 150 | */ |
| | 151 | public boolean saving; |
| 142 | 152 | |
| 143 | 153 | /** |
| 144 | 154 | * Creates a new relation editor for the given relation. The relation will be saved if the user |
| … |
… |
public class GenericRelationEditor extends RelationEditor {
|
| 291 | 301 | } |
| 292 | 302 | |
| 293 | 303 | /** |
| | 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 | /** |
| 294 | 319 | * Creates the toolbar |
| 295 | 320 | * |
| 296 | 321 | * @return the toolbar |
| … |
… |
public class GenericRelationEditor extends RelationEditor {
|
| 306 | 331 | DeleteCurrentRelationAction deleteAction = new DeleteCurrentRelationAction(getLayer(), this); |
| 307 | 332 | addPropertyChangeListener(deleteAction); |
| 308 | 333 | tb.add(deleteAction); |
| | 334 | tb.add(new JCheckBox(autoUpdateAction = new AutoUpdateAction(this))); |
| 309 | 335 | return tb; |
| 310 | 336 | } |
| 311 | 337 | |
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,
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | @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 | } |
| 56 | 62 | |
| 57 | 63 | @Override |
| 58 | 64 | public void propertyChange(PropertyChangeEvent evt) { |
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
|
| 64 | 64 | } |
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | | if (isEditorDirty() && confirmDiscardDirtyData() != 0) |
| | 67 | if (isEditorDirty() && confirmDiscardDirtyData() != 0) { |
| | 68 | getEditor().disableAutoUpdate(); |
| 68 | 69 | return; |
| | 70 | } |
| 69 | 71 | editor.reloadDataFromRelation(); |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | @Override |
| 73 | 75 | public void updateEnabledState() { |
| | 76 | if (getEditor().saving) return; |
| 74 | 77 | Relation relation = editor.getRelation(); |
| 75 | 78 | Relation snapshot = editor.getRelationSnapshot(); |
| 76 | | setEnabled(snapshot != null && ( |
| | 79 | boolean enable = snapshot != null && ( |
| 77 | 80 | !relation.hasEqualTechnicalAttributes(snapshot) || |
| 78 | 81 | !relation.hasEqualSemanticAttributes(snapshot) |
| 79 | | )); |
| | 82 | ); |
| | 83 | if (enable && getEditor().isAutoUpdate()) { |
| | 84 | actionPerformed(null); |
| | 85 | } else { |
| | 86 | setEnabled(enable); |
| | 87 | } |
| 80 | 88 | } |
| 81 | 89 | |
| 82 | 90 | protected int confirmDiscardDirtyData() { |
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;
|
| 20 | 20 | import org.openstreetmap.josm.gui.DefaultNameFormatter; |
| 21 | 21 | import org.openstreetmap.josm.gui.HelpAwareOptionPane; |
| 22 | 22 | import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; |
| | 23 | import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; |
| 23 | 24 | import org.openstreetmap.josm.gui.dialogs.relation.MemberTable; |
| 24 | 25 | import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel; |
| 25 | 26 | import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor; |
| … |
… |
abstract class SavingAction extends AbstractRelationEditorAction {
|
| 165 | 166 | } |
| 166 | 167 | |
| 167 | 168 | 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() { |
| 168 | 178 | if (editor.getRelation() == null) { |
| 169 | 179 | applyNewRelation(tagModel); |
| 170 | 180 | } else if (isEditorDirty()) { |
| … |
… |
abstract class SavingAction extends AbstractRelationEditorAction {
|
| 196 | 206 | Relation snapshot = editor.getRelationSnapshot(); |
| 197 | 207 | return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) || tagModel.isDirty(); |
| 198 | 208 | } |
| | 209 | |
| | 210 | protected GenericRelationEditor getEditor() { |
| | 211 | return (GenericRelationEditor) editor; |
| | 212 | } |
| 199 | 213 | } |