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

Last change on this file since 12346 was 11922, checked in by Don-vip, 7 years ago

javadoc

  • Property svn:eol-style set to native
File size: 1.7 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 if the collection is empty
17 * @since 5793
18 */
19public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction {
20 /** relation collection */
21 protected transient Collection<Relation> relations = Collections.<Relation>emptySet();
22
23 /**
24 * Returns the relations contained in the given collection.
25 * @param primitives collection of primitives
26 * @return the relation contained in {@code primitives}
27 */
28 protected static final Collection<Relation> getRelations(Collection<? extends OsmPrimitive> primitives) {
29 if (primitives == null || primitives.isEmpty()) {
30 return Collections.<Relation>emptySet();
31 } else {
32 return new SubclassFilteredCollection<>(primitives, Relation.class::isInstance);
33 }
34 }
35
36 @Override
37 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
38 this.relations = getRelations(primitives);
39 updateEnabledState();
40 }
41
42 /**
43 * Override in subclasses to update the enabled state of the action when something changes.
44 */
45 protected void updateEnabledState() {
46 setEnabled(!relations.isEmpty());
47 }
48}
Note: See TracBrowser for help on using the repository browser.