source: josm/trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java@ 6053

Last change on this file since 6053 was 5821, checked in by Don-vip, 11 years ago

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)

File size: 1.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.relation;
3
4import java.util.Collection;
5import java.util.Collections;
6
7import javax.swing.AbstractAction;
8
9import org.openstreetmap.josm.actions.OsmPrimitiveAction;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.tools.SubclassFilteredCollection;
13
14/**
15 * Ancestor for all actions that want to work with relation collection and
16 * to be disabled is the collection is empty
17 * @since 5793
18 */
19public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction {
20 protected Collection<Relation> relations = Collections.<Relation>emptySet();
21
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
33 */
34 @Override
35 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
36 this.relations = getRelations(primitives);
37 updateEnabledState();
38 }
39
40 protected void updateEnabledState() {
41 setEnabled(!relations.isEmpty());
42 }
43}
Note: See TracBrowser for help on using the repository browser.