Changeset 18793 in josm


Ignore:
Timestamp:
2023-08-07T19:39:39+02:00 (11 months ago)
Author:
taylor.smock
Message:

Fix #23091: Opening a preset from inside a relation editor causes a DataIntegrityProblemException

Location:
trunk
Files:
2 edited

Legend:

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

    r18413 r18793  
    124124    private final TagEditorPanel tagEditorPanel;
    125125    private final ReferringRelationsBrowser referrerBrowser;
    126     private final ReferringRelationsBrowserModel referrerModel;
    127126
    128127    /** the member table and its model */
     
    154153    private final SelectAction selectAction;
    155154    /**
    156      * Action for performing the {@link DuplicateRelationAction}
    157      */
    158     private final DuplicateRelationAction duplicateAction;
    159     /**
    160      * Action for performing the {@link DeleteCurrentRelationAction}
    161      */
    162     private final DeleteCurrentRelationAction deleteAction;
    163     /**
    164      * Action for performing the {@link OKAction}
    165      */
    166     private final OKAction okAction;
    167     /**
    168155     * Action for performing the {@link CancelAction}
    169156     */
     
    175162
    176163    private Component selectedTabPane;
    177     private JTabbedPane tabbedPane;
     164    private final JTabbedPane tabbedPane;
    178165
    179166    /**
    180167     * Creates a new relation editor for the given relation. The relation will be saved if the user
    181168     * selects "ok" in the editor.
    182      *
     169     * <p>
    183170     * If no relation is given, will create an editor for a new relation.
    184171     *
     
    202189            @Override
    203190            public Collection<OsmPrimitive> getSelection() {
    204                 Relation relation = new Relation();
    205                 tagEditorPanel.getModel().applyToPrimitive(relation);
    206                 return Collections.<OsmPrimitive>singletonList(relation);
     191                return Collections.singletonList(getRelation());
    207192            }
    208193        };
     
    214199        selectionTableModel = new SelectionTableModel(getLayer());
    215200        selectionTableModel.register();
    216         referrerModel = new ReferringRelationsBrowserModel(relation);
     201        ReferringRelationsBrowserModel referrerModel = new ReferringRelationsBrowserModel(relation);
    217202
    218203        tagEditorPanel = new TagEditorPanel(relation, presetHandler);
     
    271256        applyAction = new ApplyAction(actionAccess);
    272257        selectAction = new SelectAction(actionAccess);
    273         duplicateAction = new DuplicateRelationAction(actionAccess);
    274         deleteAction = new DeleteCurrentRelationAction(actionAccess);
     258        // Action for performing the {@link DuplicateRelationAction}
     259        final DuplicateRelationAction duplicateAction = new DuplicateRelationAction(actionAccess);
     260        // Action for performing the {@link DeleteCurrentRelationAction}
     261        final DeleteCurrentRelationAction deleteAction = new DeleteCurrentRelationAction(actionAccess);
    275262
    276263        this.memberTableModel.addTableModelListener(applyAction);
     
    279266        addPropertyChangeListener(deleteAction);
    280267
    281         okAction = new OKAction(actionAccess);
     268        // Action for performing the {@link OKAction}
     269        final OKAction okAction = new OKAction(actionAccess);
    282270        cancelAction = new CancelAction(actionAccess);
    283271
     
    518506     * @return the panel for the relation member editor
    519507     */
    520     protected static JPanel buildMemberEditorPanel(
     508    static JPanel buildMemberEditorPanel(
    521509            LeftButtonToolbar leftButtonToolbar, IRelationEditorActionAccess editorAccess) {
    522510        final JPanel pnl = new JPanel(new GridBagLayout());
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    r17275 r18793  
    55import static org.junit.jupiter.api.Assertions.assertNotNull;
    66import static org.junit.jupiter.api.Assertions.assertNull;
     7import static org.junit.jupiter.api.Assertions.assertSame;
    78
     9import java.util.Collection;
    810import java.util.Collections;
    911
     
    1113import javax.swing.JPanel;
    1214
     15import mockit.Mock;
     16import mockit.MockUp;
    1317import org.junit.jupiter.api.Test;
    14 import org.junit.jupiter.api.extension.RegisterExtension;
     18import org.junit.platform.commons.support.ReflectionSupport;
    1519import org.openstreetmap.josm.TestUtils;
    1620import org.openstreetmap.josm.data.osm.DataSet;
     
    1923import org.openstreetmap.josm.data.osm.Relation;
    2024import org.openstreetmap.josm.data.osm.Way;
     25import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionAccess;
     26import org.openstreetmap.josm.gui.dialogs.relation.actions.PasteMembersAction;
    2127import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2228import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    2329import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    24 import org.openstreetmap.josm.testutils.JOSMTestRules;
     30import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
     31import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     32import org.openstreetmap.josm.testutils.annotations.Main;
    2533import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    26 
    27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2834
    2935/**
    3036 * Unit tests of {@link GenericRelationEditor} class.
    3137 */
     38@BasicPreferences
     39@Main
    3240public class GenericRelationEditorTest {
    33 
    34     /**
    35      * Setup test.
    36      */
    37     @RegisterExtension
    38     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    39     public JOSMTestRules test = new JOSMTestRules().preferences().main();
    40 
    4141    /**
    4242     * Returns a new relation editor for unit tests.
     
    133133        assertNotNull(tagEditorPanel.getModel());
    134134    }
     135
     136    @Test
     137    void testNonRegression23091() throws Exception {
     138        new MockUp<PasteMembersAction>() {
     139            @Mock
     140            protected void updateEnabledState() {
     141                // Do nothing
     142            }
     143        };
     144
     145        DataSet ds = new DataSet();
     146        Relation relation = new Relation(1);
     147        ds.addPrimitive(relation);
     148        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     149
     150        final GenericRelationEditor gr = new GenericRelationEditor(layer, relation, Collections.emptyList());
     151        final IRelationEditorActionAccess iAccess = (IRelationEditorActionAccess)
     152                ReflectionSupport.tryToReadFieldValue(GenericRelationEditor.class.getDeclaredField("actionAccess"), gr)
     153                        .get();
     154        final TaggingPresetHandler handler = (TaggingPresetHandler)
     155                ReflectionSupport.tryToReadFieldValue(MemberTableModel.class.getDeclaredField("presetHandler"), iAccess.getMemberTableModel())
     156                        .get();
     157        final Collection<OsmPrimitive> selection = handler.getSelection();
     158        assertEquals(1, selection.size());
     159        assertSame(relation, selection.iterator().next(), "The selection should be the same");
     160    }
    135161}
Note: See TracChangeset for help on using the changeset viewer.