Ignore:
Timestamp:
2013-04-02T00:55:56+02:00 (11 years ago)
Author:
Don-vip
Message:

see #7846 - Large code refactorization in management of popup menus to simplify interactions with plugins (needed at least for imagery-xml-bounds and tag2link plugins)

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java

    r5799 r5821  
    77import javax.swing.AbstractAction;
    88
     9import org.openstreetmap.josm.actions.OsmPrimitiveAction;
     10import org.openstreetmap.josm.data.osm.OsmPrimitive;
    911import org.openstreetmap.josm.data.osm.Relation;
     12import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1013
    1114/**
     
    1417 * @since 5793
    1518 */
    16 public abstract class AbstractRelationAction extends AbstractAction {
     19public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction {
    1720    protected Collection<Relation> relations = Collections.<Relation>emptySet();
    1821
    19     /**
    20      * Specifies the working set of relations.
    21      * @param relations The new working set of relations. Can be null or empty
     22    protected static final Collection<Relation> getRelations(Collection<? extends OsmPrimitive> primitives) {
     23        if (primitives == null || primitives.isEmpty()) {
     24            return Collections.<Relation>emptySet();
     25        } else {
     26            return new SubclassFilteredCollection<OsmPrimitive, Relation>(
     27                    primitives, OsmPrimitive.relationPredicate);
     28        }
     29    }
     30   
     31    /* (non-Javadoc)
     32     * @see org.openstreetmap.josm.actions.relation.RelationAction#setPrimitives
    2233     */
    23     public void setRelations(Collection<Relation> relations) {
    24         if (relations==null) {
    25             this.relations = Collections.<Relation>emptySet();
    26         } else {
    27             this.relations = relations;
    28         }
     34    @Override
     35    public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     36        this.relations = getRelations(primitives);
    2937        updateEnabledState();
    3038    }
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r5799 r5821  
    66
    77import java.awt.event.ActionEvent;
     8import java.util.Collection;
    89
    910import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.osm.OsmPrimitive;
     12import org.openstreetmap.josm.data.osm.Relation;
    1013import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    1114import org.openstreetmap.josm.tools.ImageProvider;
     15import org.openstreetmap.josm.tools.Predicate;
     16import org.openstreetmap.josm.tools.Utils;
    1217
    1318/**
    1419 * The action for downloading members of relations
    15 
     20 * @since 5793
    1621 */
    1722public class DownloadMembersAction extends AbstractRelationAction {
     
    3237        Main.worker.submit(new DownloadRelationTask(relations, Main.map.mapView.getEditLayer()));
    3338    }
     39
     40    @Override
     41    public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     42        // selected non-new relations
     43        this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){
     44            @Override public boolean evaluate(Relation r) {
     45                return !r.isNew();
     46            }});
     47        updateEnabledState();
     48    }
    3449}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r5799 r5821  
    1414import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    1515import org.openstreetmap.josm.tools.ImageProvider;
     16import org.openstreetmap.josm.tools.Predicate;
     17import org.openstreetmap.josm.tools.Utils;
    1618
    1719/**
     
    5153                Main.map.mapView.getEditLayer()));
    5254    }
     55
     56    @Override
     57    public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     58        // selected relations with incomplete members
     59        this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){
     60            @Override public boolean evaluate(Relation r) {
     61                return !r.isNew() && r.hasIncompleteMembers();
     62            }});
     63        updateEnabledState();
     64    }
    5365}
  • trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

    r5799 r5821  
    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"));
Note: See TracChangeset for help on using the changeset viewer.