Ticket #23527: 23527-alpha.patch

File 23527-alpha.patch, 4.8 KB (added by GerdP, 2 years ago)

work in progress, fixes the problem but I think it's duplicating too much code

  • src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

     
    405405    /**
    406406     * builds the panel with the OK and the Cancel button
    407407     * @param okAction OK action
     408     * @param deleteAction  Delete action
    408409     * @param cancelAction Cancel action
    409410     *
    410411     * @return the panel with the OK and the Cancel button
     
    421422        pnl.add(new JButton(new ContextSensitiveHelpAction(ht("/Dialog/RelationEditor"))));
    422423        // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type"
    423424        // AND must contain at least one other OSM object.
    424         final TableModelListener listener = l -> updateOkPanel(this.actionAccess.getChangedRelation(), okButton, deleteButton);
     425        final TableModelListener listener = l -> updateOkPanel(okButton, deleteButton);
    425426        listener.tableChanged(null);
    426427        this.memberTableModel.addTableModelListener(listener);
    427428        this.tagEditorPanel.getModel().addTableModelListener(listener);
     
    429430    }
    430431
    431432    /**
    432      * Update the OK panel area
    433      * @param newRelation What the new relation would "look" like if it were to be saved now
     433     * Update the OK panel area with a temporary relation that looks if it were to be saved now.
    434434     * @param okButton The OK button
    435435     * @param deleteButton The delete button
    436436     */
    437     private void updateOkPanel(IRelation<?> newRelation, JButton okButton, JButton deleteButton) {
     437    private void updateOkPanel(JButton okButton, JButton deleteButton) {
     438        Relation oldRelation = this.actionAccess.getEditor().getRelation();
     439        IRelation<?> newRelation = this.actionAccess.getChangedRelation();
    438440        okButton.setVisible(newRelation.isUseful() || this.getRelationSnapshot() == null);
    439441        deleteButton.setVisible(!newRelation.isUseful() && this.getRelationSnapshot() != null);
    440442        if (this.getRelationSnapshot() == null && !newRelation.isUseful()) {
     
    442444        } else {
    443445            okButton.setText(tr("OK"));
    444446        }
     447        if (newRelation != oldRelation && newRelation.getMembersCount() > 0)
     448            newRelation.setMembers(null); // see #19885, #23527
    445449    }
    446450
    447451    /**
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java

     
    55
    66import java.awt.event.ActionEvent;
    77
     8import org.openstreetmap.josm.data.osm.IRelation;
     9import org.openstreetmap.josm.data.osm.Relation;
    810import org.openstreetmap.josm.tools.ImageProvider;
    911
    1012/**
     
    3537
    3638    @Override
    3739    public void updateEnabledState() {
    38         setEnabled(this.editorAccess.getChangedRelation().isUseful() && isEditorDirty());
     40        boolean enable = isEditorDirty();
     41        if (enable) {
     42            Relation oldRelation = this.getEditor().getRelation();
     43            IRelation<?> newRelation = this.editorAccess.getChangedRelation();
     44            enable = newRelation.isUseful();
     45            if (oldRelation != newRelation && newRelation.getMembersCount() > 0)
     46                newRelation.setMembers(null); // see #19885, #23527
     47        }
     48        setEnabled(enable);
    3949    }
    4050}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java

     
    4848        if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty())
    4949         && !(snapshot == null && getTagModel().getTags().isEmpty())) {
    5050            //give the user a chance to save the changes
    51             int ret = confirmClosingByCancel(this.editorAccess.getChangedRelation());
     51            Relation oldRel = this.editorAccess.getEditor().getRelation();
     52            IRelation<?> newRelation = this.editorAccess.getChangedRelation();
     53            int ret = confirmClosingByCancel(newRelation);
     54            if (oldRel != newRelation && newRelation.getMembersCount() > 0)
     55                newRelation.setMembers(null); // see #19885, #23527
    5256            if (ret == 0) { //Yes, save the changes
    5357                //copied from OKAction.run()
    5458                Config.getPref().put("relation.editor.generic.lastrole", Utils.strip(tfRole.getText()));