Changeset 13957 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2018-06-18T21:53:59+02:00 (13 months ago)
Author:
Don-vip
Message:

use IRelation in RelationListDialog and *RelationActions

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

Legend:

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

    r13486 r13957  
    168168            } else if (multipolygonRelation.hasIncompleteMembers()) {
    169169                MainApplication.worker.submit(new DownloadRelationMemberTask(multipolygonRelation,
    170                         DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(Collections.singleton(multipolygonRelation)),
     170                        Utils.filteredCollection(
     171                            DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(
     172                                    Collections.singleton(multipolygonRelation)), OsmPrimitive.class),
    171173                        editLayer));
    172174            }
  • trunk/src/org/openstreetmap/josm/actions/OsmPrimitiveAction.java

    r8512 r13957  
    1111 * Interface used to enable/disable all primitive-related actions, even those registered by plugins.
    1212 * @since 5821
     13 * @deprecated Use {@link IPrimitiveAction} instead
    1314 */
     15@Deprecated
    1416public interface OsmPrimitiveAction extends Action {
    1517
  • trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java

    r13559 r13957  
    88
    99import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.actions.OsmPrimitiveAction;
    11 import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.actions.IPrimitiveAction;
    1211import org.openstreetmap.josm.data.osm.DownloadPolicy;
    13 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.data.osm.Relation;
     12import org.openstreetmap.josm.data.osm.IPrimitive;
     13import org.openstreetmap.josm.data.osm.IRelation;
     14import org.openstreetmap.josm.data.osm.OsmData;
    1515import org.openstreetmap.josm.io.OnlineResource;
    1616import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     
    2020 * to be disabled if the collection is empty
    2121 * @since 5793
     22 * @since 13957 (signature)
    2223 */
    23 public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction {
     24public abstract class AbstractRelationAction extends AbstractAction implements IPrimitiveAction {
    2425    /** relation collection */
    25     protected transient Collection<Relation> relations = Collections.<Relation>emptySet();
     26    protected transient Collection<IRelation<?>> relations = Collections.<IRelation<?>>emptySet();
    2627
    2728    /**
     
    3031     * @return the relation contained in {@code primitives}
    3132     */
    32     protected static final Collection<Relation> getRelations(Collection<? extends OsmPrimitive> primitives) {
     33    protected static final Collection<IRelation<?>> getRelations(Collection<? extends IPrimitive> primitives) {
    3334        if (primitives == null || primitives.isEmpty()) {
    34             return Collections.<Relation>emptySet();
     35            return Collections.<IRelation<?>>emptySet();
    3536        } else {
    36             return new SubclassFilteredCollection<>(primitives, Relation.class::isInstance);
     37            return new SubclassFilteredCollection<>(primitives, IRelation.class::isInstance);
    3738        }
    3839    }
    3940
    4041    @Override
    41     public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     42    public void setPrimitives(Collection<? extends IPrimitive> primitives) {
    4243        this.relations = getRelations(primitives);
    4344        updateEnabledState();
     
    5556            return false;
    5657        }
    57         DataSet ds = relations.iterator().next().getDataSet();
     58        OsmData<?, ?, ?, ?> ds = relations.iterator().next().getDataSet();
    5859        return !Main.isOffline(OnlineResource.OSM_API)
    5960            && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
  • trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java

    r13925 r13957  
    1414import org.openstreetmap.josm.command.SequenceCommand;
    1515import org.openstreetmap.josm.data.osm.DataSelectionListener;
    16 import org.openstreetmap.josm.data.osm.DataSet;
    17 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     16import org.openstreetmap.josm.data.osm.IPrimitive;
     17import org.openstreetmap.josm.data.osm.OsmData;
    1818import org.openstreetmap.josm.data.osm.OsmUtils;
    1919import org.openstreetmap.josm.data.osm.Relation;
     
    2323import org.openstreetmap.josm.gui.util.GuiHelper;
    2424import org.openstreetmap.josm.tools.ImageProvider;
     25import org.openstreetmap.josm.tools.Utils;
    2526
    2627/**
     
    4041    public void actionPerformed(ActionEvent e) {
    4142        Collection<Command> cmds = new LinkedList<>();
    42         for (Relation orig : relations) {
     43        for (Relation orig : Utils.filteredCollection(relations, Relation.class)) {
    4344            Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getActiveDataSet().getSelected());
    4445            if (c != null) {
     
    6162        int size = relations.size();
    6263        putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations", size, size));
    63         DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     64        OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    6465        if (ds != null) {
    6566            selectionChanged(ds.getSelected());
     
    6970    }
    7071
    71     private void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
     72    private void selectionChanged(final Collection<? extends IPrimitive> newSelection) {
    7273        GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty()
    7374                && OsmUtils.isOsmCollectionEditable(relations)));
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r13611 r13957  
    1414import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1515import org.openstreetmap.josm.tools.ImageProvider;
     16import org.openstreetmap.josm.tools.Utils;
    1617
    1718/**
     
    4647        if (!isEnabled())
    4748            return;
    48         deleteRelation(relations);
     49        deleteRelation(Utils.filteredCollection(relations, Relation.class));
    4950    }
    5051
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r13486 r13957  
    88import java.util.Collection;
    99
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     10import org.openstreetmap.josm.data.osm.IPrimitive;
     11import org.openstreetmap.josm.data.osm.Relation;
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    1314import org.openstreetmap.josm.tools.ImageProvider;
    1415import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     16import org.openstreetmap.josm.tools.Utils;
    1517
    1618/**
     
    3335    public void actionPerformed(ActionEvent e) {
    3436        if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
    35         MainApplication.worker.submit(new DownloadRelationTask(relations, MainApplication.getLayerManager().getEditLayer()));
     37        MainApplication.worker.submit(new DownloadRelationTask(
     38                Utils.filteredCollection(relations, Relation.class), MainApplication.getLayerManager().getEditLayer()));
    3639    }
    3740
    3841    @Override
    39     public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     42    public void setPrimitives(Collection<? extends IPrimitive> primitives) {
    4043        // selected non-new relations
    4144        this.relations = SubclassFilteredCollection.filter(getRelations(primitives), r -> !r.isNew());
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r13486 r13957  
    99import java.util.Set;
    1010
     11import org.openstreetmap.josm.data.osm.IPrimitive;
     12import org.openstreetmap.josm.data.osm.IRelation;
    1113import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1214import org.openstreetmap.josm.data.osm.Relation;
     
    1517import org.openstreetmap.josm.tools.ImageProvider;
    1618import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     19import org.openstreetmap.josm.tools.Utils;
    1720
    1821/**
     
    2225public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction {
    2326
    24     private transient Collection<OsmPrimitive> incompleteMembers;
     27    private transient Collection<IPrimitive> incompleteMembers;
    2528
    2629    /**
     
    3841     * @return The set of incomplete members of the given relations.
    3942     */
    40     public static Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
    41         Set<OsmPrimitive> ret = new HashSet<>();
    42         for (Relation r : rels) {
     43    public static Set<IPrimitive> buildSetOfIncompleteMembers(Collection<IRelation<?>> rels) {
     44        Set<IPrimitive> ret = new HashSet<>();
     45        for (IRelation<?> r : rels) {
    4346            ret.addAll(SubclassFilteredCollection.filter(r.getIncompleteMembers(), osm -> !osm.isNew()));
    4447        }
     
    5053        if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
    5154        MainApplication.worker.submit(new DownloadRelationMemberTask(
    52                 relations,
    53                 incompleteMembers,
     55                Utils.filteredCollection(relations, Relation.class),
     56                Utils.filteredCollection(incompleteMembers, OsmPrimitive.class),
    5457                MainApplication.getLayerManager().getEditLayer()));
    5558    }
    5659
    5760    @Override
    58     public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     61    public void setPrimitives(Collection<? extends IPrimitive> primitives) {
    5962        // selected relations with incomplete members
    60         this.relations = SubclassFilteredCollection.filter(getRelations(primitives), Relation::hasIncompleteMembers);
     63        this.relations = SubclassFilteredCollection.filter(getRelations(primitives), IRelation::hasIncompleteMembers);
    6164        this.incompleteMembers = buildSetOfIncompleteMembers(relations);
    6265        updateEnabledState();
  • trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

    r13453 r13957  
    66import java.awt.event.ActionEvent;
    77
     8import org.openstreetmap.josm.data.osm.IRelation;
    89import org.openstreetmap.josm.data.osm.Relation;
    910import org.openstreetmap.josm.gui.MainApplication;
     
    4546        if (!isEnabled() || relations.isEmpty())
    4647            return;
    47         Relation r = relations.iterator().next();
    48         duplicateRelationAndLaunchEditor(r);
     48        IRelation<?> r = relations.iterator().next();
     49        if (r instanceof Relation) {
     50            duplicateRelationAndLaunchEditor((Relation) r);
     51        }
    4952    }
    5053
     
    5255    protected void updateEnabledState() {
    5356        // only one selected relation can be edited
    54         setEnabled(relations.size() == 1 && !relations.iterator().next().getDataSet().isLocked());
     57        setEnabled(relations.size() == 1
     58                && relations.iterator().next() instanceof Relation
     59                && !relations.iterator().next().getDataSet().isLocked());
    5560    }
    5661}
  • trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java

    r13611 r13957  
    1313
    1414import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.data.osm.IRelation;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1617import org.openstreetmap.josm.data.osm.OsmUtils;
     
    2223import org.openstreetmap.josm.spi.preferences.Config;
    2324import org.openstreetmap.josm.tools.ImageProvider;
     25import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     26import org.openstreetmap.josm.tools.Utils;
    2427
    2528/**
     
    7174    @Override
    7275    public void actionPerformed(ActionEvent e) {
    73         if (!isEnabled() || relations.isEmpty()) return;
    74         if (relations.size() > Config.getPref().getInt("warn.open.maxrelations", 5) &&
     76        SubclassFilteredCollection<IRelation<?>, Relation> filteredRelations = Utils.filteredCollection(relations, Relation.class);
     77        if (!isEnabled() || filteredRelations.isEmpty()) return;
     78        if (filteredRelations.size() > Config.getPref().getInt("warn.open.maxrelations", 5) &&
    7579            /* I18N english text for value 1 makes no real sense, never called for values <= maxrel (usually 5) */
    7680            JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(Main.parent,
    7781                    "<html>"+trn("You are about to open <b>{0}</b> different relation editor simultaneously.<br/>Do you want to continue?",
    7882                            "You are about to open <b>{0}</b> different relation editors simultaneously.<br/>Do you want to continue?",
    79                             relations.size(), relations.size())+"</html>",
     83                            filteredRelations.size(), filteredRelations.size())+"</html>",
    8084                    tr("Confirmation"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE)) {
    8185            return;
    8286        }
    83         for (Relation r : relations) {
     87        for (Relation r : filteredRelations) {
    8488            launchEditor(r);
    8589        }
     
    8993    protected void updateEnabledState() {
    9094        boolean enabled = false;
    91         if (OsmUtils.isOsmCollectionEditable(relations)) {
    92             for (Relation r : relations) {
     95        SubclassFilteredCollection<IRelation<?>, Relation> filteredRelations = Utils.filteredCollection(relations, Relation.class);
     96        if (OsmUtils.isOsmCollectionEditable(filteredRelations)) {
     97            for (Relation r : filteredRelations) {
    9398                if (!r.isDeleted()) {
    9499                    enabled = true;
  • trunk/src/org/openstreetmap/josm/actions/relation/ExportRelationToGpxAction.java

    r13852 r13957  
    2323
    2424import org.openstreetmap.josm.actions.GpxExportAction;
    25 import org.openstreetmap.josm.actions.OsmPrimitiveAction;
     25import org.openstreetmap.josm.actions.IPrimitiveAction;
    2626import org.openstreetmap.josm.data.gpx.GpxData;
    2727import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack;
    2828import org.openstreetmap.josm.data.gpx.WayPoint;
     29import org.openstreetmap.josm.data.osm.IPrimitive;
    2930import org.openstreetmap.josm.data.osm.Node;
    30 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3131import org.openstreetmap.josm.data.osm.Relation;
    3232import org.openstreetmap.josm.data.osm.RelationMember;
     
    4747 */
    4848public class ExportRelationToGpxAction extends GpxExportAction
    49     implements OsmPrimitiveAction {
     49    implements IPrimitiveAction {
    5050
    5151    /** Enumeration of export variants */
     
    235235
    236236    @Override
    237     public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
     237    public void setPrimitives(Collection<? extends IPrimitive> primitives) {
    238238        relations = Collections.<Relation>emptySet();
    239239        if (primitives != null && !primitives.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r13434 r13957  
    88import java.util.Set;
    99
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    11 import org.openstreetmap.josm.data.osm.Relation;
     10import org.openstreetmap.josm.data.osm.IPrimitive;
     11import org.openstreetmap.josm.data.osm.IRelation;
    1212import org.openstreetmap.josm.gui.MainApplication;
    1313import org.openstreetmap.josm.tools.ImageProvider;
     
    3838        if (!isEnabled() || relations.isEmpty() || !MainApplication.isDisplayingMapView()) return;
    3939
    40         Set<OsmPrimitive> members = new HashSet<>();
    41         for (Relation r: relations) {
     40        Set<IPrimitive> members = new HashSet<>();
     41        for (IRelation<?> r: relations) {
    4242            members.addAll(r.getMemberPrimitivesList());
    4343        }
    4444        if (add) {
    45             MainApplication.getLayerManager().getActiveDataSet().addSelected(members);
     45            MainApplication.getLayerManager().getActiveData().addSelected(members);
    4646        } else {
    47             MainApplication.getLayerManager().getActiveDataSet().setSelected(members);
     47            MainApplication.getLayerManager().getActiveData().setSelected(members);
    4848        }
    4949    }
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r13434 r13957  
    66import java.awt.event.ActionEvent;
    77
    8 import org.openstreetmap.josm.data.osm.DataSet;
     8import org.openstreetmap.josm.data.osm.OsmData;
    99import org.openstreetmap.josm.gui.MainApplication;
    1010import org.openstreetmap.josm.tools.ImageProvider;
     
    3434    public void actionPerformed(ActionEvent e) {
    3535        if (!isEnabled() || relations.isEmpty()) return;
    36         DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     36        OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    3737        if (ds == null) return;
    3838        if (add) {
  • trunk/src/org/openstreetmap/josm/data/osm/IRelation.java

    r13908 r13957  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.Collection;
     5import java.util.HashSet;
    46import java.util.List;
     7import java.util.Set;
     8
     9import org.openstreetmap.josm.tools.Utils;
    510
    611/**
     
    9398        return "multipolygon".equals(get("type")) || isBoundary();
    9499    }
     100
     101    /**
     102     * Returns an unmodifiable list of the {@link OsmPrimitive}s referred to by at least one member of this relation.
     103     * @return an unmodifiable list of the primitives
     104     * @since 13957
     105     */
     106    default List<? extends IPrimitive> getMemberPrimitivesList() {
     107        return Utils.transform(getMembers(), IRelationMember::getMember);
     108    }
     109
     110    /**
     111     * Replies a collection with the incomplete children this relation refers to.
     112     *
     113     * @return the incomplete children. Empty collection if no children are incomplete.
     114     * @since 13957
     115     */
     116    default Collection<? extends IPrimitive> getIncompleteMembers() {
     117        Set<IPrimitive> ret = new HashSet<>();
     118        for (M rm : getMembers()) {
     119            if (!rm.getMember().isIncomplete()) {
     120                continue;
     121            }
     122            ret.add(rm.getMember());
     123        }
     124        return ret;
     125    }
    95126}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java

    r13637 r13957  
    162162     * @return {@code true} if the given collection is not empty and does not contain any primitive in a locked layer.
    163163     * @since 13611
     164     * @since 13957 (signature)
    164165     */
    165     public static boolean isOsmCollectionEditable(Collection<? extends OsmPrimitive> collection) {
     166    public static boolean isOsmCollectionEditable(Collection<? extends IPrimitive> collection) {
    166167        return collection != null && !collection.isEmpty()
    167             && collection.stream().map(OsmPrimitive::getDataSet).filter(Objects::nonNull).noneMatch(DataSet::isLocked);
     168            && collection.stream().map(IPrimitive::getDataSet).filter(Objects::nonNull).noneMatch(OsmData::isLocked);
    168169    }
    169170}
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r13908 r13957  
    405405     * @return an unmodifiable list of the primitives
    406406     */
     407    @Override
    407408    public List<OsmPrimitive> getMemberPrimitivesList() {
    408409        return Utils.transform(getMembers(), RelationMember::getMember);
     
    505506     * @return the incomplete children. Empty collection if no children are incomplete.
    506507     */
     508    @Override
    507509    public Collection<OsmPrimitive> getIncompleteMembers() {
    508510        Set<OsmPrimitive> ret = new HashSet<>();
  • trunk/src/org/openstreetmap/josm/gui/PopupMenuHandler.java

    r11386 r13957  
    1313import javax.swing.event.PopupMenuListener;
    1414
    15 import org.openstreetmap.josm.actions.OsmPrimitiveAction;
    16 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     15import org.openstreetmap.josm.actions.IPrimitiveAction;
     16import org.openstreetmap.josm.data.osm.IPrimitive;
    1717
    1818/**
     
    2323
    2424    // Set of enabled osm primitives actions
    25     private final Set<OsmPrimitiveAction> primitiveActions = new HashSet<>();
     25    private final Set<IPrimitiveAction> primitiveActions = new HashSet<>();
    2626    // Managed menu
    2727    private final JPopupMenu menu;
     
    5353    public JMenuItem addAction(Action a) {
    5454        if (a != null) {
    55             if (a instanceof OsmPrimitiveAction) {
    56                 primitiveActions.add((OsmPrimitiveAction) a);
     55            if (a instanceof IPrimitiveAction) {
     56                primitiveActions.add((IPrimitiveAction) a);
    5757            }
    5858            return menu.add(a);
     
    6969    public void removeAction(Action a) {
    7070        if (a != null) {
    71             if (a instanceof OsmPrimitiveAction) {
     71            if (a instanceof IPrimitiveAction) {
    7272                primitiveActions.remove(a);
    7373            }
     
    106106     * @return All primitive actions that have been added.
    107107     * @see #addAction(Action)
     108     * @since 13957 (signature)
    108109     */
    109     public Collection<OsmPrimitiveAction> getPrimitiveActions() {
     110    public Collection<IPrimitiveAction> getPrimitiveActions() {
    110111        return Collections.unmodifiableCollection(primitiveActions);
    111112    }
     
    114115     * Specifies the working set of primitives for all primitive actions.
    115116     * @param primitives The new working set of primitives. Can be null or empty
    116      * @see OsmPrimitiveAction#setPrimitives
     117     * @see IPrimitiveAction#setPrimitives
     118     * @since 13957 (signature)
    117119     */
    118     public void setPrimitives(Collection<? extends OsmPrimitive> primitives) {
    119         for (OsmPrimitiveAction action : primitiveActions) {
     120    public void setPrimitives(Collection<? extends IPrimitive> primitives) {
     121        for (IPrimitiveAction action : primitiveActions) {
    120122            action.setPrimitives(primitives);
    121123        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r13926 r13957  
    3535import org.openstreetmap.josm.Main;
    3636import org.openstreetmap.josm.actions.ExpertToggleAction;
    37 import org.openstreetmap.josm.actions.OsmPrimitiveAction;
     37import org.openstreetmap.josm.actions.IPrimitiveAction;
    3838import org.openstreetmap.josm.actions.relation.AddSelectionToRelations;
    3939import org.openstreetmap.josm.actions.relation.DeleteRelationsAction;
     
    5050import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    5151import org.openstreetmap.josm.data.osm.IPrimitive;
     52import org.openstreetmap.josm.data.osm.IRelation;
     53import org.openstreetmap.josm.data.osm.OsmData;
    5254import org.openstreetmap.josm.data.osm.OsmPrimitive;
    5355import org.openstreetmap.josm.data.osm.Relation;
     
    7274import org.openstreetmap.josm.gui.SideButton;
    7375import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    74 import org.openstreetmap.josm.gui.layer.Layer;
    7576import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    7677import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     
    7980import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    8081import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    81 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    8282import org.openstreetmap.josm.gui.util.HighlightHelper;
    8383import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
     
    9090import org.openstreetmap.josm.tools.Shortcut;
    9191import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     92import org.openstreetmap.josm.tools.Utils;
    9293
    9394/**
     
    100101        implements DataSetListener, NavigatableComponent.ZoomChangeListener, ExpertToggleAction.ExpertModeChangeListener {
    101102    /** The display list. */
    102     private final JList<Relation> displaylist;
     103    private final JList<IRelation<?>> displaylist;
    103104    /** the list model used */
    104105    private final RelationListModel model;
     
    222223    // inform all actions about list of relations they need
    223224    private void updateActionsRelationLists() {
    224         List<Relation> sel = model.getSelectedRelations();
     225        List<IRelation<?>> sel = model.getSelectedRelations();
    225226        popupMenuHandler.setPrimitives(sel);
    226227
     
    228229
    229230        //update highlights
    230         if (highlightEnabled && focused == displaylist && MainApplication.isDisplayingMapView() && highlightHelper.highlightOnly(sel)) {
     231        if (highlightEnabled && focused == displaylist && MainApplication.isDisplayingMapView()
     232                && highlightHelper.highlightOnly(Utils.filteredCollection(sel, Relation.class))) {
    231233            MainApplication.getMap().mapView.repaint();
    232234        }
     
    261263
    262264    /**
    263      * Initializes the relation list dialog from a layer. If <code>layer</code> is null
    264      * or if it isn't an {@link OsmDataLayer} the dialog is reset to an empty dialog.
     265     * Initializes the relation list dialog from a dataset. If <code>data</code> is null
     266     * the dialog is reset to an empty dialog.
    265267     * Otherwise it is initialized with the list of non-deleted and visible relations
    266      * in the layer's dataset.
     268     * in the dataset.
    267269     *
    268      * @param layer the layer. May be null.
    269      */
    270     protected void initFromLayer(Layer layer) {
    271         if (!(layer instanceof OsmDataLayer)) {
     270     * @param data the dataset. May be null.
     271     * @since 13957
     272     */
     273    protected void initFromData(OsmData<?, ?, ?, ?> data) {
     274        if (data == null) {
    272275            model.setRelations(null);
    273276            return;
    274277        }
    275         OsmDataLayer l = (OsmDataLayer) layer;
    276         model.setRelations(l.data.getRelations());
     278        model.setRelations(data.getRelations());
    277279        model.updateTitle();
    278280        updateActionsRelationLists();
     
    282284     * @return The selected relation in the list
    283285     */
    284     private Relation getSelected() {
     286    private IRelation<?> getSelected() {
    285287        if (model.getSize() == 1) {
    286288            displaylist.setSelectedIndex(0);
     
    301303     * Selects the relations in the list of relations.
    302304     * @param relations  the relations to be selected
    303      */
    304     public void selectRelations(Collection<Relation> relations) {
     305     * @since 13957 (signature)
     306     */
     307    public void selectRelations(Collection<? extends IRelation<?>> relations) {
    305308        if (relations == null || relations.isEmpty()) {
    306309            model.setSelectedRelations(null);
     
    348351
    349352        protected void editCurrentRelation() {
    350             EditRelationAction.launchEditor(getSelected());
     353            IRelation<?> rel = getSelected();
     354            if (rel instanceof Relation) {
     355                EditRelationAction.launchEditor((Relation) rel);
     356            }
    351357        }
    352358
     
    412418     * The list model for the list of relations displayed in the relation list dialog.
    413419     */
    414     private class RelationListModel extends AbstractListModel<Relation> {
    415         private final transient List<Relation> relations = new ArrayList<>();
    416         private transient List<Relation> filteredRelations;
     420    private class RelationListModel extends AbstractListModel<IRelation<?>> {
     421        private final transient List<IRelation<?>> relations = new ArrayList<>();
     422        private transient List<IRelation<?>> filteredRelations;
    417423        private final DefaultListSelectionModel selectionModel;
    418424        private transient SearchCompiler.Match filter;
     
    439445        }
    440446
    441         private boolean isValid(Relation r) {
     447        private boolean isValid(IRelation<?> r) {
    442448            return !r.isDeleted() && !r.isIncomplete();
    443449        }
    444450
    445         public void setRelations(Collection<Relation> relations) {
    446             List<Relation> sel = getSelectedRelations();
     451        public void setRelations(Collection<? extends IRelation<?>> relations) {
     452            List<IRelation<?>> sel = getSelectedRelations();
    447453            this.relations.clear();
    448454            this.filteredRelations = null;
     
    452458                return;
    453459            }
    454             for (Relation r: relations) {
     460            for (IRelation<?> r: relations) {
    455461                if (isValid(r)) {
    456462                    this.relations.add(r);
     
    487493            }
    488494            if (added) {
    489                 List<Relation> sel = getSelectedRelations();
     495                List<IRelation<?>> sel = getSelectedRelations();
    490496                sort();
    491497                updateFilteredRelations();
     
    520526            }
    521527            if (size != relations.size()) {
    522                 List<Relation> sel = getSelectedRelations();
     528                List<IRelation<?>> sel = getSelectedRelations();
    523529                sort();
    524530                fireContentsChanged(this, 0, getSize());
     
    538544            this.filter = filter;
    539545            updateFilteredRelations();
    540             List<Relation> sel = getSelectedRelations();
     546            List<IRelation<?>> sel = getSelectedRelations();
    541547            fireContentsChanged(this, 0, getSize());
    542548            setSelectedRelations(sel);
     
    544550        }
    545551
    546         private List<Relation> getVisibleRelations() {
     552        private List<IRelation<?>> getVisibleRelations() {
    547553            return filteredRelations == null ? relations : filteredRelations;
    548554        }
    549555
    550         private Relation getVisibleRelation(int index) {
     556        private IRelation<?> getVisibleRelation(int index) {
    551557            if (index < 0 || index >= getVisibleRelations().size()) return null;
    552558            return getVisibleRelations().get(index);
     
    554560
    555561        @Override
    556         public Relation getElementAt(int index) {
     562        public IRelation<?> getElementAt(int index) {
    557563            return getVisibleRelation(index);
    558564        }
     
    568574         *
    569575         * @return the list of selected, non-new relations.
     576         * @since 13957 (signature)
    570577         */
    571         public List<Relation> getSelectedRelations() {
    572             List<Relation> ret = new ArrayList<>();
     578        public List<IRelation<?>> getSelectedRelations() {
     579            List<IRelation<?>> ret = new ArrayList<>();
    573580            for (int i = 0; i < getSize(); i++) {
    574581                if (!selectionModel.isSelectedIndex(i)) {
     
    584591         *
    585592         * @param sel the list of selected relations
     593         * @since 13957 (signature)
    586594         */
    587         public void setSelectedRelations(Collection<Relation> sel) {
     595        public void setSelectedRelations(Collection<? extends IRelation<?>> sel) {
    588596            selectionModel.setValueIsAdjusting(true);
    589597            selectionModel.clearSelection();
     
    592600                    resetFilter();
    593601                }
    594                 for (Relation r: sel) {
     602                for (IRelation<?> r: sel) {
    595603                    Integer i = getVisibleRelationIndex(r);
    596604                    if (i != null) {
     
    602610        }
    603611
    604         private Integer getVisibleRelationIndex(Relation rel) {
     612        private Integer getVisibleRelationIndex(IRelation<?> rel) {
    605613            int i = getVisibleRelations().indexOf(rel);
    606614            if (i < 0)
     
    655663            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    656664                for (JMenuItem mi: checkDisabled) {
    657                     mi.setVisible(((OsmPrimitiveAction) mi.getAction()).isEnabled());
     665                    mi.setVisible(((IPrimitiveAction) mi.getAction()).isEnabled());
    658666
    659667                    Component sep = popupMenu.getComponent(
     
    692700     * Replies the list of selected relations. Empty list, if there are no selected relations.
    693701     * @return the list of selected, non-new relations.
    694      */
    695     public Collection<Relation> getSelectedRelations() {
     702     * @since 13957 (signature)
     703     */
     704    public Collection<IRelation<?>> getSelectedRelations() {
    696705        return model.getSelectedRelations();
    697706    }
     
    725734    @Override
    726735    public void relationMembersChanged(final RelationMembersChangedEvent event) {
    727         List<Relation> sel = model.getSelectedRelations();
     736        List<IRelation<?>> sel = model.getSelectedRelations();
    728737        model.sort();
    729738        model.setSelectedRelations(sel);
     
    737746            return;
    738747        // trigger a sort of the relation list because the display name may have changed
    739         List<Relation> sel = model.getSelectedRelations();
     748        List<IRelation<?>> sel = model.getSelectedRelations();
    740749        model.sort();
    741750        model.setSelectedRelations(sel);
     
    745754    @Override
    746755    public void dataChanged(DataChangedEvent event) {
    747         initFromLayer(MainApplication.getLayerManager().getActiveDataLayer());
     756        initFromData(MainApplication.getLayerManager().getActiveData());
    748757    }
    749758
Note: See TracChangeset for help on using the changeset viewer.