Ticket #16388: fix-16388.patch

File fix-16388.patch, 121.5 KB (added by michael2402, 8 weeks 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 b0b2aad..671a513 100644
    a b import java.awt.event.MouseEvent; 
    2323import java.awt.event.WindowAdapter;
    2424import java.awt.event.WindowEvent;
    2525import java.util.ArrayList;
     26import java.util.Arrays;
    2627import java.util.Collection;
    2728import java.util.Collections;
    2829import java.util.EnumSet;
    import javax.swing.JToolBar; 
    4849import javax.swing.KeyStroke;
    4950
    5051import org.openstreetmap.josm.Main;
    51 import org.openstreetmap.josm.actions.ExpertToggleAction;
    5252import org.openstreetmap.josm.actions.JosmAction;
    5353import org.openstreetmap.josm.command.ChangeCommand;
    5454import org.openstreetmap.josm.command.Command;
    import org.openstreetmap.josm.gui.dialogs.relation.actions.DownloadIncompleteMem 
    7575import org.openstreetmap.josm.gui.dialogs.relation.actions.DownloadSelectedIncompleteMembersAction;
    7676import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction;
    7777import org.openstreetmap.josm.gui.dialogs.relation.actions.EditAction;
     78import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionAccess;
     79import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionGroup;
    7880import org.openstreetmap.josm.gui.dialogs.relation.actions.MoveDownAction;
    7981import org.openstreetmap.josm.gui.dialogs.relation.actions.MoveUpAction;
    8082import org.openstreetmap.josm.gui.dialogs.relation.actions.OKAction;
    import org.openstreetmap.josm.gui.dialogs.relation.actions.SortBelowAction; 
    9294import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    9395import org.openstreetmap.josm.gui.help.HelpUtil;
    9496import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     97import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    9598import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    9699import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    97100import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
    public class GenericRelationEditor extends RelationEditor { 
    220223        selectionTable = new SelectionTable(selectionTableModel, memberTableModel);
    221224        selectionTable.setRowHeight(ce.getEditor().getPreferredSize().height);
    222225
    223         leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, this);
     226        leftButtonToolbar = new LeftButtonToolbar(new RelationEditorActionAccess());
    224227        tfRole = buildRoleTextField(this);
    225228
    226229        JSplitPane pane = buildSplitPane(
    227230                buildTagEditorPanel(tagEditorPanel),
    228                 buildMemberEditorPanel(memberTable, memberTableModel, selectionTable, selectionTableModel, this, leftButtonToolbar, tfRole),
     231                buildMemberEditorPanel(leftButtonToolbar, new RelationEditorActionAccess()),
    229232                this);
    230233        pane.setPreferredSize(new Dimension(100, 100));
    231234
    public class GenericRelationEditor extends RelationEditor { 
    247250                referrerBrowser.init();
    248251            }
    249252        });
    250 
    251         refreshAction = new RefreshAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this);
    252         applyAction = new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this);
    253         selectAction = new SelectAction(getLayer(), this);
    254         duplicateAction = new DuplicateRelationAction(memberTableModel, tagEditorPanel.getModel(), getLayer());
    255         deleteAction = new DeleteCurrentRelationAction(getLayer(), this);
     253       
     254        IRelationEditorActionAccess actionAccess = new RelationEditorActionAccess();
     255
     256        refreshAction = new RefreshAction(actionAccess);
     257        applyAction = new ApplyAction(actionAccess);
     258        selectAction = new SelectAction(actionAccess);
     259        duplicateAction = new DuplicateRelationAction(actionAccess);
     260        deleteAction = new DeleteCurrentRelationAction(actionAccess);
    256261        addPropertyChangeListener(deleteAction);
    257262
    258         okAction = new OKAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole);
    259         cancelAction = new CancelAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole);
     263        okAction = new OKAction(actionAccess);
     264        cancelAction = new CancelAction(actionAccess);
    260265
    261266        getContentPane().add(buildToolBar(refreshAction, applyAction, selectAction, duplicateAction, deleteAction), BorderLayout.NORTH);
    262267        getContentPane().add(tabbedPane, BorderLayout.CENTER);
    public class GenericRelationEditor extends RelationEditor { 
    287292        KeyStroke key = Shortcut.getPasteKeyStroke();
    288293        if (key != null) {
    289294            // handle uncommon situation, that user has no keystroke assigned to paste
    290             registerCopyPasteAction(new PasteMembersAction(memberTable, getLayer(), this) {
    291                 @Override
     295            registerCopyPasteAction(new PasteMembersAction(actionAccess) {
     296                                private static final long serialVersionUID = 1L;
     297
     298                                @Override
    292299                public void actionPerformed(ActionEvent e) {
    293300                    super.actionPerformed(e);
    294301                    tfRole.requestFocusInWindow();
    public class GenericRelationEditor extends RelationEditor { 
    298305        key = Shortcut.getCopyKeyStroke();
    299306        if (key != null) {
    300307            // handle uncommon situation, that user has no keystroke assigned to copy
    301             registerCopyPasteAction(new CopyMembersAction(memberTableModel, getLayer(), this),
     308            registerCopyPasteAction(new CopyMembersAction(actionAccess),
    302309                    "COPY_MEMBERS", key, getRootPane(), memberTable, selectionTable);
    303310        }
    304311        tagEditorPanel.setNextFocusComponent(memberTable);
    public class GenericRelationEditor extends RelationEditor { 
    446453
    447454    /**
    448455     * builds the panel for the relation member editor
    449      * @param memberTable member table
    450      * @param memberTableModel member table model
    451      * @param selectionTable selection table
    452      * @param selectionTableModel selection table model
    453      * @param re relation editor
    454456     * @param leftButtonToolbar left button toolbar
    455      * @param tfRole role text field
     457     * @param editorAccess The relation editor
    456458     *
    457459     * @return the panel for the relation member editor
    458460     */
    459     protected static JPanel buildMemberEditorPanel(final MemberTable memberTable, MemberTableModel memberTableModel,
    460             SelectionTable selectionTable, SelectionTableModel selectionTableModel, IRelationEditor re,
    461             LeftButtonToolbar leftButtonToolbar, final AutoCompletingTextField tfRole) {
     461    protected static JPanel buildMemberEditorPanel(
     462            LeftButtonToolbar leftButtonToolbar, IRelationEditorActionAccess editorAccess) {
    462463        final JPanel pnl = new JPanel(new GridBagLayout());
    463         final JScrollPane scrollPane = new JScrollPane(memberTable);
     464        final JScrollPane scrollPane = new JScrollPane(editorAccess.getMemberTable());
    464465
    465466        GridBagConstraints gc = new GridBagConstraints();
    466467        gc.gridx = 0;
    public class GenericRelationEditor extends RelationEditor { 
    494495        // --- role editing
    495496        JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    496497        p3.add(new JLabel(tr("Apply Role:")));
    497         p3.add(tfRole);
    498         SetRoleAction setRoleAction = new SetRoleAction(memberTable, memberTableModel, tfRole);
    499         memberTableModel.getSelectionModel().addListSelectionListener(setRoleAction);
    500         tfRole.getDocument().addDocumentListener(setRoleAction);
    501         tfRole.addActionListener(setRoleAction);
    502         memberTableModel.getSelectionModel().addListSelectionListener(
    503                 e -> tfRole.setEnabled(memberTable.getSelectedRowCount() > 0)
     498        p3.add(editorAccess.getTextFieldRole());
     499        SetRoleAction setRoleAction = new SetRoleAction(editorAccess);
     500        editorAccess.getMemberTableModel().getSelectionModel().addListSelectionListener(setRoleAction);
     501        editorAccess.getTextFieldRole().getDocument().addDocumentListener(setRoleAction);
     502        editorAccess.getTextFieldRole().addActionListener(setRoleAction);
     503        editorAccess.getMemberTableModel().getSelectionModel().addListSelectionListener(
     504                e -> editorAccess.getTextFieldRole().setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0)
    504505        );
    505         tfRole.setEnabled(memberTable.getSelectedRowCount() > 0);
     506        editorAccess.getTextFieldRole().setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0);
    506507        JButton btnApply = new JButton(setRoleAction);
    507508        btnApply.setPreferredSize(new Dimension(20, 20));
    508509        btnApply.setText("");
    public class GenericRelationEditor extends RelationEditor { 
    536537        gc.anchor = GridBagConstraints.NORTHWEST;
    537538        gc.weightx = 0.0;
    538539        gc.weighty = 1.0;
    539         pnl2.add(new ScrollViewport(buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re),
     540        pnl2.add(new ScrollViewport(buildSelectionControlButtonToolbar(editorAccess),
    540541                ScrollViewport.VERTICAL_DIRECTION), gc);
    541542
    542543        gc.gridx = 1;
    public class GenericRelationEditor extends RelationEditor { 
    544545        gc.weightx = 1.0;
    545546        gc.weighty = 1.0;
    546547        gc.fill = GridBagConstraints.BOTH;
    547         pnl2.add(buildSelectionTablePanel(selectionTable), gc);
     548        pnl2.add(buildSelectionTablePanel(editorAccess.getSelectionTable()), gc);
    548549
    549550        final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    550551        splitPane.setLeftComponent(pnl);
    551552        splitPane.setRightComponent(pnl2);
    552553        splitPane.setOneTouchExpandable(false);
    553         if (re instanceof Window) {
    554             ((Window) re).addWindowListener(new WindowAdapter() {
     554        if (editorAccess.getEditor() instanceof Window) {
     555            ((Window) editorAccess.getEditor()).addWindowListener(new WindowAdapter() {
    555556                @Override
    556557                public void windowOpened(WindowEvent e) {
    557558                    // has to be called when the window is visible, otherwise no effect
    public class GenericRelationEditor extends RelationEditor { 
    607608     * The toolbar with the buttons on the left
    608609     */
    609610    static class LeftButtonToolbar extends JToolBar {
     611                private static final long serialVersionUID = 1L;
    610612
    611         /**
    612          * Button for performing the {@link org.openstreetmap.josm.gui.dialogs.relation.actions.SortBelowAction}.
    613          */
    614         final JButton sortBelowButton;
    615 
    616         /**
     613                /**
    617614         * Constructs a new {@code LeftButtonToolbar}.
    618          * @param memberTable member table
    619          * @param memberTableModel member table model
    620615         * @param re relation editor
    621616         */
    622         LeftButtonToolbar(MemberTable memberTable, MemberTableModel memberTableModel, IRelationEditor re) {
     617        LeftButtonToolbar(IRelationEditorActionAccess editorAccess) {
    623618            setOrientation(JToolBar.VERTICAL);
    624619            setFloatable(false);
    625620
    626             // -- move up action
    627             MoveUpAction moveUpAction = new MoveUpAction(memberTable, memberTableModel, "moveUp");
    628             memberTableModel.getSelectionModel().addListSelectionListener(moveUpAction);
    629             add(moveUpAction);
    630 
    631             // -- move down action
    632             MoveDownAction moveDownAction = new MoveDownAction(memberTable, memberTableModel, "moveDown");
    633             memberTableModel.getSelectionModel().addListSelectionListener(moveDownAction);
    634             add(moveDownAction);
    635 
    636             addSeparator();
    637 
    638             // -- edit action
    639             EditAction editAction = new EditAction(memberTable, memberTableModel, re.getLayer());
    640             memberTableModel.getSelectionModel().addListSelectionListener(editAction);
    641             add(editAction);
    642 
    643             // -- delete action
    644             RemoveAction removeSelectedAction = new RemoveAction(memberTable, memberTableModel, "removeSelected");
    645             memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction);
    646             add(removeSelectedAction);
    647 
    648             addSeparator();
    649             // -- sort action
    650             SortAction sortAction = new SortAction(memberTable, memberTableModel);
    651             memberTableModel.addTableModelListener(sortAction);
    652             add(sortAction);
    653             final SortBelowAction sortBelowAction = new SortBelowAction(memberTable, memberTableModel);
    654             memberTableModel.addTableModelListener(sortBelowAction);
    655             memberTableModel.getSelectionModel().addListSelectionListener(sortBelowAction);
    656             sortBelowButton = add(sortBelowAction);
    657 
    658             // -- reverse action
    659             ReverseAction reverseAction = new ReverseAction(memberTable, memberTableModel);
    660             memberTableModel.addTableModelListener(reverseAction);
    661             add(reverseAction);
    662 
    663             addSeparator();
    664 
    665             // -- download action
    666             DownloadIncompleteMembersAction downloadIncompleteMembersAction = new DownloadIncompleteMembersAction(
    667                     memberTable, memberTableModel, "downloadIncomplete", re.getLayer(), re);
    668             memberTable.getModel().addTableModelListener(downloadIncompleteMembersAction);
    669             add(downloadIncompleteMembersAction);
    670 
    671             // -- download selected action
    672             DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(
    673                     memberTable, memberTableModel, null, re.getLayer(), re);
    674             memberTable.getModel().addTableModelListener(downloadSelectedIncompleteMembersAction);
    675             memberTable.getSelectionModel().addListSelectionListener(downloadSelectedIncompleteMembersAction);
    676             add(downloadSelectedIncompleteMembersAction);
    677 
    678             InputMap inputMap = memberTable.getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    679             inputMap.put((KeyStroke) removeSelectedAction.getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected");
    680             inputMap.put((KeyStroke) moveUpAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveUp");
    681             inputMap.put((KeyStroke) moveDownAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveDown");
    682             inputMap.put((KeyStroke) downloadIncompleteMembersAction.getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete");
     621            List<IRelationEditorActionGroup> groups = new ArrayList<>();
     622            // Move
     623            groups.add(buildNativeGroup(10,
     624                        new MoveUpAction(editorAccess, "moveUp"),
     625                        new MoveDownAction(editorAccess, "moveDown")
     626                        ));
     627            // Edit
     628            groups.add(buildNativeGroup(20,
     629                        new EditAction(editorAccess),
     630                        new RemoveAction(editorAccess, "removeSelected")
     631                        ));
     632            // Sort
     633            groups.add(buildNativeGroup(30,
     634                        new SortAction(editorAccess),
     635                        new SortBelowAction(editorAccess)
     636                        ));
     637            // Reverse
     638            groups.add(buildNativeGroup(40,
     639                        new ReverseAction(editorAccess)
     640                        ));
     641            // Download
     642            groups.add(buildNativeGroup(50,
     643                        new DownloadIncompleteMembersAction(editorAccess, "downloadIncomplete"),
     644                        new DownloadSelectedIncompleteMembersAction(editorAccess)
     645                        ));
     646            groups.addAll(RelationEditorHooks.getMemberActions());
     647           
     648            IRelationEditorActionGroup.fillToolbar(this, groups, editorAccess);
     649           
     650
     651            InputMap inputMap = editorAccess.getMemberTable().getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     652            inputMap.put((KeyStroke) new RemoveAction(editorAccess, "removeSelected").getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected");
     653            inputMap.put((KeyStroke) new MoveUpAction(editorAccess, "moveUp").getValue(AbstractAction.ACCELERATOR_KEY), "moveUp");
     654            inputMap.put((KeyStroke) new MoveDownAction(editorAccess, "moveDown").getValue(AbstractAction.ACCELERATOR_KEY), "moveDown");
     655            inputMap.put((KeyStroke) new DownloadIncompleteMembersAction(
     656                        editorAccess, "downloadIncomplete").getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete");
    683657        }
    684658    }
    685659
    public class GenericRelationEditor extends RelationEditor { 
    692666     *
    693667     * @return control buttons panel for selection/members
    694668     */
    695     protected static JToolBar buildSelectionControlButtonToolbar(MemberTable memberTable,
    696             MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor re) {
     669    protected static JToolBar buildSelectionControlButtonToolbar(IRelationEditorActionAccess editorAccess) {
    697670        JToolBar tb = new JToolBar(JToolBar.VERTICAL);
    698671        tb.setFloatable(false);
    699672
    700         // -- add at start action
    701         AddSelectedAtStartAction addSelectionAction = new AddSelectedAtStartAction(
    702                 memberTableModel, selectionTableModel, re);
    703         selectionTableModel.addTableModelListener(addSelectionAction);
    704         tb.add(addSelectionAction);
    705 
    706         // -- add before selected action
    707         AddSelectedBeforeSelection addSelectedBeforeSelectionAction = new AddSelectedBeforeSelection(
    708                 memberTableModel, selectionTableModel, re);
    709         selectionTableModel.addTableModelListener(addSelectedBeforeSelectionAction);
    710         memberTableModel.getSelectionModel().addListSelectionListener(addSelectedBeforeSelectionAction);
    711         tb.add(addSelectedBeforeSelectionAction);
    712 
    713         // -- add after selected action
    714         AddSelectedAfterSelection addSelectedAfterSelectionAction = new AddSelectedAfterSelection(
    715                 memberTableModel, selectionTableModel, re);
    716         selectionTableModel.addTableModelListener(addSelectedAfterSelectionAction);
    717         memberTableModel.getSelectionModel().addListSelectionListener(addSelectedAfterSelectionAction);
    718         tb.add(addSelectedAfterSelectionAction);
    719 
    720         // -- add at end action
    721         AddSelectedAtEndAction addSelectedAtEndAction = new AddSelectedAtEndAction(
    722                 memberTableModel, selectionTableModel, re);
    723         selectionTableModel.addTableModelListener(addSelectedAtEndAction);
    724         tb.add(addSelectedAtEndAction);
    725 
    726         tb.addSeparator();
    727 
    728         // -- select members action
    729         SelectedMembersForSelectionAction selectMembersForSelectionAction = new SelectedMembersForSelectionAction(
    730                 memberTableModel, selectionTableModel, re.getLayer());
    731         selectionTableModel.addTableModelListener(selectMembersForSelectionAction);
    732         memberTableModel.addTableModelListener(selectMembersForSelectionAction);
    733         tb.add(selectMembersForSelectionAction);
    734 
    735         // -- select action
    736         SelectPrimitivesForSelectedMembersAction selectAction = new SelectPrimitivesForSelectedMembersAction(
    737                 memberTable, memberTableModel, re.getLayer());
    738         memberTable.getSelectionModel().addListSelectionListener(selectAction);
    739         tb.add(selectAction);
    740 
    741         tb.addSeparator();
    742 
    743         // -- remove selected action
    744         RemoveSelectedAction removeSelectedAction = new RemoveSelectedAction(memberTableModel, selectionTableModel, re.getLayer());
    745         selectionTableModel.addTableModelListener(removeSelectedAction);
    746         tb.add(removeSelectedAction);
    747 
     673                List<IRelationEditorActionGroup> groups = new ArrayList<>();
     674                groups.add(buildNativeGroup(10,
     675                                new AddSelectedAtStartAction(editorAccess),
     676                                new AddSelectedBeforeSelection(editorAccess),
     677                                new AddSelectedAfterSelection(editorAccess),
     678                                new AddSelectedAtEndAction(editorAccess)
     679                                ));
     680                groups.add(buildNativeGroup(20,
     681                                new SelectedMembersForSelectionAction(editorAccess),
     682                                new SelectPrimitivesForSelectedMembersAction(editorAccess)
     683                                ));
     684                groups.add(buildNativeGroup(30,
     685                                new RemoveSelectedAction(editorAccess)
     686                                ));
     687                groups.addAll(RelationEditorHooks.getSelectActions());
     688       
     689        IRelationEditorActionGroup.fillToolbar(tb, groups, editorAccess);
    748690        return tb;
    749691    }
     692   
     693    private static IRelationEditorActionGroup buildNativeGroup(int order, AbstractRelationEditorAction... actions) {
     694        return new IRelationEditorActionGroup() {
     695                @Override
     696                public int order() {
     697                        return order;
     698                }
     699               
     700                        @Override
     701                        public List<AbstractRelationEditorAction> getActions(IRelationEditorActionAccess editorAccess) {
     702                                return Arrays.asList(actions);
     703                        }
     704                };
     705    }
    750706
    751707    @Override
    752708    protected Dimension findMaxDialogSize() {
    public class GenericRelationEditor extends RelationEditor { 
    764720        super.setVisible(visible);
    765721        Clipboard clipboard = ClipboardUtils.getClipboard();
    766722        if (visible) {
    767             leftButtonToolbar.sortBelowButton.setVisible(ExpertToggleAction.isExpert());
    768723            RelationDialogManager.getRelationDialogManager().positionOnScreen(this);
    769724            if (windowMenuItem == null) {
    770725                windowMenuItem = addToWindowMenu(this, getLayer().getName());
    public class GenericRelationEditor extends RelationEditor { 
    805760                "dialogs/relationlist",
    806761                tr("Focus Relation Editor with relation ''{0}'' in layer ''{1}''", name, layerName),
    807762                null, false, false) {
    808             @Override
     763                        private static final long serialVersionUID = 1L;
     764
     765                        @Override
    809766            public void actionPerformed(ActionEvent e) {
    810767                ((RelationEditor) getValue("relationEditor")).setVisible(true);
    811768            }
    public class GenericRelationEditor extends RelationEditor { 
    987944        @Override
    988945        public void mouseClicked(MouseEvent e) {
    989946            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
    990                 new EditAction(memberTable, memberTableModel, getLayer()).actionPerformed(null);
     947                new EditAction(new RelationEditorActionAccess()).actionPerformed(null);
    991948            }
    992949        }
    993950    }
     951   
     952    private class RelationEditorActionAccess implements IRelationEditorActionAccess {
     953
     954                @Override
     955                public MemberTable getMemberTable() {
     956                        return memberTable;
     957                }
     958
     959                @Override
     960                public MemberTableModel getMemberTableModel() {
     961                        return memberTableModel;
     962                }
     963
     964                @Override
     965                public SelectionTable getSelectionTable() {
     966                        return selectionTable;
     967                }
     968
     969                @Override
     970                public SelectionTableModel getSelectionTableModel() {
     971                        return selectionTableModel;
     972                }
     973
     974                @Override
     975                public IRelationEditor getEditor() {
     976                        return GenericRelationEditor.this;
     977                }
     978
     979                @Override
     980                public TagEditorModel getTagModel() {
     981                        return tagEditorPanel.getModel();
     982                }
     983
     984                @Override
     985                public AutoCompletingTextField getTextFieldRole() {
     986                        return tfRole;
     987                }
     988       
     989    }
    994990}
  • src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
    index cb2747a..0d17216 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.beans.PropertyChangeListener;
    77import java.beans.PropertyChangeSupport;
    8 import java.lang.reflect.Method;
    9 import java.util.ArrayList;
    108import java.util.Collection;
    11 import java.util.List;
    129
    1310import org.openstreetmap.josm.Main;
    1411import org.openstreetmap.josm.data.osm.Relation;
    import org.openstreetmap.josm.data.osm.RelationMember; 
    1613import org.openstreetmap.josm.gui.ExtendedDialog;
    1714import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1815import org.openstreetmap.josm.tools.CheckParameterUtil;
    19 import org.openstreetmap.josm.tools.Logging;
    2016
    2117/**
    2218 * Abstract relation editor.
    2319 * @since 1599
    2420 */
    2521public abstract class RelationEditor extends ExtendedDialog implements IRelationEditor {
     22        private static final long serialVersionUID = 1L;
    2623
    27     /** the property name for the current relation.
     24        /** the property name for the current relation.
    2825     * @see #setRelation(Relation)
    2926     * @see #getRelation()
    3027     */
    public abstract class RelationEditor extends ExtendedDialog implements IRelation 
    3532     */
    3633    public static final String RELATION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".relationSnapshot";
    3734
    38     /** the list of registered relation editor classes */
    39     private static List<Class<RelationEditor>> editors = new ArrayList<>();
    40 
    4135    /** The relation that this editor is working on. */
    4236    private transient Relation relation;
    4337
    public abstract class RelationEditor extends ExtendedDialog implements IRelation 
    7064    }
    7165
    7266    /**
    73      * Registers a relation editor class. Depending on the type of relation to be edited
    74      * {@link #getEditor(OsmDataLayer, Relation, Collection)} will create an instance of
    75      * this class.
    76      *
    77      * @param clazz the class
    78      */
    79     public void registerRelationEditor(Class<RelationEditor> clazz) {
    80         if (clazz != null && !editors.contains(clazz)) {
    81             editors.add(clazz);
    82         }
    83     }
    84 
    85     /**
    8667     * This is a factory method that creates an appropriate RelationEditor instance suitable for editing the relation
    8768     * that was passed in as an argument.
    8869     *
    89      * This method is guaranteed to return a working RelationEditor. If no specific editor has been registered for the
    90      * type of relation, then a generic editor will be returned.
    91      *
    92      * Editors can be registered by adding their class to the static list "editors" in the RelationEditor class.
    93      * When it comes to editing a relation, all registered editors are queried via their static "canEdit" method whether
    94      * they feel responsible for that kind of relation, and if they return true then an instance of that class will be used.
     70     * This method is guaranteed to return a working RelationEditor.
    9571     *
    9672     * @param layer the data layer the relation is a member of
    9773     * @param r the relation to be edited
    public abstract class RelationEditor extends ExtendedDialog implements IRelation 
    9975     * @return an instance of RelationEditor suitable for editing that kind of relation
    10076     */
    10177    public static RelationEditor getEditor(OsmDataLayer layer, Relation r, Collection<RelationMember> selectedMembers) {
    102         for (Class<RelationEditor> e : editors) {
    103             try {
    104                 Method m = e.getMethod("canEdit", Relation.class);
    105                 Boolean canEdit = (Boolean) m.invoke(null, r);
    106                 if (canEdit) {
    107                     return e.getConstructor(Relation.class, Collection.class).newInstance(layer, r, selectedMembers);
    108                 }
    109             } catch (ReflectiveOperationException ex) {
    110                 Logging.warn(ex);
    111             }
    112         }
    11378        if (RelationDialogManager.getRelationDialogManager().isOpenInEditor(layer, r))
    11479            return RelationDialogManager.getRelationDialogManager().getEditorForRelation(layer, r);
    11580        else {
  • new file src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditorHooks.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditorHooks.java b/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditorHooks.java
    new file mode 100644
    index 0000000..d8f6fb8
    - +  
     1package org.openstreetmap.josm.gui.dialogs.relation;
     2
     3import java.util.Collections;
     4import java.util.List;
     5import java.util.concurrent.CopyOnWriteArrayList;
     6
     7import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionGroup;
     8
     9/**
     10 * This class allows to hook into the relation editor. It can be used to overwrite specific behavior.
     11 *
     12 * @author Michael Zangl
     13 * @since xxx
     14 */
     15public class RelationEditorHooks {
     16       
     17        private static final CopyOnWriteArrayList<IRelationEditorActionGroup> memberActions = new CopyOnWriteArrayList<>();
     18        private static final CopyOnWriteArrayList<IRelationEditorActionGroup> selectionActions = new CopyOnWriteArrayList<>();
     19
     20        private RelationEditorHooks() {
     21                // only static methods.
     22        }
     23       
     24        /**
     25         * Adds actions to the members action toolbar
     26         * @param group The group to add
     27         */
     28        public static void addActionsToMembers(IRelationEditorActionGroup group) {
     29                memberActions.add(group);
     30        }
     31       
     32        /**
     33         * Adds actions to the selection action toolbar
     34         * @param group The group to add
     35         */
     36        public static void addActionsToSelectio(IRelationEditorActionGroup group) {
     37                selectionActions.add(group);
     38        }
     39       
     40        /* package */ static List<IRelationEditorActionGroup> getMemberActions() {
     41                return Collections.unmodifiableList(memberActions);
     42        }
     43       
     44        /* package */ static List<IRelationEditorActionGroup> getSelectActions() {
     45                return Collections.unmodifiableList(selectionActions);
     46        }
     47       
     48}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java
    index a6b6153..e093389 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.dialogs.relation.actions;
    33
     4import java.beans.PropertyChangeEvent;
     5import java.beans.PropertyChangeListener;
     6import java.util.Objects;
     7
    48import javax.swing.AbstractAction;
    59import javax.swing.event.ListSelectionEvent;
    610import javax.swing.event.ListSelectionListener;
    import org.openstreetmap.josm.data.osm.DownloadPolicy; 
    1317import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    1418import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    1519import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
     20import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable;
     21import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    1622import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     23import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    1724import org.openstreetmap.josm.io.OnlineResource;
    1825
    1926/**
    2027 * Abstract superclass of relation editor actions.
     28 *
    2129 * @since 9496
    2230 */
    23 public abstract class AbstractRelationEditorAction extends AbstractAction implements TableModelListener, ListSelectionListener {
    24     protected final MemberTable memberTable;
    25     protected final MemberTableModel memberTableModel;
    26     protected final transient OsmDataLayer layer;
    27     protected final transient IRelationEditor editor;
    28 
    29     protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {
    30         this(memberTable, memberTableModel, actionMapKey, null, null);
    31     }
     31public abstract class AbstractRelationEditorAction extends AbstractAction
     32                implements TableModelListener, ListSelectionListener, PropertyChangeListener {
     33        private static final long serialVersionUID = 1L;
     34        protected final transient IRelationEditorActionAccess editorAccess;
    3235
    33     protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey,
    34             OsmDataLayer layer, IRelationEditor editor) {
    35         this.memberTable = memberTable;
    36         this.memberTableModel = memberTableModel;
    37         this.layer = layer;
    38         this.editor = editor;
    39         if (actionMapKey != null) {
    40             this.memberTable.getActionMap().put(actionMapKey, this);
    41         }
    42     }
     36        /**
     37         * Create a new relation editor action
     38         *
     39         * @param editorAccess
     40         *            The editor this action is for
     41         * @param actionMapKey
     42         *            The key for the member table action map.
     43         * @param updateOn
     44         *            The events that may cause the enabled state of this button to
     45         *            change.
     46         */
     47        protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess,
     48                        IRelationEditorUpdateOn... updateOn) {
     49                Objects.requireNonNull(editorAccess, "editorAccess");
     50                Objects.requireNonNull(updateOn, "updateOn");
     51                this.editorAccess = editorAccess;
     52                for (IRelationEditorUpdateOn u : updateOn) {
     53                        u.register(editorAccess, this);
     54                }
     55        }
    4356
    44     @Override
    45     public void tableChanged(TableModelEvent e) {
    46         updateEnabledState();
    47     }
     57        /**
     58         * Create a new relation editor action
     59         *
     60         * @param editorAccess
     61         *            The editor this action is for
     62         * @param actionMapKey
     63         *            The key for the member table action map.
     64         * @param updateOn
     65         *            The events that may cause the enabled state of this button to
     66         *            change.
     67         */
     68        protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess, String actionMapKey,
     69                        IRelationEditorUpdateOn... updateOn) {
     70                this(editorAccess, updateOn);
     71                Objects.requireNonNull(actionMapKey, "actionMapKey");
     72
     73                this.editorAccess.addMemberTableAction(actionMapKey, this);
     74        }
     75
     76        @Override
     77        public void tableChanged(TableModelEvent e) {
     78                updateEnabledState();
     79        }
     80
     81        @Override
     82        public void valueChanged(ListSelectionEvent e) {
     83                updateEnabledState();
     84        }
    4885
    4986    @Override
    50     public void valueChanged(ListSelectionEvent e) {
     87    public void propertyChange(PropertyChangeEvent evt) {
    5188        updateEnabledState();
    5289    }
    5390
    54     protected abstract void updateEnabledState();
     91        protected abstract void updateEnabledState();
    5592
    56     protected final boolean canDownload() {
    57         if (editor.getRelation() == null)
    58             return false;
    59         DataSet ds = editor.getRelation().getDataSet();
    60         return !Main.isOffline(OnlineResource.OSM_API)
    61             && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
    62     }
     93        protected final boolean canDownload() {
     94                if (editorAccess.getEditor().getRelation() == null)
     95                        return false;
     96                DataSet ds = editorAccess.getEditor().getRelation().getDataSet();
     97                return !Main.isOffline(OnlineResource.OSM_API) && ds != null && !ds.isLocked()
     98                                && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
     99        }
     100
     101        protected MemberTable getMemberTable() {
     102                return editorAccess.getMemberTable();
     103        }
     104
     105        protected MemberTableModel getMemberTableModel() {
     106                return editorAccess.getMemberTableModel();
     107        }
     108
     109        protected SelectionTable getSelectionTable() {
     110                return editorAccess.getSelectionTable();
     111        }
     112
     113        protected SelectionTableModel getSelectionTableModel() {
     114                return editorAccess.getSelectionTableModel();
     115        }
     116
     117        protected IRelationEditor getEditor() {
     118                return editorAccess.getEditor();
     119        }
     120
     121        protected TagEditorModel getTagModel() {
     122                return editorAccess.getTagModel();
     123        }
     124
     125        protected OsmDataLayer getLayer() {
     126                return editorAccess.getEditor().getLayer();
     127        }
     128
     129        public boolean isExpertOnly() {
     130                return false;
     131        }
    63132}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddFromSelectionAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddFromSelectionAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddFromSelectionAction.java
    index 1b0953f..4c6d3fa 100644
    a b import org.openstreetmap.josm.data.osm.Relation; 
    1010import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    1111import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
    1212import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
    13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    16 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable;
    17 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1913
    2014/**
    2115 * Abstract superclass of "Add from selection" actions.
    2216 * @since 9496
    2317 */
    2418abstract class AddFromSelectionAction extends AbstractRelationEditorAction {
     19        private static final long serialVersionUID = 1L;
    2520
    26     protected final SelectionTable selectionTable;
    27     protected final SelectionTableModel selectionTableModel;
    28 
    29     protected AddFromSelectionAction(MemberTable memberTable, MemberTableModel memberTableModel, SelectionTable selectionTable,
    30             SelectionTableModel selectionTableModel, String actionMapKey, OsmDataLayer layer, IRelationEditor editor) {
    31         super(memberTable, memberTableModel, actionMapKey, layer, editor);
    32         this.selectionTable = selectionTable;
    33         this.selectionTableModel = selectionTableModel;
     21    protected AddFromSelectionAction(IRelationEditorActionAccess editorAccess,
     22                        IRelationEditorUpdateOn... updateOn) {
     23        super(editorAccess, updateOn);
    3424    }
    3525
    3626    protected boolean isPotentialDuplicate(OsmPrimitive primitive) {
    37         return memberTableModel.hasMembersReferringTo(Collections.singleton(primitive));
     27        return editorAccess.getMemberTableModel().hasMembersReferringTo(Collections.singleton(primitive));
    3828    }
    3929
    4030    protected List<OsmPrimitive> filterConfirmedPrimitives(List<OsmPrimitive> primitives) throws AddAbortException {
    abstract class AddFromSelectionAction extends AbstractRelationEditorAction { 
    4333        List<OsmPrimitive> ret = new ArrayList<>();
    4434        ConditionalOptionPaneUtil.startBulkOperation("add_primitive_to_relation");
    4535        for (OsmPrimitive primitive : primitives) {
    46             if (primitive instanceof Relation && editor.getRelation() != null && editor.getRelation().equals(primitive)) {
     36            if (primitive instanceof Relation && editorAccess.getEditor().getRelation() != null && editorAccess.getEditor().getRelation().equals(primitive)) {
    4737                GenericRelationEditor.warnOfCircularReferences(primitive);
    4838                continue;
    4939            }
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAfterSelection.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAfterSelection.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAfterSelection.java
    index ca62de2..74a4ef9 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    66import java.awt.event.ActionEvent;
    77
    88import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
    9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    129import org.openstreetmap.josm.tools.ImageProvider;
    1310import org.openstreetmap.josm.tools.Logging;
    1411
    import org.openstreetmap.josm.tools.Logging; 
    1714 * @since 9496
    1815 */
    1916public class AddSelectedAfterSelection extends AddFromSelectionAction {
     17        private static final long serialVersionUID = 1L;
    2018
    2119    /**
    2220     * Constructs a new {@code AddSelectedAfterSelection}.
    public class AddSelectedAfterSelection extends AddFromSelectionAction { 
    2422     * @param selectionTableModel selection table model
    2523     * @param editor relation editor
    2624     */
    27     public AddSelectedAfterSelection(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {
    28         super(null, memberTableModel, null, selectionTableModel, null, null, editor);
     25    public AddSelectedAfterSelection(IRelationEditorActionAccess editorAccess) {
     26        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
    2927        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last selected member"));
    3028        new ImageProvider("dialogs/conflict", "copyaftercurrentright").getResource().attachImageIcon(this, true);
    3129        updateEnabledState();
    public class AddSelectedAfterSelection extends AddFromSelectionAction { 
    3331
    3432    @Override
    3533    protected void updateEnabledState() {
    36         setEnabled(selectionTableModel.getRowCount() > 0 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0);
     34                setEnabled(getSelectionTableModel().getRowCount() > 0
     35                                && getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0);
    3736    }
    3837
    3938    @Override
    4039    public void actionPerformed(ActionEvent e) {
    4140        try {
    42             memberTableModel.addMembersAfterIdx(filterConfirmedPrimitives(selectionTableModel.getSelection()),
    43                     memberTableModel.getSelectionModel().getMaxSelectionIndex());
     41                getMemberTableModel().addMembersAfterIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()),
     42                                getMemberTableModel().getSelectionModel().getMaxSelectionIndex());
    4443        } catch (AddAbortException ex) {
    4544            Logging.trace(ex);
    4645        }
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtEndAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtEndAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtEndAction.java
    index 5e7443f..826ed7d 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    66import java.awt.event.ActionEvent;
    77
    88import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
    9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    129import org.openstreetmap.josm.tools.ImageProvider;
    1310import org.openstreetmap.josm.tools.Logging;
    1411
    import org.openstreetmap.josm.tools.Logging; 
    1714 * @since 9496
    1815 */
    1916public class AddSelectedAtEndAction extends AddFromSelectionAction {
     17        private static final long serialVersionUID = 1L;
    2018
    2119    /**
    2220     * Constructs a new {@code AddSelectedAtEndAction}.
    public class AddSelectedAtEndAction extends AddFromSelectionAction { 
    2422     * @param selectionTableModel selection table model
    2523     * @param editor relation editor
    2624     */
    27     public AddSelectedAtEndAction(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {
    28         super(null, memberTableModel, null, selectionTableModel, null, null, editor);
     25    public AddSelectedAtEndAction(IRelationEditorActionAccess editorAccess) {
     26        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
    2927        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member"));
    3028        new ImageProvider("dialogs/conflict", "copyendright").getResource().attachImageIcon(this, true);
    3129        updateEnabledState();
    public class AddSelectedAtEndAction extends AddFromSelectionAction { 
    3331
    3432    @Override
    3533    protected void updateEnabledState() {
    36         setEnabled(selectionTableModel.getRowCount() > 0);
     34        setEnabled(getSelectionTableModel().getRowCount() > 0);
    3735    }
    3836
    3937    @Override
    4038    public void actionPerformed(ActionEvent e) {
    4139        try {
    42             memberTableModel.addMembersAtEnd(filterConfirmedPrimitives(selectionTableModel.getSelection()));
     40                getMemberTableModel().addMembersAtEnd(filterConfirmedPrimitives(getSelectionTableModel().getSelection()));
    4341        } catch (AddAbortException ex) {
    4442            Logging.trace(ex);
    4543        }
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtStartAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtStartAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtStartAction.java
    index 7b61f32..941f7f9 100644
    a b import org.openstreetmap.josm.tools.Logging; 
    1717 * @since 9496
    1818 */
    1919public class AddSelectedAtStartAction extends AddFromSelectionAction {
     20        private static final long serialVersionUID = 1L;
    2021
    2122    /**
    2223     * Constructs a new {@code AddSelectedAtStartAction}.
    public class AddSelectedAtStartAction extends AddFromSelectionAction { 
    2425     * @param selectionTableModel selection table model
    2526     * @param editor relation editor
    2627     */
    27     public AddSelectedAtStartAction(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {
    28         super(null, memberTableModel, null, selectionTableModel, null, null, editor);
     28    public AddSelectedAtStartAction(IRelationEditorActionAccess editorAccess) {
     29        super(editorAccess);
    2930        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first member"));
    3031        new ImageProvider("dialogs/conflict", "copystartright").getResource().attachImageIcon(this, true);
    3132        updateEnabledState();
    public class AddSelectedAtStartAction extends AddFromSelectionAction { 
    3334
    3435    @Override
    3536    protected void updateEnabledState() {
    36         setEnabled(selectionTableModel.getRowCount() > 0);
     37        setEnabled(getSelectionTableModel().getRowCount() > 0);
    3738    }
    3839
    3940    @Override
    4041    public void actionPerformed(ActionEvent e) {
    4142        try {
    42             memberTableModel.addMembersAtBeginning(filterConfirmedPrimitives(selectionTableModel.getSelection()));
     43                getMemberTableModel().addMembersAtBeginning(filterConfirmedPrimitives(getSelectionTableModel().getSelection()));
    4344        } catch (AddAbortException ex) {
    4445            Logging.trace(ex);
    4546        }
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedBeforeSelection.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedBeforeSelection.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedBeforeSelection.java
    index e32ad3c..c8194a9 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    66import java.awt.event.ActionEvent;
    77
    88import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException;
    9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    129import org.openstreetmap.josm.tools.ImageProvider;
    1310import org.openstreetmap.josm.tools.Logging;
    1411
    import org.openstreetmap.josm.tools.Logging; 
    1714 * @since 9496
    1815 */
    1916public class AddSelectedBeforeSelection extends AddFromSelectionAction {
     17        private static final long serialVersionUID = 1L;
    2018
    2119    /**
    2220     * Constructs a new {@code AddSelectedBeforeSelection}.
    public class AddSelectedBeforeSelection extends AddFromSelectionAction { 
    2422     * @param selectionTableModel selection table model
    2523     * @param editor relation editor
    2624     */
    27     public AddSelectedBeforeSelection(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {
    28         super(null, memberTableModel, null, selectionTableModel, null, null, editor);
     25    public AddSelectedBeforeSelection(IRelationEditorActionAccess editorAccess) {
     26        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
    2927        putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first selected member"));
    3028        new ImageProvider("dialogs/conflict", "copybeforecurrentright").getResource().attachImageIcon(this, true);
    3129        updateEnabledState();
    public class AddSelectedBeforeSelection extends AddFromSelectionAction { 
    3331
    3432    @Override
    3533    protected void updateEnabledState() {
    36         setEnabled(selectionTableModel.getRowCount() > 0 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0);
     34                setEnabled(getSelectionTableModel().getRowCount() > 0
     35                                && editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0);
    3736    }
    3837
    3938    @Override
    4039    public void actionPerformed(ActionEvent e) {
    4140        try {
    42             memberTableModel.addMembersBeforeIdx(filterConfirmedPrimitives(selectionTableModel.getSelection()),
    43                     memberTableModel.getSelectionModel().getMinSelectionIndex());
     41                editorAccess.getMemberTableModel().addMembersBeforeIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()),
     42                                editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex());
    4443        } catch (AddAbortException ex) {
    4544            Logging.trace(ex);
    4645        }
  • 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 90945ed..68a246b 100644
    a b package org.openstreetmap.josm.gui.dialogs.relation.actions; 
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.awt.event.ActionEvent;
    7 import java.beans.PropertyChangeEvent;
    8 import java.beans.PropertyChangeListener;
    97
    10 import javax.swing.event.TableModelEvent;
    11 
    12 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    15 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    16 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    178import org.openstreetmap.josm.tools.ImageProvider;
    189
    1910/**
    2011 * Apply the current updates.
    2112 * @since 9496
    2213 */
    23 public class ApplyAction extends SavingAction implements PropertyChangeListener {
     14public class ApplyAction extends SavingAction {
     15        private static final long serialVersionUID = 1L;
    2416
    2517    /**
    2618     * Constructs a new {@code ApplyAction}.
    public class ApplyAction extends SavingAction implements PropertyChangeListener 
    3022     * @param editor relation editor
    3123     * @param tagModel tag editor model
    3224     */
    33     public ApplyAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
    34             IRelationEditor editor) {
    35         super(memberTable, memberTableModel, tagModel, layer, editor, null);
     25    public ApplyAction(IRelationEditorActionAccess editorAccess) {
     26        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.TAG_CHANGE);
    3627        putValue(SHORT_DESCRIPTION, tr("Apply the current updates"));
    3728        new ImageProvider("save").getResource().attachImageIcon(this, true);
    3829        putValue(NAME, tr("Apply"));
    39         updateEnabledState();
    40         memberTableModel.addTableModelListener(this);
    41         tagModel.addPropertyChangeListener(this);
     30        updateEnabledState();       
    4231    }
    4332
    4433    @Override
    4534    public void actionPerformed(ActionEvent e) {
    4635        if (applyChanges()) {
    47             editor.reloadDataFromRelation();
     36                editorAccess.getEditor().reloadDataFromRelation();
    4837        }
    4938    }
    5039
    public class ApplyAction extends SavingAction implements PropertyChangeListener 
    5241    protected void updateEnabledState() {
    5342        setEnabled(isEditorDirty());
    5443    }
    55 
    56     @Override
    57     public void propertyChange(PropertyChangeEvent evt) {
    58         updateEnabledState();
    59     }
    60 
    61     @Override
    62     public void tableChanged(TableModelEvent e) {
    63         updateEnabledState();
    64     }
    6544}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
    index 24f8502..9a5a0d7 100644
    a b import org.openstreetmap.josm.Main; 
    1212import org.openstreetmap.josm.data.osm.Relation;
    1313import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    1414import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    15 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    16 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    17 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    19 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    20 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2115import org.openstreetmap.josm.spi.preferences.Config;
    2216import org.openstreetmap.josm.tools.ImageProvider;
    2317import org.openstreetmap.josm.tools.InputMapUtils;
    import org.openstreetmap.josm.tools.InputMapUtils; 
    2721 * @since 9496
    2822 */
    2923public class CancelAction extends SavingAction {
     24        private static final long serialVersionUID = 1L;
    3025
    3126    /**
    3227     * Constructs a new {@code CancelAction}.
    public class CancelAction extends SavingAction { 
    3732     * @param editor relation editor
    3833     * @param tfRole role text field
    3934     */
    40     public CancelAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
    41             IRelationEditor editor, AutoCompletingTextField tfRole) {
    42         super(memberTable, memberTableModel, tagModel, layer, editor, tfRole);
     35    public CancelAction(IRelationEditorActionAccess editorAccess) {
     36        super(editorAccess);
    4337        putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog"));
    4438        new ImageProvider("cancel").getResource().attachImageIcon(this);
    4539        putValue(NAME, tr("Cancel"));
    4640
    47         if (editor instanceof RootPaneContainer) {
    48             InputMapUtils.addEscapeAction(((RootPaneContainer) editor).getRootPane(), this);
     41        if (getEditor() instanceof RootPaneContainer) {
     42            InputMapUtils.addEscapeAction(((RootPaneContainer) getEditor()).getRootPane(), this);
    4943        }
    5044        setEnabled(true);
    5145    }
    5246
    5347    @Override
    5448    public void actionPerformed(ActionEvent e) {
    55         memberTable.stopHighlighting();
    56         Relation snapshot = editor.getRelationSnapshot();
    57         if ((!memberTableModel.hasSameMembersAs(snapshot) || tagModel.isDirty())
    58          && !(snapshot == null && tagModel.getTags().isEmpty())) {
     49        getMemberTable().stopHighlighting();
     50        Relation snapshot = getEditor().getRelationSnapshot();
     51        if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty())
     52         && !(snapshot == null && getTagModel().getTags().isEmpty())) {
    5953            //give the user a chance to save the changes
    6054            int ret = confirmClosingByCancel();
    6155            if (ret == 0) { //Yes, save the changes
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/CopyMembersAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CopyMembersAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CopyMembersAction.java
    index 8b8ba36..1bc36f4 100644
    a b import java.util.Collection; 
    77import org.openstreetmap.josm.data.osm.RelationMember;
    88import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    99import org.openstreetmap.josm.gui.datatransfer.RelationMemberTransferable;
    10 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    12 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1310
    1411/**
    1512 * Copy members.
    1613 * @since 9496
    1714 */
    1815public class CopyMembersAction extends AddFromSelectionAction {
     16        private static final long serialVersionUID = 1L;
    1917
    2018    /**
    2119     * Constructs a new {@code CopyMembersAction}.
    public class CopyMembersAction extends AddFromSelectionAction { 
    2321     * @param layer OSM data layer
    2422     * @param editor relation editor
    2523     */
    26     public CopyMembersAction(MemberTableModel memberTableModel, OsmDataLayer layer, IRelationEditor editor) {
    27         super(null, memberTableModel, null, null, null, layer, editor);
     24    public CopyMembersAction(IRelationEditorActionAccess editorAccess) {
     25        super(editorAccess);
    2826    }
    2927
    3028    @Override
    3129    public void actionPerformed(ActionEvent e) {
    32         final Collection<RelationMember> members = memberTableModel.getSelectedMembers();
     30        final Collection<RelationMember> members = getMemberTableModel().getSelectedMembers();
    3331
    3432        if (!members.isEmpty()) {
    3533            ClipboardUtils.copy(new RelationMemberTransferable(members));
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/DeleteCurrentRelationAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DeleteCurrentRelationAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DeleteCurrentRelationAction.java
    index 40f761b..5519109 100644
    a b import java.beans.PropertyChangeListener; 
    1010import org.openstreetmap.josm.actions.mapmode.DeleteAction;
    1111import org.openstreetmap.josm.data.osm.Relation;
    1212import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
    13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    14 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1513import org.openstreetmap.josm.tools.ImageProvider;
    1614
    1715/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1917 * @since 9496
    2018 */
    2119public class DeleteCurrentRelationAction extends AbstractRelationEditorAction implements PropertyChangeListener {
     20        private static final long serialVersionUID = 1L;
    2221
    2322    /**
    2423     * Constructs a new {@code DeleteCurrentRelationAction}.
    2524     * @param layer OSM data layer
    2625     * @param editor relation editor
    2726     */
    28     public DeleteCurrentRelationAction(OsmDataLayer layer, IRelationEditor editor) {
    29         super(null, null, null, layer, editor);
     27    public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) {
     28        super(editorAccess);
    3029        putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation"));
    3130        new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
    3231        putValue(NAME, tr("Delete"));
    public class DeleteCurrentRelationAction extends AbstractRelationEditorAction im 
    3534
    3635    @Override
    3736    public void actionPerformed(ActionEvent e) {
    38         Relation toDelete = editor.getRelation();
     37        Relation toDelete = getEditor().getRelation();
    3938        if (toDelete == null)
    4039            return;
    41         DeleteAction.deleteRelation(layer, toDelete);
     40        DeleteAction.deleteRelation(getLayer(), toDelete);
    4241    }
    4342
    4443    @Override
    4544    protected void updateEnabledState() {
    46         setEnabled(editor.getRelationSnapshot() != null);
     45        setEnabled(getEditor().getRelationSnapshot() != null);
    4746    }
    4847
    4948    @Override
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadIncompleteMembersAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadIncompleteMembersAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadIncompleteMembersAction.java
    index 6cceee2..d9b69d6 100644
    a b import java.awt.event.KeyEvent; 
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.gui.MainApplication;
    1212import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1713import org.openstreetmap.josm.tools.ImageProvider;
    1814import org.openstreetmap.josm.tools.Shortcut;
    1915
    import org.openstreetmap.josm.tools.Shortcut; 
    2218 * @since 9496
    2319 */
    2420public class DownloadIncompleteMembersAction extends AbstractRelationEditorAction {
     21        private static final long serialVersionUID = 1L;
    2522
    2623    /**
    2724     * Constructs a new {@code DownloadIncompleteMembersAction}.
    public class DownloadIncompleteMembersAction extends AbstractRelationEditorActio 
    3128     * @param layer OSM data layer
    3229     * @param editor relation editor
    3330     */
    34     public DownloadIncompleteMembersAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey,
    35             OsmDataLayer layer, IRelationEditor editor) {
    36         super(memberTable, memberTableModel, actionMapKey, layer, editor);
     31    public DownloadIncompleteMembersAction(IRelationEditorActionAccess editorAccess, String actionMapKey) {
     32        super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
    3733        Shortcut sc = Shortcut.registerShortcut("relationeditor:downloadincomplete", tr("Relation Editor: Download Members"),
    3834            KeyEvent.VK_HOME, Shortcut.ALT);
    3935        sc.setAccelerator(this);
    public class DownloadIncompleteMembersAction extends AbstractRelationEditorActio 
    4844        if (!isEnabled())
    4945            return;
    5046        MainApplication.worker.submit(new DownloadRelationMemberTask(
    51                 editor.getRelation(),
    52                 memberTableModel.getIncompleteMemberPrimitives(),
    53                 layer,
    54                 (Dialog) editor)
     47                        getEditor().getRelation(),
     48                getMemberTableModel().getIncompleteMemberPrimitives(),
     49                getLayer(),
     50                (Dialog) getEditor())
    5551        );
    5652    }
    5753
    5854    @Override
    5955    protected void updateEnabledState() {
    60         setEnabled(memberTableModel.hasIncompleteMembers() && canDownload());
     56        setEnabled(getMemberTableModel().hasIncompleteMembers() && canDownload());
    6157    }
    6258}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadSelectedIncompleteMembersAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadSelectedIncompleteMembersAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadSelectedIncompleteMembersAction.java
    index 9a30974..327c7f8 100644
    a b import java.awt.event.ActionEvent; 
    88
    99import org.openstreetmap.josm.gui.MainApplication;
    1010import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    11 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    12 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    14 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1511import org.openstreetmap.josm.tools.ImageProvider;
    1612
    1713/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1915 * @since 9496
    2016 */
    2117public class DownloadSelectedIncompleteMembersAction extends AbstractRelationEditorAction {
     18        private static final long serialVersionUID = 1L;
    2219
    2320    /**
    2421     * Constructs a new {@code DownloadSelectedIncompleteMembersAction}.
    public class DownloadSelectedIncompleteMembersAction extends AbstractRelationEdi 
    2825     * @param layer OSM data layer
    2926     * @param editor relation editor
    3027     */
    31     public DownloadSelectedIncompleteMembersAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey,
    32             OsmDataLayer layer, IRelationEditor editor) {
    33         super(memberTable, memberTableModel, actionMapKey, layer, editor);
     28    public DownloadSelectedIncompleteMembersAction(IRelationEditorActionAccess editorAccess) {
     29        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    3430        putValue(SHORT_DESCRIPTION, tr("Download selected incomplete members"));
    3531        new ImageProvider("dialogs/relation", "downloadincompleteselected").getResource().attachImageIcon(this, true);
    3632        putValue(NAME, tr("Download members"));
    public class DownloadSelectedIncompleteMembersAction extends AbstractRelationEdi 
    4238        if (!isEnabled())
    4339            return;
    4440        MainApplication.worker.submit(new DownloadRelationMemberTask(
    45                 editor.getRelation(),
    46                 memberTableModel.getSelectedIncompleteMemberPrimitives(),
    47                 layer,
    48                 (Dialog) editor)
     41                        getEditor().getRelation(),
     42                getMemberTableModel().getSelectedIncompleteMemberPrimitives(),
     43                getLayer(),
     44                (Dialog) getEditor())
    4945        );
    5046    }
    5147
    5248    @Override
    5349    protected void updateEnabledState() {
    54         setEnabled(memberTableModel.hasIncompleteSelectedMembers() && canDownload());
     50        setEnabled(getMemberTableModel().hasIncompleteSelectedMembers() && canDownload());
    5551    }
    5652}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/DuplicateRelationAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DuplicateRelationAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DuplicateRelationAction.java
    index ce48ae1..91fcbea 100644
    a b import java.awt.GraphicsEnvironment; 
    77import java.awt.event.ActionEvent;
    88
    99import org.openstreetmap.josm.data.osm.Relation;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1110import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    12 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    13 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    1411import org.openstreetmap.josm.tools.ImageProvider;
    1512
    1613/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1815 * @since 9496
    1916 */
    2017public class DuplicateRelationAction extends AbstractRelationEditorAction {
    21 
    22     private final transient TagEditorModel tagEditorModel;
     18        private static final long serialVersionUID = 1L;
    2319
    2420    /**
    2521     * Constructs a new {@code DuplicateRelationAction}.
    public class DuplicateRelationAction extends AbstractRelationEditorAction { 
    2723     * @param tagEditorModel tag editor model
    2824     * @param layer OSM data layer
    2925     */
    30     public DuplicateRelationAction(MemberTableModel memberTableModel, TagEditorModel tagEditorModel, OsmDataLayer layer) {
    31         super(null, memberTableModel, null, layer, null);
    32         this.tagEditorModel = tagEditorModel;
     26    public DuplicateRelationAction(IRelationEditorActionAccess editorAccess) {
     27        super(editorAccess);
    3328        putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
    3429        // FIXME provide an icon
    3530        new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
    public class DuplicateRelationAction extends AbstractRelationEditorAction { 
    4035    @Override
    4136    public void actionPerformed(ActionEvent e) {
    4237        Relation copy = new Relation();
    43         tagEditorModel.applyToPrimitive(copy);
    44         memberTableModel.applyToRelation(copy);
     38        getTagModel().applyToPrimitive(copy);
     39        editorAccess.getMemberTableModel().applyToRelation(copy);
    4540        if (!GraphicsEnvironment.isHeadless()) {
    46             RelationEditor.getEditor(layer, copy, memberTableModel.getSelectedMembers()).setVisible(true);
     41            RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true);
    4742        }
    4843    }
    4944
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/EditAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/EditAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/EditAction.java
    index 44f4a19..26c95ec 100644
    a b import java.util.HashSet; 
    1010import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1111import org.openstreetmap.josm.data.osm.Relation;
    1212import org.openstreetmap.josm.data.osm.RelationMember;
    13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1513import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1714import org.openstreetmap.josm.tools.ImageProvider;
    1815
    1916/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    2118 * @since 9496
    2219 */
    2320public class EditAction extends AbstractRelationEditorAction {
     21        private static final long serialVersionUID = 1L;
    2422
    2523    /**
    2624     * Constructs a new {@code EditAction}.
    public class EditAction extends AbstractRelationEditorAction { 
    2826     * @param memberTableModel member table model
    2927     * @param layer layer
    3028     */
    31     public EditAction(MemberTable memberTable, MemberTableModel memberTableModel, OsmDataLayer layer) {
    32         super(memberTable, memberTableModel, null, layer, null);
     29    public EditAction(IRelationEditorActionAccess editorAccess) {
     30        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    3331        putValue(SHORT_DESCRIPTION, tr("Edit the relation the currently selected relation member refers to"));
    3432        new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true);
    3533        updateEnabledState();
    public class EditAction extends AbstractRelationEditorAction { 
    3735
    3836    @Override
    3937    protected void updateEnabledState() {
    40         setEnabled(memberTable.getSelectedRowCount() == 1
    41                 && memberTableModel.isEditableRelation(memberTable.getSelectedRow()));
     38        setEnabled(editorAccess.getMemberTable().getSelectedRowCount() == 1
     39                                && editorAccess.getMemberTableModel()
     40                                                .isEditableRelation(editorAccess.getMemberTable().getSelectedRow()));
    4241    }
    4342
    4443    protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) {
    4544        Collection<RelationMember> members = new HashSet<>();
    46         Collection<OsmPrimitive> selection = layer.data.getSelected();
     45        Collection<OsmPrimitive> selection = getLayer().data.getSelected();
    4746        for (RelationMember member: r.getMembers()) {
    4847            if (selection.contains(member.getMember())) {
    4948                members.add(member);
    public class EditAction extends AbstractRelationEditorAction { 
    5655    public void actionPerformed(ActionEvent e) {
    5756        if (!isEnabled())
    5857            return;
    59         int idx = memberTable.getSelectedRow();
     58        int idx = editorAccess.getMemberTable().getSelectedRow();
    6059        if (idx < 0)
    6160            return;
    62         OsmPrimitive primitive = memberTableModel.getReferredPrimitive(idx);
     61        OsmPrimitive primitive = editorAccess.getMemberTableModel().getReferredPrimitive(idx);
    6362        if (!(primitive instanceof Relation))
    6463            return;
    6564        Relation r = (Relation) primitive;
    6665        if (r.isIncomplete())
    6766            return;
    6867
    69         RelationEditor.getEditor(layer, r, getMembersForCurrentSelection(r)).setVisible(true);
     68        RelationEditor.getEditor(getLayer(), r, getMembersForCurrentSelection(r)).setVisible(true);
    7069    }
    7170}
  • new file src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java
    new file mode 100644
    index 0000000..e1c507a
    - +  
     1package org.openstreetmap.josm.gui.dialogs.relation.actions;
     2
     3import javax.swing.Action;
     4
     5import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
     6import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
     7import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
     8import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable;
     9import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
     10import org.openstreetmap.josm.gui.tagging.TagEditorModel;
     11import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
     12
     13/**
     14 * This interface provides access to the relation editor for actions.
     15 * <p>
     16 *
     17 * @author Michael Zangl
     18 * @since xxx
     19 */
     20public interface IRelationEditorActionAccess {
     21
     22        /**
     23         * Adds a keyboard action to the member table.
     24         * @param actionMapKey The key to use
     25         * @param action The action to map for that key.
     26         */
     27        default void addMemberTableAction(String actionMapKey, Action action) {
     28                getMemberTable().getActionMap().put(actionMapKey, action);
     29        }
     30
     31        /**
     32         * Get the member table that is used by the dialog.
     33         * @return The member table
     34         */
     35        MemberTable getMemberTable();
     36       
     37        /**
     38         * Get the model the member table is using.
     39         * @return That model
     40         */
     41        MemberTableModel getMemberTableModel();
     42       
     43        /**
     44         * Get the table that displays the current user selection
     45         * @return That table
     46         */
     47        SelectionTable getSelectionTable();
     48       
     49        /**
     50         * Get the model that the selection table is based on.
     51         * @return The model
     52         */
     53    SelectionTableModel getSelectionTableModel();
     54   
     55    IRelationEditor getEditor();
     56    TagEditorModel getTagModel();
     57   
     58    /**
     59     * Get the text field that is used to edit the role.
     60     * @return The role text field.
     61     */
     62    AutoCompletingTextField getTextFieldRole();
     63}
  • new file src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionGroup.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionGroup.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionGroup.java
    new file mode 100644
    index 0000000..3dc443d
    - +  
     1package org.openstreetmap.josm.gui.dialogs.relation.actions;
     2
     3import java.util.Comparator;
     4import java.util.List;
     5
     6import javax.swing.JButton;
     7import javax.swing.JToolBar;
     8
     9import org.openstreetmap.josm.actions.ExpertToggleAction;
     10
     11/**
     12 * An action group for the relation editor, to be used in one of the tool bars.
     13 *
     14 * @author Michael Zangl
     15 * @since xxx
     16 */
     17public interface IRelationEditorActionGroup {
     18
     19        /**
     20         * Get the position at which the action group should be added.
     21         *
     22         * @return The order index, default is to add at the end.
     23         */
     24        default int order() {
     25                return 100;
     26        }
     27
     28        /**
     29         * Get the actions in this action group.
     30         *
     31         * @param editorAccess
     32         *            Methods to access the relation editor.
     33         * @return The actions
     34         */
     35        List<AbstractRelationEditorAction> getActions(IRelationEditorActionAccess editorAccess);
     36
     37        static void fillToolbar(JToolBar toolbar, List<IRelationEditorActionGroup> groups,
     38                        IRelationEditorActionAccess editorAccess) {
     39                groups.stream().sorted(Comparator.comparingInt(IRelationEditorActionGroup::order)).forEach(group -> {
     40                        if (toolbar.getComponentCount() > 0) {
     41                                toolbar.addSeparator();
     42                        }
     43
     44                        for (AbstractRelationEditorAction action : group.getActions(editorAccess)) {
     45                                JButton button = toolbar.add(action);
     46                                if (action.isExpertOnly()) {
     47                                        ExpertToggleAction.addVisibilitySwitcher(button);
     48                                }
     49                        }
     50                });
     51        }
     52}
  • new file src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorUpdateOn.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorUpdateOn.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorUpdateOn.java
    new file mode 100644
    index 0000000..78e8e66
    - +  
     1package org.openstreetmap.josm.gui.dialogs.relation.actions;
     2
     3/**
     4 * This interface can be used to register the event listeners for a
     5 * {@link AbstractRelationEditorAction}.
     6 * <p>
     7 * It holds common constants that are often used.
     8 *
     9 * @author Michael Zangl
     10 * @since xxx
     11 */
     12@FunctionalInterface
     13public interface IRelationEditorUpdateOn {
     14        /**
     15         * Update when the member table contents change
     16         */
     17        IRelationEditorUpdateOn MEMBER_TABLE_CHANGE = (editor, action) -> editor.getMemberTableModel()
     18                        .addTableModelListener(action);
     19        /**
     20         * Update upon a member table selection change
     21         */
     22        IRelationEditorUpdateOn MEMBER_TABLE_SELECTION = (editor, action) -> editor.getMemberTable().getSelectionModel()
     23                        .addListSelectionListener(action);
     24
     25        IRelationEditorUpdateOn TAG_CHANGE = (editor, action) -> editor.getTagModel().addPropertyChangeListener(action);
     26        IRelationEditorUpdateOn SELECTION_TABLE_CHANGE = (editor, action) -> editor.getSelectionTableModel()
     27                        .addTableModelListener(action);
     28
     29        void register(IRelationEditorActionAccess editor, AbstractRelationEditorAction action);
     30}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveDownAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveDownAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveDownAction.java
    index ec691e6..69c84c3 100644
    a b import java.awt.event.ActionEvent; 
    77import java.awt.event.KeyEvent;
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1210import org.openstreetmap.josm.tools.ImageProvider;
    1311import org.openstreetmap.josm.tools.Shortcut;
    1412
    import org.openstreetmap.josm.tools.Shortcut; 
    1715 * @since 9496
    1816 */
    1917public class MoveDownAction extends AbstractRelationEditorAction {
     18        private static final long serialVersionUID = 1L;
    2019
    2120    /**
    2221     * Constructs a new {@code MoveDownAction}.
    public class MoveDownAction extends AbstractRelationEditorAction { 
    2423     * @param memberTableModel member table model
    2524     * @param actionMapKey action map key
    2625     */
    27     public MoveDownAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {
    28         super(memberTable, memberTableModel, actionMapKey);
     26    public MoveDownAction(IRelationEditorActionAccess editorAccess, String actionMapKey) {
     27        super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    2928        new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this, true);
    3029        Shortcut sc = Shortcut.registerShortcut("relationeditor:movedown", tr("Relation Editor: Move Down"), KeyEvent.VK_DOWN, Shortcut.ALT);
    3130        sc.setAccelerator(this);
    public class MoveDownAction extends AbstractRelationEditorAction { 
    3534
    3635    @Override
    3736    public void actionPerformed(ActionEvent e) {
    38         memberTableModel.moveDown(memberTable.getSelectedRows());
     37        editorAccess.getMemberTableModel().moveDown(editorAccess.getMemberTable().getSelectedRows());
    3938    }
    4039
    4140    @Override
    4241    protected void updateEnabledState() {
    43         setEnabled(memberTableModel.canMoveDown(memberTable.getSelectedRows()));
     42        setEnabled(editorAccess.getMemberTableModel().canMoveDown(editorAccess.getMemberTable().getSelectedRows()));
    4443    }
    4544}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveUpAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveUpAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveUpAction.java
    index aceb7f5..0f84f98 100644
    a b import java.awt.event.ActionEvent; 
    77import java.awt.event.KeyEvent;
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1210import org.openstreetmap.josm.tools.ImageProvider;
    1311import org.openstreetmap.josm.tools.Shortcut;
    1412
    import org.openstreetmap.josm.tools.Shortcut; 
    1715 * @since 9496
    1816 */
    1917public class MoveUpAction extends AbstractRelationEditorAction {
     18        private static final long serialVersionUID = 1L;
    2019
    2120    /**
    2221     * Constructs a new {@code MoveUpAction}.
    public class MoveUpAction extends AbstractRelationEditorAction { 
    2423     * @param memberTableModel member table model
    2524     * @param actionMapKey key in table action map
    2625     */
    27     public MoveUpAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {
    28         super(memberTable, memberTableModel, actionMapKey);
     26    public MoveUpAction(IRelationEditorActionAccess editorAccess, String actionMapKey) {
     27        super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    2928        new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this, true);
    3029        Shortcut sc = Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Up"), KeyEvent.VK_UP, Shortcut.ALT);
    3130        sc.setAccelerator(this);
    public class MoveUpAction extends AbstractRelationEditorAction { 
    3534
    3635    @Override
    3736    public void actionPerformed(ActionEvent e) {
    38         memberTableModel.moveUp(memberTable.getSelectedRows());
     37        editorAccess.getMemberTableModel().moveUp(editorAccess.getMemberTable().getSelectedRows());
    3938    }
    4039
    4140    @Override
    4241    protected void updateEnabledState() {
    43         setEnabled(memberTableModel.canMoveUp(memberTable.getSelectedRows()));
     42        setEnabled(editorAccess.getMemberTableModel().canMoveUp(editorAccess.getMemberTable().getSelectedRows()));
    4443    }
    4544}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/OKAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/OKAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/OKAction.java
    index 6317915..f821791 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    12 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    148import org.openstreetmap.josm.spi.preferences.Config;
    159import org.openstreetmap.josm.tools.ImageProvider;
    1610
    import org.openstreetmap.josm.tools.ImageProvider; 
    1812 * Apply the updates and close the dialog.
    1913 */
    2014public class OKAction extends SavingAction {
     15        private static final long serialVersionUID = 1L;
    2116
    2217    /**
    2318     * Constructs a new {@code OKAction}.
    public class OKAction extends SavingAction { 
    2823     * @param editor relation editor
    2924     * @param tfRole role text field
    3025     */
    31     public OKAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
    32             IRelationEditor editor, AutoCompletingTextField tfRole) {
    33         super(memberTable, memberTableModel, tagModel, layer, editor, tfRole);
     26    public OKAction(IRelationEditorActionAccess editorAccess) {
     27        super(editorAccess);
    3428        putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog"));
    3529        new ImageProvider("ok").getResource().attachImageIcon(this);
    3630        putValue(NAME, tr("OK"));
    public class OKAction extends SavingAction { 
    4034    @Override
    4135    public void actionPerformed(ActionEvent e) {
    4236        Config.getPref().put("relation.editor.generic.lastrole", tfRole.getText());
    43         memberTable.stopHighlighting();
     37        editorAccess.getMemberTable().stopHighlighting();
    4438        if (!applyChanges())
    4539            return;
    4640        hideEditor();
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/PasteMembersAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/PasteMembersAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/PasteMembersAction.java
    index dd0d969..7c92ad4 100644
    a b import java.util.Optional; 
    99import javax.swing.TransferHandler.TransferSupport;
    1010
    1111import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    12 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    1412import org.openstreetmap.josm.gui.dialogs.relation.MemberTransferHandler;
    15 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1613import org.openstreetmap.josm.tools.Logging;
    1714
    1815/**
    import org.openstreetmap.josm.tools.Logging; 
    2017 * @since 9496
    2118 */
    2219public class PasteMembersAction extends AddFromSelectionAction implements FlavorListener {
     20        private static final long serialVersionUID = 1L;
    2321
    2422    /**
    2523     * Constructs a new {@code PasteMembersAction}.
    public class PasteMembersAction extends AddFromSelectionAction implements Flavor 
    2725     * @param layer OSM data layer
    2826     * @param editor relation editor
    2927     */
    30     public PasteMembersAction(MemberTable memberTable, OsmDataLayer layer, IRelationEditor editor) {
    31         super(memberTable, null, null, null, null, layer, editor);
     28    public PasteMembersAction(IRelationEditorActionAccess editorAccess) {
     29        super(editorAccess);
    3230        updateEnabledState();
    3331    }
    3432
    public class PasteMembersAction extends AddFromSelectionAction implements Flavor 
    4240    }
    4341
    4442    private TransferSupport getSupport() {
    45         return new TransferSupport(memberTable, Optional.ofNullable(ClipboardUtils.getClipboardContent())
     43        return new TransferSupport(editorAccess.getMemberTable(), Optional.ofNullable(ClipboardUtils.getClipboardContent())
    4644                .orElseThrow(() -> new IllegalStateException("Failed to retrieve clipboard content")));
    4745    }
    4846
  • 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 d43e736..3b286a3 100644
    a b import org.openstreetmap.josm.data.osm.Relation; 
    1515import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    1616import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    1717import org.openstreetmap.josm.gui.MainApplication;
    18 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    19 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    20 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    21 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    22 import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    2318import org.openstreetmap.josm.tools.ImageProvider;
    2419import org.openstreetmap.josm.tools.Shortcut;
    2520
    import org.openstreetmap.josm.tools.Shortcut; 
    2823 * @since 9657
    2924 */
    3025public class RefreshAction extends SavingAction implements CommandQueueListener {
     26        private static final long serialVersionUID = 1L;
    3127
    3228    /**
    3329     * Constructs a new {@code RefreshAction}.
    public class RefreshAction extends SavingAction implements CommandQueueListener 
    3733     * @param editor relation editor
    3834     * @param tagModel tag editor model
    3935     */
    40     public RefreshAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer,
    41             IRelationEditor editor) {
    42         super(memberTable, memberTableModel, tagModel, layer, editor, null);
     36    public RefreshAction(IRelationEditorActionAccess editorAccess) {
     37        super(editorAccess);
    4338        // CHECKSTYLE.OFF: LineLength
    4439        Shortcut sc = Shortcut.registerShortcut("relationeditor:refresh", tr("Relation Editor: Refresh"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
    4540        // CHECKSTYLE.ON: LineLength
    4641        putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tr("Refresh relation from data layer"), sc));
    4742        new ImageProvider("dialogs/refresh").getResource().attachImageIcon(this, true);
    4843        putValue(NAME, tr("Refresh"));
    49         if (editor instanceof JComponent) {
    50             ((JComponent) editor).getRootPane().getActionMap().put("refresh", this);
    51             ((JComponent) editor).getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh");
     44        if (editorAccess.getEditor() instanceof JComponent) {
     45            ((JComponent) editorAccess.getEditor()).getRootPane().getActionMap().put("refresh", this);
     46            ((JComponent) editorAccess.getEditor()).getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh");
    5247        }
    5348        MainApplication.undoRedo.addCommandQueueListener(this);
    5449        updateEnabledState();
    public class RefreshAction extends SavingAction implements CommandQueueListener 
    5651
    5752    @Override
    5853    public void actionPerformed(ActionEvent e) {
    59         Relation relation = editor.getRelation();
     54        Relation relation = editorAccess.getEditor().getRelation();
    6055        if (relation == null)
    6156            return;
    6257        if (relation.isDeleted()) {
    public class RefreshAction extends SavingAction implements CommandQueueListener 
    6762        }
    6863        if (isEditorDirty() && confirmDiscardDirtyData() != 0)
    6964            return;
    70         editor.reloadDataFromRelation();
     65        editorAccess.getEditor().reloadDataFromRelation();
    7166    }
    7267
    7368    @Override
    7469    public void updateEnabledState() {
    75         Relation relation = editor.getRelation();
    76         Relation snapshot = editor.getRelationSnapshot();
     70        Relation relation = editorAccess.getEditor().getRelation();
     71        Relation snapshot = editorAccess.getEditor().getRelationSnapshot();
    7772        setEnabled(snapshot != null && (
    7873            !relation.hasEqualTechnicalAttributes(snapshot) ||
    7974            !relation.hasEqualSemanticAttributes(snapshot)
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveAction.java
    index fc09cf2..ba0b5db 100644
    a b import java.awt.event.ActionEvent; 
    77import java.awt.event.KeyEvent;
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1210import org.openstreetmap.josm.tools.ImageProvider;
    1311import org.openstreetmap.josm.tools.Shortcut;
    1412
    import org.openstreetmap.josm.tools.Shortcut; 
    1715 * @since 9496
    1816 */
    1917public class RemoveAction extends AbstractRelationEditorAction {
     18        private static final long serialVersionUID = 1L;
    2019
    2120    /**
    2221     * Constructs a new {@code RemoveAction}.
    public class RemoveAction extends AbstractRelationEditorAction { 
    2423     * @param memberTableModel member table model
    2524     * @param actionMapKey action map key
    2625     */
    27     public RemoveAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {
    28         super(memberTable, memberTableModel, actionMapKey);
     26    public RemoveAction(IRelationEditorActionAccess editorAccess, String actionMapKey) {
     27        super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    2928        new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
    3029        putValue(NAME, tr("Remove"));
    3130        Shortcut sc = Shortcut.registerShortcut("relationeditor:remove", tr("Relation Editor: Remove"), KeyEvent.VK_DELETE, Shortcut.ALT);
    public class RemoveAction extends AbstractRelationEditorAction { 
    3635
    3736    @Override
    3837    public void actionPerformed(ActionEvent e) {
    39         memberTableModel.remove(memberTable.getSelectedRows());
     38        editorAccess.getMemberTableModel().remove(editorAccess.getMemberTable().getSelectedRows());
    4039    }
    4140
    4241    @Override
    4342    protected void updateEnabledState() {
    44         setEnabled(memberTableModel.canRemove(memberTable.getSelectedRows()));
     43        setEnabled(editorAccess.getMemberTableModel().canRemove(editorAccess.getMemberTable().getSelectedRows()));
    4544    }
    4645}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveSelectedAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveSelectedAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveSelectedAction.java
    index f92c586..013a7aa 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    66import java.awt.event.ActionEvent;
    77
    88import org.openstreetmap.josm.data.osm.DataSet;
    9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    10 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    129import org.openstreetmap.josm.tools.ImageProvider;
    1310
    1411/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1613 * @since 9496
    1714 */
    1815public class RemoveSelectedAction extends AddFromSelectionAction {
     16        private static final long serialVersionUID = 1L;
    1917
    2018    /**
    2119     * Constructs a new {@code RemoveSelectedAction}.
    public class RemoveSelectedAction extends AddFromSelectionAction { 
    2321     * @param selectionTableModel selection table model
    2422     * @param layer OSM data layer
    2523     */
    26     public RemoveSelectedAction(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, OsmDataLayer layer) {
    27         super(null, memberTableModel, null, selectionTableModel, null, layer, null);
     24    public RemoveSelectedAction(IRelationEditorActionAccess editorAccess) {
     25        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE);
    2826        putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected objects"));
    2927        new ImageProvider("dialogs/relation", "deletemembers").getResource().attachImageIcon(this, true);
    3028        updateEnabledState();
    public class RemoveSelectedAction extends AddFromSelectionAction { 
    3230
    3331    @Override
    3432    protected void updateEnabledState() {
    35         DataSet ds = layer.data;
     33        DataSet ds = getLayer().data;
    3634        if (ds == null || ds.selectionEmpty()) {
    3735            setEnabled(false);
    3836            return;
    3937        }
    4038        // only enable the action if we have members referring to the selected primitives
    41         setEnabled(memberTableModel.hasMembersReferringTo(ds.getSelected()));
     39        setEnabled(editorAccess.getMemberTableModel().hasMembersReferringTo(ds.getSelected()));
    4240    }
    4341
    4442    @Override
    4543    public void actionPerformed(ActionEvent e) {
    46         memberTableModel.removeMembersReferringTo(selectionTableModel.getSelection());
     44        editorAccess.getMemberTableModel().removeMembersReferringTo(getSelectionTableModel().getSelection());
    4745    }
    4846}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/ReverseAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ReverseAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ReverseAction.java
    index 9fa0534..2c8f01e 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    108import org.openstreetmap.josm.tools.ImageProvider;
    119
    1210/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1412 * @since 9496
    1513 */
    1614public class ReverseAction extends AbstractRelationEditorAction {
     15        private static final long serialVersionUID = 1L;
    1716
    1817    /**
    1918     * Constructs a new {@code ReverseAction}.
    20      * @param memberTable member table
    21      * @param memberTableModel member table model
     19     * @param editorAccess
    2220     */
    23     public ReverseAction(MemberTable memberTable, MemberTableModel memberTableModel) {
    24         super(memberTable, memberTableModel, null);
     21    public ReverseAction(IRelationEditorActionAccess editorAccess) {
     22        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
     23
    2524        putValue(SHORT_DESCRIPTION, tr("Reverse the order of the relation members"));
    2625        new ImageProvider("dialogs/relation", "reverse").getResource().attachImageIcon(this, true);
    2726        putValue(NAME, tr("Reverse"));
    public class ReverseAction extends AbstractRelationEditorAction { 
    3029
    3130    @Override
    3231    public void actionPerformed(ActionEvent e) {
    33         memberTableModel.reverse();
     32        editorAccess.getMemberTableModel().reverse();
    3433    }
    3534
    3635    @Override
    3736    protected void updateEnabledState() {
    38         setEnabled(memberTableModel.getRowCount() > 0);
     37        setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0);
    3938    }
    4039}
  • 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 6d333c0..ca2d2a3 100644
    a b import org.openstreetmap.josm.data.osm.RelationMember; 
    2121import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    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;
    3228import org.openstreetmap.josm.tools.ImageProvider;
    import org.openstreetmap.josm.tools.Utils; 
    3733 * @since 9496
    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
    5145    /**
    abstract class SavingAction extends AbstractRelationEditorAction { 
    5549    protected void applyNewRelation(TagEditorModel tagEditorModel) {
    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()) {
    6155            if (!rm.getMember().isDeleted()) {
    abstract class SavingAction extends AbstractRelationEditorAction { 
    7266        // tags, don't add an empty relation
    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
    8579        SwingUtilities.invokeLater(() -> MainApplication.getMap().relationListDialog.selectRelation(newRelation));
    abstract class SavingAction extends AbstractRelationEditorAction { 
    9084     * @param tagEditorModel tag editor model
    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
    10094    /**
    abstract class SavingAction extends AbstractRelationEditorAction { 
    10296     * @param tagEditorModel tag editor model
    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));
    111105        }
    abstract class SavingAction extends AbstractRelationEditorAction { 
    152146                tr("<html>Layer ''{0}'' already has a conflict for object<br>"
    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"),
    159153                JOptionPane.WARNING_MESSAGE
    abstract class SavingAction extends AbstractRelationEditorAction { 
    166160    }
    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}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectAction.java
    index 14c8d25..6bb04ef 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    66import java.awt.event.ActionEvent;
    77
    88import org.openstreetmap.josm.data.osm.Relation;
    9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    119import org.openstreetmap.josm.tools.ImageProvider;
    1210
    1311/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1513 * @since 12933
    1614 */
    1715public class SelectAction extends AbstractRelationEditorAction {
     16        private static final long serialVersionUID = 1L;
    1817
    1918    /**
    2019     * Constructs a new {@code SelectAction}.
    2120     * @param layer OSM data layer
    2221     * @param editor relation editor
    2322     */
    24     public SelectAction(OsmDataLayer layer, IRelationEditor editor) {
    25         super(null, null, null, layer, editor);
     23    public SelectAction(IRelationEditorActionAccess editorAccess) {
     24        super(editorAccess);
    2625        putValue(NAME, tr("Select"));
    2726        putValue(SHORT_DESCRIPTION, tr("Select the currently edited relation"));
    2827        new ImageProvider("dialogs", "select").getResource().attachImageIcon(this, true);
    public class SelectAction extends AbstractRelationEditorAction { 
    3130
    3231    @Override
    3332    public void actionPerformed(ActionEvent e) {
    34         Relation toSelect = editor.getRelation();
     33        Relation toSelect = editorAccess.getEditor().getRelation();
    3534        if (toSelect == null)
    3635            return;
    37         layer.data.setSelected(toSelect);
     36        getLayer().data.setSelected(toSelect);
    3837    }
    3938
    4039    @Override
    4140    protected void updateEnabledState() {
    42         setEnabled(editor.getRelationSnapshot() != null);
     41        setEnabled(editorAccess.getEditor().getRelationSnapshot() != null);
    4342    }
    4443}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectPrimitivesForSelectedMembersAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectPrimitivesForSelectedMembersAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectPrimitivesForSelectedMembersAction.java
    index 6a5fe0f..fc998a2 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    118import org.openstreetmap.josm.tools.ImageProvider;
    129
    1310/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1613 * @since 9496
    1714 */
    1815public class SelectPrimitivesForSelectedMembersAction extends AbstractRelationEditorAction {
     16        private static final long serialVersionUID = 1L;
    1917
    2018    /**
    2119     * Select objects for selected relation members.
    public class SelectPrimitivesForSelectedMembersAction extends AbstractRelationEd 
    2321     * @param memberTableModel member table model
    2422     * @param layer layer
    2523     */
    26     public SelectPrimitivesForSelectedMembersAction(MemberTable memberTable, MemberTableModel memberTableModel, OsmDataLayer layer) {
    27         super(memberTable, memberTableModel, null, layer, null);
     24    public SelectPrimitivesForSelectedMembersAction(IRelationEditorActionAccess editorAccess) {
     25        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    2826        putValue(SHORT_DESCRIPTION, tr("Select objects for selected relation members"));
    2927        new ImageProvider("dialogs/relation", "selectprimitives").getResource().attachImageIcon(this, true);
    3028        updateEnabledState();
    public class SelectPrimitivesForSelectedMembersAction extends AbstractRelationEd 
    3230
    3331    @Override
    3432    protected void updateEnabledState() {
    35         setEnabled(memberTable.getSelectedRowCount() > 0);
     33        setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0);
    3634    }
    3735
    3836    @Override
    3937    public void actionPerformed(ActionEvent e) {
    40         layer.data.setSelected(memberTableModel.getSelectedChildPrimitives());
     38        getLayer().data.setSelected(editorAccess.getMemberTableModel().getSelectedChildPrimitives());
    4139    }
    4240}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectedMembersForSelectionAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectedMembersForSelectionAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectedMembersForSelectionAction.java
    index 642c0be..0f905ba 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    9 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
    10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    118import org.openstreetmap.josm.tools.ImageProvider;
    129
    1310/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1512 * @since 9496
    1613 */
    1714public class SelectedMembersForSelectionAction extends AddFromSelectionAction {
     15        private static final long serialVersionUID = 1L;
    1816
    1917    /**
    2018     * Constructs a new {@code SelectedMembersForSelectionAction}.
    public class SelectedMembersForSelectionAction extends AddFromSelectionAction { 
    2220     * @param selectionTableModel selection table model
    2321     * @param layer OSM data layer
    2422     */
    25     public SelectedMembersForSelectionAction(MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, OsmDataLayer layer) {
    26         super(null, memberTableModel, null, selectionTableModel, null, layer, null);
     23    public SelectedMembersForSelectionAction(IRelationEditorActionAccess editorAccess) {
     24        super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
    2725        putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection"));
    2826        new ImageProvider("dialogs/relation", "selectmembers").getResource().attachImageIcon(this, true);
    2927        updateEnabledState();
    public class SelectedMembersForSelectionAction extends AddFromSelectionAction { 
    3129
    3230    @Override
    3331    protected void updateEnabledState() {
    34         boolean enabled = selectionTableModel.getRowCount() > 0
    35         && !memberTableModel.getChildPrimitives(layer.data.getSelected()).isEmpty();
     32        boolean enabled = getSelectionTableModel().getRowCount() > 0
     33        && !editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).isEmpty();
    3634
    3735        if (enabled) {
    3836            putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to {0} objects in the current selection",
    39                     memberTableModel.getChildPrimitives(layer.data.getSelected()).size()));
     37                        editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).size()));
    4038        } else {
    4139            putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection"));
    4240        }
    public class SelectedMembersForSelectionAction extends AddFromSelectionAction { 
    4543
    4644    @Override
    4745    public void actionPerformed(ActionEvent e) {
    48         memberTableModel.selectMembersReferringTo(layer.data.getSelected());
     46        editorAccess.getMemberTableModel().selectMembersReferringTo(getLayer().data.getSelected());
    4947    }
    5048}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SetRoleAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SetRoleAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SetRoleAction.java
    index 0d42ba7..07a0df2 100644
    a b import javax.swing.event.DocumentListener; 
    1212
    1313import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
    15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    16 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1715import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    1816import org.openstreetmap.josm.tools.ImageProvider;
    1917
    import org.openstreetmap.josm.tools.ImageProvider; 
    2220 * @since 9496
    2321 */
    2422public class SetRoleAction extends AbstractRelationEditorAction implements DocumentListener {
     23        private static final long serialVersionUID = 1L;
    2524
    2625    private final transient AutoCompletingTextField tfRole;
    2726
    public class SetRoleAction extends AbstractRelationEditorAction implements Docum 
    3130     * @param memberTableModel member table model
    3231     * @param tfRole role text field
    3332     */
    34     public SetRoleAction(MemberTable memberTable, MemberTableModel memberTableModel, AutoCompletingTextField tfRole) {
    35         super(memberTable, memberTableModel, null);
    36         this.tfRole = tfRole;
     33    public SetRoleAction(IRelationEditorActionAccess editorAccess) {
     34        super(editorAccess);
     35        this.tfRole = editorAccess.getTextFieldRole();
    3736        putValue(SHORT_DESCRIPTION, tr("Sets a role for the selected members"));
    3837        new ImageProvider("apply").getResource().attachImageIcon(this);
    3938        putValue(NAME, tr("Apply Role"));
    public class SetRoleAction extends AbstractRelationEditorAction implements Docum 
    4241
    4342    @Override
    4443    protected void updateEnabledState() {
    45         setEnabled(memberTable.getSelectedRowCount() > 0);
     44        setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0);
    4645    }
    4746
    4847    protected boolean isEmptyRole() {
    public class SetRoleAction extends AbstractRelationEditorAction implements Docum 
    8281
    8382    @Override
    8483    public void actionPerformed(ActionEvent e) {
    85         if (isEmptyRole() && !confirmSettingEmptyRole(memberTable.getSelectedRowCount())) {
     84        if (isEmptyRole() && !confirmSettingEmptyRole(editorAccess.getMemberTable().getSelectedRowCount())) {
    8685            return;
    8786        }
    88         memberTableModel.updateRole(memberTable.getSelectedRows(), tfRole.getText());
     87        editorAccess.getMemberTableModel().updateRole(editorAccess.getMemberTable().getSelectedRows(), tfRole.getText());
    8988    }
    9089
    9190    @Override
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortAction.java
    index 49cf2bb..c70ce9f 100644
    a b import java.awt.event.ActionEvent; 
    77import java.awt.event.KeyEvent;
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1210import org.openstreetmap.josm.tools.ImageProvider;
    1311import org.openstreetmap.josm.tools.Shortcut;
    1412
    import org.openstreetmap.josm.tools.Shortcut; 
    1715 * @since 9496
    1816 */
    1917public class SortAction extends AbstractRelationEditorAction {
     18        private static final long serialVersionUID = 1L;
    2019
    2120    /**
    2221     * Constructs a new {@code SortAction}.
    2322     * @param memberTable member table
    2423     * @param memberTableModel member table model
    2524     */
    26     public SortAction(MemberTable memberTable, MemberTableModel memberTableModel) {
    27         super(memberTable, memberTableModel, null);
     25    public SortAction(IRelationEditorActionAccess editorAccess) {
     26        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE);
    2827        new ImageProvider("dialogs", "sort").getResource().attachImageIcon(this, true);
    2928        putValue(NAME, tr("Sort"));
    3029        Shortcut sc = Shortcut.registerShortcut("relationeditor:sort", tr("Relation Editor: Sort"), KeyEvent.VK_END, Shortcut.ALT);
    public class SortAction extends AbstractRelationEditorAction { 
    3534
    3635    @Override
    3736    public void actionPerformed(ActionEvent e) {
    38         memberTableModel.sort();
     37        editorAccess.getMemberTableModel().sort();
    3938    }
    4039
    4140    @Override
    4241    protected void updateEnabledState() {
    43         setEnabled(memberTableModel.getRowCount() > 0);
     42        setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0);
    4443    }
    4544}
  • src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortBelowAction.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortBelowAction.java b/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortBelowAction.java
    index b7ea8d4..35812eb 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    108import org.openstreetmap.josm.tools.ImageProvider;
    119
    1210/**
    import org.openstreetmap.josm.tools.ImageProvider; 
    1412 * @since 9496
    1513 */
    1614public class SortBelowAction extends AbstractRelationEditorAction {
     15        private static final long serialVersionUID = 1L;
    1716
    1817    /**
    1918     * Constructs a new {@code SortBelowAction}.
    2019     * @param memberTable member table
    2120     * @param memberTableModel member table model
    2221     */
    23     public SortBelowAction(MemberTable memberTable, MemberTableModel memberTableModel) {
    24         super(memberTable, memberTableModel, null);
     22    public SortBelowAction(IRelationEditorActionAccess editorAccess) {
     23        super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION);
    2524        new ImageProvider("dialogs", "sort_below").getResource().attachImageIcon(this, true);
    2625        putValue(NAME, tr("Sort below"));
    2726        putValue(SHORT_DESCRIPTION, tr("Sort the selected relation members and all members below"));
    public class SortBelowAction extends AbstractRelationEditorAction { 
    3029
    3130    @Override
    3231    public void actionPerformed(ActionEvent e) {
    33         memberTableModel.sortBelow();
     32        editorAccess.getMemberTableModel().sortBelow();
    3433    }
    3534
    3635    @Override
    3736    protected void updateEnabledState() {
    38         setEnabled(memberTableModel.getRowCount() > 0 && !memberTableModel.getSelectionModel().isSelectionEmpty());
     37        setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0 && !editorAccess.getMemberTableModel().getSelectionModel().isSelectionEmpty());
     38    }
     39   
     40    @Override
     41    public boolean isExpertOnly() {
     42        return true;
    3943    }
    4044}
  • test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java
    index 5ad6461..26fbbfd 100644
    a b public class GenericRelationEditorTest { 
    117117        SelectionTableModel selectionTableModel = new SelectionTableModel(layer);
    118118        SelectionTable selectionTable = new SelectionTable(selectionTableModel, memberTableModel);
    119119
    120         LeftButtonToolbar leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, re);
    121         assertNotNull(leftButtonToolbar.sortBelowButton);
    122 
    123120        AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re);
    124121        assertNotNull(tfRole);
    125122
    126123        TagEditorPanel tagEditorPanel = new TagEditorPanel(relation, null);
    127124
    128125        JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel);
    129         JPanel bottom = GenericRelationEditor.buildMemberEditorPanel(
    130                 memberTable, memberTableModel, selectionTable, selectionTableModel, re, leftButtonToolbar, tfRole);
    131126        assertNotNull(top);
    132         assertNotNull(bottom);
    133         assertNotNull(GenericRelationEditor.buildSplitPane(top, bottom, re));
    134 
    135127        TagEditorModel tagModel = tagEditorPanel.getModel();
    136128
    137         assertNotNull(GenericRelationEditor.buildOkCancelButtonPanel(
    138                 new OKAction(memberTable, memberTableModel, tagModel, layer, re, tfRole),
    139                 new CancelAction(memberTable, memberTableModel, tagModel, layer, re, tfRole)));
    140         assertNotNull(GenericRelationEditor.buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re));
    141         assertNotNull(GenericRelationEditor.buildSelectionTablePanel(selectionTable));
    142 
    143         assertNotNull(GenericRelationEditor.buildToolBar(
    144                 new RefreshAction(memberTable, memberTableModel, tagModel, layer, re),
    145                 new ApplyAction(memberTable, memberTableModel, tagModel, layer, re),
    146                 new SelectAction(layer, re),
    147                 new DuplicateRelationAction(memberTableModel, tagModel, layer),
    148                 new DeleteCurrentRelationAction(layer, re)));
    149129    }
    150130}