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

Last change on this file since 8308 was 8308, checked in by Don-vip, 9 years ago

fix potential NPEs and Sonar issues related to serialization

  • Property svn:eol-style set to native
File size: 1.4 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 protected transient 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<>(
27 primitives, OsmPrimitive.relationPredicate);
28 }
29 }
30
31 @Override
32 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
33 this.relations = getRelations(primitives);
34 updateEnabledState();
35 }
36
37 protected void updateEnabledState() {
38 setEnabled(!relations.isEmpty());
39 }
40}
Note: See TracBrowser for help on using the repository browser.