Ticket #7846: 7846_refactor.patch

File 7846_refactor.patch, 38.7 KB (added by Don-vip, 12 years ago)

Refactorization needed for xml-imagery-bounds and tag2link plugins

  • core/src/org/openstreetmap/josm/actions/data/NodeAction.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions.data;
     3
     4import java.util.Collection;
     5
     6import javax.swing.Action;
     7
     8import org.openstreetmap.josm.data.osm.Node;
     9
     10/**
     11 * Interface used to enable/disable all node-related actions, even those registered by plugins.
     12 * @since 5805
     13 */
     14public interface NodeAction extends Action {
     15
     16    /**
     17     * Specifies the working set of nodes.
     18     * @param nodes The new working set of nodes. Can be null or empty
     19     */
     20    public abstract void setNodes(Collection<Node> nodes);
     21}
  • core/src/org/openstreetmap/josm/actions/data/RelationAction.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions.data;
     3
     4import java.util.Collection;
     5
     6import javax.swing.Action;
     7
     8import org.openstreetmap.josm.data.osm.Relation;
     9
     10/**
     11 * Interface used to enable/disable all relation-related actions, even those registered by plugins.
     12 * @since 5805
     13 */
     14public interface RelationAction extends Action {
     15
     16    /**
     17     * Specifies the working set of relations.
     18     * @param relations The new working set of relations. Can be null or empty
     19     */
     20    public abstract void setRelations(Collection<Relation> relations);
     21}
  • core/src/org/openstreetmap/josm/actions/data/WayAction.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions.data;
     3
     4import java.util.Collection;
     5
     6import javax.swing.Action;
     7
     8import org.openstreetmap.josm.data.osm.Way;
     9
     10/**
     11 * Interface used to enable/disable all way-related actions, even those registered by plugins.
     12 * @since 5805
     13 */
     14public interface WayAction extends Action {
     15
     16    /**
     17     * Specifies the working set of ways.
     18     * @param ways The new working set of ways. Can be null or empty
     19     */
     20    public abstract void setWays(Collection<Way> ways);
     21}
  • core/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java

     
    66
    77import javax.swing.AbstractAction;
    88
     9import org.openstreetmap.josm.actions.data.RelationAction;
    910import org.openstreetmap.josm.data.osm.Relation;
    1011
    1112/**
     
    1314 * to be disabled is the collection is empty
    1415 * @since 5793
    1516 */
    16 public abstract class AbstractRelationAction extends AbstractAction {
     17public abstract class AbstractRelationAction extends AbstractAction implements RelationAction {
    1718    protected Collection<Relation> relations = Collections.<Relation>emptySet();
    1819
    19     /**
    20      * Specifies the working set of relations.
    21      * @param relations The new working set of relations. Can be null or empty
     20    /* (non-Javadoc)
     21     * @see org.openstreetmap.josm.actions.relation.RelationAction#setRelations(java.util.Collection)
    2222     */
     23    @Override
    2324    public void setRelations(Collection<Relation> relations) {
    2425        if (relations==null) {
    2526            this.relations = Collections.<Relation>emptySet();
  • core/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

     
    1616 * @since 5799
    1717 */
    1818public class DuplicateRelationAction extends AbstractRelationAction {
     19   
     20    /**
     21     * Constructs a new {@code DuplicateRelationAction}.
     22     */
    1923    public DuplicateRelationAction() {
    2024        putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
    2125        putValue(SMALL_ICON, ImageProvider.get("duplicate"));
  • core/src/org/openstreetmap/josm/gui/DataActionPopupMenuHandler.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui;
     3
     4import java.util.Collection;
     5import java.util.Collections;
     6import java.util.HashSet;
     7import java.util.Set;
     8
     9import javax.swing.Action;
     10import javax.swing.JMenuItem;
     11import javax.swing.JPopupMenu;
     12import javax.swing.MenuElement;
     13import javax.swing.event.PopupMenuListener;
     14
     15import org.openstreetmap.josm.actions.data.NodeAction;
     16import org.openstreetmap.josm.actions.data.RelationAction;
     17import org.openstreetmap.josm.actions.data.WayAction;
     18import org.openstreetmap.josm.actions.relation.DownloadMembersAction;
     19import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
     20import org.openstreetmap.josm.actions.relation.EditRelationAction;
     21import org.openstreetmap.josm.actions.relation.SelectInRelationListAction;
     22import org.openstreetmap.josm.actions.relation.SelectMembersAction;
     23import org.openstreetmap.josm.actions.relation.SelectRelationAction;
     24import org.openstreetmap.josm.data.osm.Node;
     25import org.openstreetmap.josm.data.osm.Relation;
     26import org.openstreetmap.josm.data.osm.Way;
     27
     28/**
     29 * Handler to ease management of osm primitives related actions in all different popup menus.
     30 * @since 5805
     31 */
     32public class DataActionPopupMenuHandler {
     33
     34    // Pre-defined relation actions
     35    private SelectRelationAction selectRelationAction;
     36    private SelectRelationAction addRelationToSelectionAction;
     37    private SelectMembersAction selectMembersAction;
     38    private SelectMembersAction addMembersToSelectionAction;
     39    private SelectInRelationListAction selectInRelationListAction;
     40    private EditRelationAction editRelationAction;
     41    private DownloadMembersAction downloadMembersAction;
     42    private DownloadSelectedIncompleteMembersAction downloadIncompleteMembersAction;
     43
     44    // Set of enabled node, way and relation actions
     45    private final Set<NodeAction> nodeActions = new HashSet<NodeAction>();
     46    private final Set<WayAction> wayActions = new HashSet<WayAction>();
     47    private final Set<RelationAction> relationActions = new HashSet<RelationAction>();
     48    // Managed menu
     49    private final JPopupMenu menu;
     50   
     51    /**
     52     * Constructs a new {@code RelationActionMenuHandler} for the specified popup menu.
     53     *
     54     * @param menu The menu to be managed
     55     */
     56    public DataActionPopupMenuHandler(JPopupMenu menu) {
     57        this.menu = menu;
     58    }
     59   
     60    /**
     61     * Enables the action "Select relation" which can be then accessed with the method {@code #getSelectRelationAction()}
     62     * @see #getSelectRelationAction
     63     */
     64    public void enableSelectRelationAction() {
     65        if (selectRelationAction == null) {
     66            addAction(selectRelationAction = new SelectRelationAction(false));
     67        }
     68    }
     69   
     70    /**
     71     * Enables the action "Select relation (add)" which can be then accessed with the method {@code #getAddRelationToSelectionAction()}
     72     * @see #getAddRelationToSelectionAction
     73     */
     74    public void enableAddRelationToSelectionAction() {
     75        if (addRelationToSelectionAction == null) {
     76            addAction(addRelationToSelectionAction = new SelectRelationAction(true));
     77        }
     78    }
     79   
     80    /**
     81     * Enables the action "Select members" which can be then accessed with the method {@code #getSelectMembersAction()}
     82     * @see #getSelectMembersAction
     83     */
     84    public void enableSelectMembersAction() {
     85        if (selectMembersAction == null) {
     86            addAction(selectMembersAction = new SelectMembersAction(false));
     87        }
     88    }
     89   
     90    /**
     91     * Enables the action "Select members (add)" which can be then accessed with the method {@code #getAddMembersToSelectionAction()}
     92     * @see #getAddMembersToSelectionAction
     93     */
     94    public void enableAddMembersToSelectionAction() {
     95        if (addMembersToSelectionAction == null) {
     96            addAction(addMembersToSelectionAction = new SelectMembersAction(true));
     97        }
     98    }
     99   
     100    /**
     101     * Enables the action "Select in relation list" which can be then accessed with the method {@code #getSelectInRelationListAction()}
     102     * @see #getSelectInRelationListAction
     103     */
     104    public void enableSelectInRelationListAction() {
     105        if (selectInRelationListAction == null) {
     106            addAction(selectInRelationListAction = new SelectInRelationListAction());
     107        }
     108    }
     109   
     110    /**
     111     * Enables the action "Edit relation" which can be then accessed with the method {@code #getEditRelationAction()}
     112     * @see #getEditRelationAction
     113     */
     114    public void enableEditRelationAction() {
     115        if (editRelationAction == null) {
     116            addAction(editRelationAction = new EditRelationAction());
     117        }
     118    }
     119   
     120    /**
     121     * Enables the action "Download members" which can be then accessed with the method {@code #getDownloadMembersAction()}
     122     * @see #getDownloadMembersAction
     123     */
     124    public void enableDownloadMembersAction() {
     125        if (downloadMembersAction == null) {
     126            addAction(downloadMembersAction = new DownloadMembersAction());
     127        }
     128    }
     129   
     130    /**
     131     * Enables the action "Download incomplete members" which can be then accessed with the method {@code #getDownloadSelectedIncompleteMembersAction()}
     132     * @see #getDownloadSelectedIncompleteMembersAction
     133     */
     134    public void enableDownloadIncompleteMembersAction() {
     135        if (downloadIncompleteMembersAction == null) {
     136            addAction(downloadIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction());
     137        }
     138    }
     139
     140    /**
     141     * Appends a new separator at the end of the menu.
     142     * @see JPopupMenu#addSeparator
     143     */
     144    public void addSeparator() {
     145        menu.addSeparator();
     146    }
     147
     148    /**
     149     * Appends a new menu item to the end of the menu which dispatches the specified <code>Action</code> object.
     150     *
     151     * @param a the <code>Action</code> to add to the menu
     152     * @return the new menu item
     153     * @see JPopupMenu#add(Action)
     154     */
     155    public JMenuItem addAction(Action a) {
     156        if (a != null) {
     157            if (a instanceof NodeAction) {
     158                nodeActions.add((NodeAction) a);
     159            }
     160            if (a instanceof WayAction) {
     161                wayActions.add((WayAction) a);
     162            }
     163            if (a instanceof RelationAction) {
     164                relationActions.add((RelationAction) a);
     165            }
     166            return menu.add(a);
     167        }
     168        return null;
     169    }
     170
     171    /**
     172     * Removes the menu item which dispatches the specified <code>Action</code> object.
     173     *
     174     * @param a the <code>Action</code> to remove from the menu
     175     * @see JPopupMenu#remove(int)
     176     */
     177    public void removeAction(Action a) {
     178        if (a != null) {
     179            if (a instanceof NodeAction) {
     180                nodeActions.remove(a);
     181            }
     182            if (a instanceof WayAction) {
     183                wayActions.remove(a);
     184            }
     185            if (a instanceof RelationAction) {
     186                relationActions.remove(a);
     187            }
     188            MenuElement[] elements = menu.getSubElements();
     189            for (int i=0; i<elements.length; i++) {
     190                if (elements[i] instanceof JMenuItem) {
     191                    if (((JMenuItem) elements[i]).getAction() == a) {
     192                        menu.remove(i);
     193                        return;
     194                    }
     195                }
     196            }
     197        }
     198    }
     199
     200    /**
     201     *  Adds a <code>PopupMenu</code> listener.
     202     *
     203     *  @param l the <code>PopupMenuListener</code> to add
     204     *  @see JPopupMenu#addPopupMenuListener
     205     */
     206    public void addListener(PopupMenuListener l) {
     207        menu.addPopupMenuListener(l);
     208    }
     209
     210    /**
     211     * Removes a <code>PopupMenu</code> listener.
     212     *
     213     * @param l the <code>PopupMenuListener</code> to remove
     214     *  @see JPopupMenu#removePopupMenuListener
     215     */
     216    public void removeListener(PopupMenuListener l) {
     217        menu.removePopupMenuListener(l);
     218    }
     219   
     220    /**
     221     * Returns all enabled node actions.
     222     * @return All node actions that have been added.
     223     * @see #addAction(Action)
     224     */
     225    public Collection<NodeAction> getNodeActions() {
     226        return Collections.unmodifiableCollection(nodeActions);
     227    }
     228
     229    /**
     230     * Returns all enabled way actions.
     231     * @return All way actions that have been added.
     232     * @see #addAction(Action)
     233     */
     234    public Collection<WayAction> getWayActions() {
     235        return Collections.unmodifiableCollection(wayActions);
     236    }
     237
     238    /**
     239     * Returns all enabled relation actions.
     240     * @return All relation actions that have been added or enabled.
     241     * @see #addAction(Action)
     242     * @see #enableAddMembersToSelectionAction()
     243     * @see #enableAddRelationToSelectionAction()
     244     * @see #enableDownloadIncompleteMembersAction()
     245     * @see #enableEditRelationAction()
     246     * @see #enableSelectInRelationListAction()
     247     * @see #enableSelectMembersAction()
     248     * @see #enableSelectRelationAction()
     249     */
     250    public Collection<RelationAction> getRelationActions() {
     251        return Collections.unmodifiableCollection(relationActions);
     252    }
     253   
     254    /**
     255     * Specifies the working set of nodes for all node actions.
     256     * @param nodes The new working set of nodes. Can be null or empty
     257     * @see NodeAction#setNodes
     258     */
     259    public void setNodes(Collection<Node> nodes) {
     260        for (NodeAction action : nodeActions) {
     261            action.setNodes(nodes);
     262        }
     263    }
     264   
     265    /**
     266     * Specifies the working set of ways for all way actions.
     267     * @param ways The new working set of ways. Can be null or empty
     268     * @see WayAction#setWays
     269     */
     270    public void setWays(Collection<Way> ways) {
     271        for (WayAction action : wayActions) {
     272            action.setWays(ways);
     273        }
     274    }
     275   
     276    /**
     277     * Specifies the working set of relations for all relation actions.
     278     * @param relations The new working set of relations. Can be null or empty
     279     * @see RelationAction#setRelations
     280     */
     281    public void setRelations(Collection<Relation> relations) {
     282        for (RelationAction action : relationActions) {
     283            action.setRelations(relations);
     284        }
     285    }
     286
     287    /**
     288     * Replies the "Select relation (add)" action.
     289     * @return the "Select relation (add)" action, if previously enabled, {@code null} otherwise.
     290     * @see #enableAddRelationToSelectionAction
     291     */
     292    public final SelectRelationAction getAddRelationToSelectionAction() {
     293        return addRelationToSelectionAction;
     294    }
     295
     296    /**
     297     * Replies the "Select members (add)" action.
     298     * @return the "Select members (add)" action, if previously enabled, {@code null} otherwise.
     299     * @see #enableAddMembersToSelectionAction
     300     */
     301    public final SelectMembersAction getAddMembersToSelectionAction() {
     302        return addMembersToSelectionAction;
     303    }
     304
     305    /**
     306     * Replies the "Select relation" action.
     307     * @return the "Select relation" action, if previously enabled, {@code null} otherwise.
     308     * @see #enableSelectRelationAction
     309     */
     310    public final SelectRelationAction getSelectRelationAction() {
     311        return selectRelationAction;
     312    }
     313
     314    /**
     315     * Replies the "Select in relation list" action.
     316     * @return the "Select in relation list" action, if previously enabled, {@code null} otherwise.
     317     * @see #enableSelectInRelationListAction
     318     */
     319    public final SelectInRelationListAction getSelectInRelationListAction() {
     320        return selectInRelationListAction;
     321    }
     322
     323    /**
     324     * Replies the "Edit relation" action.
     325     * @return the "Edit relation" action, if previously enabled, {@code null} otherwise.
     326     * @see #enableEditRelationAction
     327     */
     328    public final EditRelationAction getEditRelationAction() {
     329        return editRelationAction;
     330    }
     331
     332    /**
     333     * Replies the "Select members" action.
     334     * @return the "Select members" action, if previously enabled, {@code null} otherwise.
     335     * @see #enableSelectMembersAction
     336     */
     337    public final SelectMembersAction getSelectMembersAction() {
     338        return selectMembersAction;
     339    }
     340
     341    /**
     342     * Replies the "Download members" action.
     343     * @return the "Download members" action, if previously enabled, {@code null} otherwise.
     344     * @see #enableDownloadMembersAction
     345     */
     346    public final DownloadMembersAction getDownloadMembersAction() {
     347        return downloadMembersAction;
     348    }
     349   
     350    /**
     351     * Replies the "Download incomplete members" action.
     352     * @return the "Download incomplete members" action, if previously enabled, {@code null} otherwise.
     353     * @see #enableDownloadIncompleteMembersAction
     354     */
     355    public final DownloadSelectedIncompleteMembersAction getDownloadSelectedIncompleteMembersAction() {
     356        return downloadIncompleteMembersAction;
     357    }
     358}
  • core/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

     
    2121
    2222import javax.swing.AbstractAction;
    2323import javax.swing.AbstractListModel;
    24 import javax.swing.Action;
    2524import javax.swing.DefaultListSelectionModel;
    2625import javax.swing.JComponent;
    2726import javax.swing.JList;
    28 import javax.swing.JMenuItem;
    2927import javax.swing.JPanel;
    3028import javax.swing.JPopupMenu;
    3129import javax.swing.JScrollPane;
     
    3836import javax.swing.event.DocumentListener;
    3937import javax.swing.event.ListSelectionEvent;
    4038import javax.swing.event.ListSelectionListener;
    41 import javax.swing.event.PopupMenuListener;
    4239
    4340import org.openstreetmap.josm.Main;
     41import org.openstreetmap.josm.actions.data.RelationAction;
    4442import org.openstreetmap.josm.actions.relation.AddSelectionToRelations;
    4543import org.openstreetmap.josm.actions.relation.DeleteRelationsAction;
    46 import org.openstreetmap.josm.actions.relation.DownloadMembersAction;
    47 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    4844import org.openstreetmap.josm.actions.relation.DuplicateRelationAction;
    4945import org.openstreetmap.josm.actions.relation.EditRelationAction;
    50 import org.openstreetmap.josm.actions.relation.SelectMembersAction;
    5146import org.openstreetmap.josm.actions.relation.SelectRelationAction;
    5247import org.openstreetmap.josm.actions.search.SearchCompiler;
    5348import org.openstreetmap.josm.data.osm.DataSet;
     
    6459import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
    6560import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    6661import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     62import org.openstreetmap.josm.gui.DataActionPopupMenuHandler;
    6763import org.openstreetmap.josm.gui.DefaultNameFormatter;
    6864import org.openstreetmap.josm.gui.MapView;
    6965import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     
    9490
    9591    private final NewAction newAction;
    9692   
    97     /** the popup menu */
    98     private final RelationDialogPopupMenu popupMenu;
     93    /** the popup menu and its handler */
     94    private final JPopupMenu popupMenu;
     95    private final DataActionPopupMenuHandler popupMenuHandler;
    9996
    10097    private final JTextField filter;
    10198   
    102     // Actions
     99    // Actions specific to this dialog (other may be found inside popupMenu.handler)
    103100    /** the edit action */
    104101    private final EditRelationAction editAction = new EditRelationAction();
    105102    /** the delete action */
    106103    private final DeleteRelationsAction deleteRelationsAction = new DeleteRelationsAction();
    107104    /** the duplicate action */
    108105    private final DuplicateRelationAction duplicateAction = new DuplicateRelationAction();
    109     private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction();
    110     private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction();
    111     private final SelectMembersAction selectMemebersAction = new SelectMembersAction(false);
    112     private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true);
    113     private final SelectRelationAction selectRelationAction = new SelectRelationAction(false);
    114     private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true);
    115     /** add all selected primitives to the given realtions */
     106    /** add all selected primitives to the given relations */
    116107    private final AddSelectionToRelations addSelectionToRelations = new AddSelectionToRelations();
    117108   
    118109    /**
     
    153144                updateActionsRelationLists();
    154145            }
    155146        });
     147
     148        // Create popup menu and relation actions
     149        popupMenu = new JPopupMenu();
     150        popupMenuHandler = setupPopupMenuHandler();
     151       
     152        SelectRelationAction selectRelationAction = popupMenuHandler.getSelectRelationAction();
    156153       
    157154        JPanel pane = new JPanel(new BorderLayout());
    158155        pane.add(filter, BorderLayout.NORTH);
     
    174171        // Select relation on Ctrl-Enter
    175172        InputMapUtils.addEnterAction(displaylist, selectRelationAction);
    176173
    177         popupMenu = new RelationDialogPopupMenu();
    178 
    179174        // Edit relation on Ctrl-Enter
    180175        displaylist.getActionMap().put("edit", editAction);
    181176        displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), "edit");
     
    185180   
    186181    // inform all actions about list of relations they need
    187182    private void updateActionsRelationLists() {
    188         List<Relation> rels;
    189         rels = model.getSelectedNonNewRelations();
    190         downloadMembersAction.setRelations(rels);
    191 
    192         rels = model.getSelectedRelationsWithIncompleteMembers();
    193         downloadSelectedIncompleteMembersAction.setRelations(rels);
    194 
    195         rels = model.getSelectedRelations();
    196         editAction.setRelations(rels);
    197         deleteRelationsAction.setRelations(rels);
    198         addSelectionToRelations.setRelations(rels);
    199         selectMemebersAction.setRelations(rels);
    200         addMembersToSelectionAction.setRelations(rels);
    201         selectRelationAction.setRelations(rels);
    202         addRelationToSelectionAction.setRelations(rels);
    203         duplicateAction.setRelations(rels);
     183        List<Relation> rels = model.getSelectedRelations();
     184        for (RelationAction relAction : popupMenuHandler.getRelationActions()) {
     185            if (relAction == popupMenuHandler.getDownloadMembersAction()) {
     186                relAction.setRelations(model.getSelectedNonNewRelations());
     187            } else if (relAction == popupMenuHandler.getDownloadSelectedIncompleteMembersAction()) {
     188                relAction.setRelations(model.getSelectedRelationsWithIncompleteMembers());
     189            } else {
     190                relAction.setRelations(rels);
     191            }
     192        }
    204193    }
    205194   
    206195    @Override public void showNotify() {
     
    655644        }
    656645    }
    657646
    658     class RelationDialogPopupMenu extends JPopupMenu {
    659 
    660         public RelationDialogPopupMenu() {
    661             // -- download members action
    662             add(downloadMembersAction);
     647    private final DataActionPopupMenuHandler setupPopupMenuHandler() {
     648        DataActionPopupMenuHandler handler = new DataActionPopupMenuHandler(popupMenu);
     649       
     650        // -- download members action
     651        handler.enableDownloadMembersAction();
    663652
    664             // -- download incomplete members action
    665             add(downloadSelectedIncompleteMembersAction);
     653        // -- download incomplete members action
     654        handler.enableDownloadIncompleteMembersAction();
    666655
    667             addSeparator();
     656        handler.addSeparator();
    668657
    669             // -- select members action
    670             add(selectMemebersAction);
    671             add(addMembersToSelectionAction);
     658        // -- select members action
     659        handler.enableSelectMembersAction();
     660        handler.enableAddMembersToSelectionAction();
    672661
    673             // -- select action
    674             add(selectRelationAction);
    675             add(addRelationToSelectionAction);
     662        // -- select action
     663        handler.enableSelectRelationAction();
     664        handler.enableAddRelationToSelectionAction();
    676665
    677             addSeparator();
     666        handler.addSeparator();
    678667
    679             add(addSelectionToRelations);
    680         }
     668        handler.addAction(addSelectionToRelations);
     669       
     670        return handler;
    681671    }
    682 
     672   
    683673    /* ---------------------------------------------------------------------------------- */
    684     /* Methods that can be called from plugins                                                                    */
     674    /* Methods that can be called from plugins                                            */
    685675    /* ---------------------------------------------------------------------------------- */
    686676
    687     public void addPopupMenuSeparator() {
    688         popupMenu.addSeparator();
    689     }
    690 
    691     public JMenuItem addPopupMenuAction(Action a) {
    692         return popupMenu.add(a);
    693     }
    694 
    695     public void addPopupMenuListener(PopupMenuListener l) {
    696         popupMenu.addPopupMenuListener(l);
    697     }
    698 
    699     public void removePopupMenuListener(PopupMenuListener l) {
    700         popupMenu.addPopupMenuListener(l);
     677    public DataActionPopupMenuHandler getPopupMenuHandler() {
     678        return popupMenuHandler;
    701679    }
    702680
    703681    public Collection<Relation> getSelectedRelations() {
  • core/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

     
    2323
    2424import javax.swing.AbstractAction;
    2525import javax.swing.AbstractListModel;
    26 import javax.swing.Action;
    2726import javax.swing.DefaultListSelectionModel;
    2827import javax.swing.JList;
    2928import javax.swing.JMenuItem;
     
    3433import javax.swing.event.ListDataListener;
    3534import javax.swing.event.ListSelectionEvent;
    3635import javax.swing.event.ListSelectionListener;
    37 import javax.swing.event.PopupMenuListener;
    3836
    3937import org.openstreetmap.josm.Main;
    4038import org.openstreetmap.josm.actions.AutoScaleAction;
    41 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    42 import org.openstreetmap.josm.actions.relation.EditRelationAction;
    43 import org.openstreetmap.josm.actions.relation.SelectInRelationListAction;
     39import org.openstreetmap.josm.actions.data.RelationAction;
    4440import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    4541import org.openstreetmap.josm.data.SelectionChangedListener;
    4642import org.openstreetmap.josm.data.osm.Node;
     
    6258import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    6359import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    6460import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     61import org.openstreetmap.josm.gui.DataActionPopupMenuHandler;
    6562import org.openstreetmap.josm.gui.DefaultNameFormatter;
    6663import org.openstreetmap.josm.gui.MapView;
    6764import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     
    8784    private SearchAction actSearch;
    8885    private ZoomToJOSMSelectionAction actZoomToJOSMSelection;
    8986    private ZoomToListSelection actZoomToListSelection;
    90     private SelectInRelationListAction actSetRelationSelection;
    91     private EditRelationAction actEditRelationSelection;
    92     private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers;
    9387
    94     private SelectionPopup popupMenu;
     88    /** the popup menu and its handler */
     89    private final ListPopupMenu popupMenu;
     90    private final DataActionPopupMenuHandler popupMenuHandler;
    9591
    9692    /**
    9793     * Builds the content panel for this dialog
     
    143139        model.addListDataListener(actZoomToJOSMSelection);
    144140
    145141        actZoomToListSelection = new ZoomToListSelection();
    146         actSetRelationSelection = new SelectInRelationListAction();
    147         actEditRelationSelection = new EditRelationAction();
    148         actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
     142
     143        popupMenu = new ListPopupMenu(lstPrimitives);
     144        popupMenuHandler = setupPopupMenuHandler();
    149145
    150146        lstPrimitives.addListSelectionListener(new ListSelectionListener() {
    151147            @Override
    152148            public void valueChanged(ListSelectionEvent e) {
    153149                actZoomToListSelection.valueChanged(e);
    154                 List<Relation> rels;
    155                 rels = model.getSelectedRelationsWithIncompleteMembers();
    156                 actDownloadSelectedIncompleteMembers.setRelations(rels);
    157                 rels = OsmPrimitive.getFilteredList(model.getSelected(), Relation.class);
    158                 actSetRelationSelection.setRelations(rels);
    159                 actEditRelationSelection.setRelations(rels);
     150                Collection<OsmPrimitive> selection = model.getSelected();
     151                popupMenuHandler.setNodes(OsmPrimitive.getFilteredList(selection, Node.class));
     152                popupMenuHandler.setWays(OsmPrimitive.getFilteredList(selection, Way.class));
     153                List<Relation> rels = OsmPrimitive.getFilteredList(selection, Relation.class);
     154                for (RelationAction relAction : popupMenuHandler.getRelationActions()) {
     155                    if (relAction == popupMenuHandler.getDownloadSelectedIncompleteMembersAction()) {
     156                        relAction.setRelations(model.getSelectedRelationsWithIncompleteMembers());
     157                    } else {
     158                        relAction.setRelations(rels);
     159                    }
     160                }
    160161            }
    161162        });
    162163               
    163164        lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher());
    164165        lstPrimitives.addMouseListener(new DblClickHandler());
    165166
    166         popupMenu = new SelectionPopup(lstPrimitives);
    167167        InputMapUtils.addEnterAction(lstPrimitives, actZoomToListSelection);
    168168    }
    169169
     
    220220        }
    221221    }
    222222
    223     /**
    224      * The popup menu for the selection list
    225      */
    226     class SelectionPopup extends ListPopupMenu {
    227         public SelectionPopup(JList list) {
    228             super(list);
    229             add(actZoomToJOSMSelection);
    230             add(actZoomToListSelection);
    231             addSeparator();
    232             add(actSetRelationSelection);
    233             add(actEditRelationSelection);
    234             addSeparator();
    235             add(actDownloadSelectedIncompleteMembers);
    236         }
     223    private final DataActionPopupMenuHandler setupPopupMenuHandler() {
     224        DataActionPopupMenuHandler handler = new DataActionPopupMenuHandler(popupMenu);
     225        handler.addAction(actZoomToJOSMSelection);
     226        handler.addAction(actZoomToListSelection);
     227        handler.addSeparator();
     228        handler.enableSelectInRelationListAction();
     229        handler.enableEditRelationAction();
     230        handler.addSeparator();
     231        handler.enableDownloadIncompleteMembersAction();
     232        return handler;
    237233    }
    238234
    239     public void addPopupMenuSeparator() {
    240         popupMenu.addSeparator();
    241     }
    242 
    243     public JMenuItem addPopupMenuAction(Action a) {
    244         return popupMenu.add(a);
    245     }
    246 
    247     public void addPopupMenuListener(PopupMenuListener l) {
    248         popupMenu.addPopupMenuListener(l);
    249     }
    250 
    251     public void removePopupMenuListener(PopupMenuListener l) {
    252         popupMenu.addPopupMenuListener(l);
     235    public DataActionPopupMenuHandler getPopupMenuActionHandler() {
     236        return popupMenuHandler;
    253237    }
    254238
    255239    public Collection<OsmPrimitive> getSelectedPrimitives() {
  • core/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

     
    5151
    5252import org.openstreetmap.josm.Main;
    5353import org.openstreetmap.josm.actions.JosmAction;
    54 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
    55 import org.openstreetmap.josm.actions.relation.SelectMembersAction;
    56 import org.openstreetmap.josm.actions.relation.SelectRelationAction;
    5754import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
    5855import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    5956import org.openstreetmap.josm.command.ChangeCommand;
     
    7269import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    7370import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    7471import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
     72import org.openstreetmap.josm.gui.DataActionPopupMenuHandler;
    7573import org.openstreetmap.josm.gui.DefaultNameFormatter;
    7674import org.openstreetmap.josm.gui.ExtendedDialog;
    7775import org.openstreetmap.josm.gui.MapFrame;
     
    110108 * @author imi
    111109 */
    112110public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {
    113     // hook for roadsigns plugin to display a small
    114     // button in the upper right corner of this dialog
     111
     112    /**
     113     * hook for roadsigns plugin to display a small button in the upper right corner of this dialog
     114     */
    115115    public static final JPanel pluginHook = new JPanel();
    116116
    117117    /**
     
    133133     */
    134134    private final JTable membershipTable = new JTable(membershipData);
    135135
    136     private JPopupMenu propertyMenu;
    137     private JPopupMenu membershipMenu;
     136    private final JPopupMenu propertyMenu = new JPopupMenu();
     137    private final JPopupMenu membershipMenu = new JPopupMenu();
    138138
    139139    private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>();
    140140    /**
     
    156156    private final JosmAction[] josmActions = new JosmAction[]{addAction, editAction, deleteAction};
    157157
    158158    // relation actions
    159     private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction();
    160     private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true);
    161     private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true);
    162     private final SelectRelationAction selectRelationAction = new SelectRelationAction(false);
     159    private final DataActionPopupMenuHandler membershipMenuHandler = new DataActionPopupMenuHandler(membershipMenu);
    163160   
    164161    /**
    165162     * The Add button (needed to be able to disable it)
     
    201198   
    202199    /**
    203200     * Create a new PropertiesDialog
     201     * @param mapFrame The parent map fram
    204202     */
    205203    public PropertiesDialog(MapFrame mapFrame) {
    206204        super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."),
     
    369367     */
    370368    private void setupMembershipMenu() {
    371369        // setting up the membership table
    372         membershipMenu = new JPopupMenu();
    373         membershipMenu.add(addRelationToSelectionAction);
    374         membershipMenu.add(selectRelationAction);
    375         membershipMenu.add(addMembersToSelectionAction);
    376         membershipMenu.add(downloadSelectedIncompleteMembersAction);
     370        membershipMenuHandler.enableAddRelationToSelectionAction();
     371        membershipMenuHandler.enableSelectRelationAction();
     372        membershipMenuHandler.enableAddMembersToSelectionAction();
     373        membershipMenuHandler.enableDownloadIncompleteMembersAction();
    377374        membershipMenu.addSeparator();
    378375        membershipMenu.add(helpAction);
    379376
     
    388385                    membershipTable.changeSelection(row, 0, false, false);
    389386                    idx = new int[]{row};
    390387                }
    391                 List<Relation> rels =  new ArrayList<Relation>(10);
     388                List<Relation> rels = new ArrayList<Relation>();
    392389                for (int i: idx) {
    393390                    Relation r = (Relation) (membershipData.getValueAt(i, 0));
    394391                    rels.add(r);
    395392                }
    396                 selectRelationAction.setRelations(rels);
    397                 addRelationToSelectionAction.setRelations(rels);
    398                 addMembersToSelectionAction.setRelations(rels);
    399                 downloadSelectedIncompleteMembersAction.setRelations(rels);
     393                membershipMenuHandler.setRelations(rels);
    400394                membershipMenu.show(membershipTable, p.x, p.y-3);
    401395            }
    402396        });
     
    406400     * creates the popup menu @field propertyMenu and its launcher on property table
    407401     */
    408402    private void setupPropertiesMenu() {
    409         propertyMenu = new JPopupMenu();
    410403        propertyMenu.add(pasteValueAction);
    411404        propertyMenu.add(copyValueAction);
    412405        propertyMenu.add(copyKeyValueAction);
     
    720713                map.size() > 1 ? "" : map.keySet().iterator().next());
    721714    }
    722715
    723     public void addMembershipPopupMenuSeparator() {
    724         membershipMenu.addSeparator();
    725     }
    726 
    727     public JMenuItem addMembershipPopupMenuAction(Action a) {
    728         return membershipMenu.add(a);
    729     }
    730 
    731     public void addMembershipPopupMenuListener(PopupMenuListener l) {
    732         membershipMenu.addPopupMenuListener(l);
    733     }
    734 
    735     public void removeMembershipPopupMenuListener(PopupMenuListener l) {
    736         membershipMenu.addPopupMenuListener(l);
     716    public DataActionPopupMenuHandler getMembershipPopupMenuHandler() {
     717        return membershipMenuHandler;
    737718    }
    738719
    739720    public IRelation getSelectedMembershipRelation() {