Ignore:
Timestamp:
2018-07-12T23:02:02+02:00 (8 years ago)
Author:
michael2402
Message:

See #16388: New mechanism for plugins to register relation editor actions.

File:
1 edited

Legend:

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

    r13842 r14027  
    2222import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    2323import org.openstreetmap.josm.gui.MainApplication;
    24 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    25 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    26 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    2724import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager;
    2825import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    29 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3026import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    3127import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
     
    3834 */
    3935abstract class SavingAction extends AbstractRelationEditorAction {
     36        private static final long serialVersionUID = 1L;
    4037
    41     protected final TagEditorModel tagModel;
    4238    protected final AutoCompletingTextField tfRole;
    4339
    44     protected SavingAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
    45             IRelationEditor editor, AutoCompletingTextField tfRole) {
    46         super(memberTable, memberTableModel, null, layer, editor);
    47         this.tagModel = tagModel;
    48         this.tfRole = tfRole;
     40    protected SavingAction(IRelationEditorActionAccess editorAccess, IRelationEditorUpdateOn... updateOn) {
     41        super(editorAccess, updateOn);
     42        this.tfRole = editorAccess.getTextFieldRole();
    4943    }
    5044
     
    5650        final Relation newRelation = new Relation();
    5751        tagEditorModel.applyToPrimitive(newRelation);
    58         memberTableModel.applyToRelation(newRelation);
     52        getMemberTableModel().applyToRelation(newRelation);
    5953        List<RelationMember> newMembers = new ArrayList<>();
    6054        for (RelationMember rm: newRelation.getMembers()) {
     
    7367        if (newRelation.getMembersCount() == 0 && !newRelation.hasKeys())
    7468            return;
    75         MainApplication.undoRedo.add(new AddCommand(layer.getDataSet(), newRelation));
     69        MainApplication.undoRedo.add(new AddCommand(getLayer().getDataSet(), newRelation));
    7670
    7771        // make sure everybody is notified about the changes
    7872        //
    79         editor.setRelation(newRelation);
    80         if (editor instanceof RelationEditor) {
     73        getEditor().setRelation(newRelation);
     74        if (getEditor() instanceof RelationEditor) {
    8175            RelationDialogManager.getRelationDialogManager().updateContext(
    82                     layer, editor.getRelation(), (RelationEditor) editor);
     76                    getLayer(), getEditor().getRelation(), (RelationEditor) getEditor());
    8377        }
    8478        // Relation list gets update in EDT so selecting my be postponed to following EDT run
     
    9185     */
    9286    protected void applyExistingConflictingRelation(TagEditorModel tagEditorModel) {
    93         Relation editedRelation = new Relation(editor.getRelation());
     87        Relation editedRelation = new Relation(editorAccess.getEditor().getRelation());
    9488        tagEditorModel.applyToPrimitive(editedRelation);
    95         memberTableModel.applyToRelation(editedRelation);
    96         Conflict<Relation> conflict = new Conflict<>(editor.getRelation(), editedRelation);
    97         MainApplication.undoRedo.add(new ConflictAddCommand(layer.getDataSet(), conflict));
     89        editorAccess.getMemberTableModel().applyToRelation(editedRelation);
     90        Conflict<Relation> conflict = new Conflict<>(editorAccess.getEditor().getRelation(), editedRelation);
     91        MainApplication.undoRedo.add(new ConflictAddCommand(getLayer().getDataSet(), conflict));
    9892    }
    9993
     
    10397     */
    10498    protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) {
    105         Relation originRelation = editor.getRelation();
     99        Relation originRelation = editorAccess.getEditor().getRelation();
    106100        Relation editedRelation = new Relation(originRelation);
    107101        tagEditorModel.applyToPrimitive(editedRelation);
    108         memberTableModel.applyToRelation(editedRelation);
     102        getMemberTableModel().applyToRelation(editedRelation);
    109103        if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) {
    110104            MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation));
     
    153147                        + "''{1}''.<br>"
    154148                        + "Please resolve this conflict first, then try again.</html>",
    155                         Utils.escapeReservedCharactersHTML(layer.getName()),
    156                         Utils.escapeReservedCharactersHTML(editor.getRelation().getDisplayName(DefaultNameFormatter.getInstance()))
     149                        Utils.escapeReservedCharactersHTML(getLayer().getName()),
     150                        Utils.escapeReservedCharactersHTML(getEditor().getRelation().getDisplayName(DefaultNameFormatter.getInstance()))
    157151                ),
    158152                tr("Double conflict"),
     
    167161
    168162    protected boolean applyChanges() {
    169         if (editor.getRelation() == null) {
    170             applyNewRelation(tagModel);
     163        if (editorAccess.getEditor().getRelation() == null) {
     164            applyNewRelation(getTagModel());
    171165        } else if (isEditorDirty()) {
    172             if (editor.isDirtyRelation()) {
     166            if (editorAccess.getEditor().isDirtyRelation()) {
    173167                if (confirmClosingBecauseOfDirtyState()) {
    174                     if (layer.getConflicts().hasConflictForMy(editor.getRelation())) {
     168                    if (getLayer().getConflicts().hasConflictForMy(editorAccess.getEditor().getRelation())) {
    175169                        warnDoubleConflict();
    176170                        return false;
    177171                    }
    178                     applyExistingConflictingRelation(tagModel);
     172                    applyExistingConflictingRelation(getTagModel());
    179173                    hideEditor();
    180174                } else
    181175                    return false;
    182176            } else {
    183                 applyExistingNonConflictingRelation(tagModel);
     177                applyExistingNonConflictingRelation(getTagModel());
    184178            }
    185179        }
    186         editor.setRelation(editor.getRelation());
     180        editorAccess.getEditor().setRelation(editorAccess.getEditor().getRelation());
    187181        return true;
    188182    }
    189183
    190184    protected void hideEditor() {
    191         if (editor instanceof Component) {
    192             ((Component) editor).setVisible(false);
     185        if (editorAccess.getEditor() instanceof Component) {
     186            ((Component) editorAccess.getEditor()).setVisible(false);
    193187        }
    194188    }
    195189
    196190    protected boolean isEditorDirty() {
    197         Relation snapshot = editor.getRelationSnapshot();
    198         return (snapshot != null && !memberTableModel.hasSameMembersAs(snapshot)) || tagModel.isDirty();
     191        Relation snapshot = editorAccess.getEditor().getRelationSnapshot();
     192        return (snapshot != null && !getMemberTableModel().hasSameMembersAs(snapshot)) || getTagModel().isDirty();
    199193    }
    200194}
Note: See TracChangeset for help on using the changeset viewer.