Changeset 15707 in josm for trunk/src


Ignore:
Timestamp:
2020-01-13T23:51:08+01:00 (5 years ago)
Author:
simon04
Message:

see #14465 -Tag2Link: consider all selected primitives/properties

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r15673 r15707  
    667667            @Override
    668668            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    669                 final IRelation<?> selection = getSelected();
    670                 if (selection != null) {
    671                     selection.visitKeys((primitive, key, value) -> addLinks(popupMenu, key, value));
    672                 }
     669                getSelectedRelations().forEach(relation ->
     670                        relation.visitKeys((primitive, key, value) -> addLinks(popupMenu, key, value)));
    673671            }
    674672        });
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r15673 r15707  
    236236            @Override
    237237            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    238                 final Collection<OsmPrimitive> selection = getSelectedPrimitives();
    239                 if (!selection.isEmpty()) {
    240                     selection.iterator().next().visitKeys((primitive, key, value) -> addLinks(popupMenu, key, value));
    241                 }
     238                getSelectedPrimitives().forEach(primitive ->
     239                        primitive.visitKeys((p, key, value) -> addLinks(popupMenu, key, value)));
    242240            }
    243241        });
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r15673 r15707  
    2828import java.util.TreeSet;
    2929import java.util.concurrent.atomic.AtomicBoolean;
     30import java.util.stream.Collectors;
    3031
    3132import javax.swing.AbstractAction;
     
    6566import org.openstreetmap.josm.data.osm.IRelation;
    6667import org.openstreetmap.josm.data.osm.IRelationMember;
     68import org.openstreetmap.josm.data.osm.KeyValueVisitor;
    6769import org.openstreetmap.josm.data.osm.Node;
    6870import org.openstreetmap.josm.data.osm.OsmData;
     
    396398            @Override
    397399            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    398                 final IRelation<?> relation = getSelectedMembershipRelation();
    399                 if (relation != null) {
    400                     relation.visitKeys((primitive, key, value) -> addLinks(membershipMenu, key, value));
    401                 }
     400                getSelectedMembershipRelations().forEach(relation ->
     401                        relation.visitKeys((primitive, key, value) -> addLinks(membershipMenu, key, value)));
    402402            }
    403403        });
     
    457457            @Override
    458458            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
    459                 final Tags tags = getSelectedProperties();
    460                 if (tags != null) {
    461                     tags.getValues().forEach(value -> addLinks(tagMenu, tags.getKey(), value));
    462                 }
     459                visitSelectedProperties((primitive, key, value) -> addLinks(tagMenu, key, value));
    463460            }
    464461        });
     
    804801
    805802    /**
     803     * Visits all combinations of the selected keys/values.
     804     * @param visitor the visitor
     805     * @since 15707
     806     */
     807    public void visitSelectedProperties(KeyValueVisitor visitor) {
     808        for (int row : tagTable.getSelectedRows()) {
     809            final String key = editHelper.getDataKey(row);
     810            Set<String> values = editHelper.getDataValues(row).keySet();
     811            values.forEach(value -> visitor.visitKeyValue(null, key, value));
     812        }
     813    }
     814
     815    /**
    806816     * Replies the membership popup menu handler.
    807817     * @return The membership popup menu handler
     
    818828        int row = membershipTable.getSelectedRow();
    819829        return row > -1 ? (IRelation<?>) membershipData.getValueAt(row, 0) : null;
     830    }
     831
     832    /**
     833     * Returns all selected relation memberships.
     834     * @return The selected relation memberships
     835     * @since 15707
     836     */
     837    public Collection<IRelation<?>> getSelectedMembershipRelations() {
     838        return Arrays.stream(membershipTable.getSelectedRows())
     839                .mapToObj(row -> (IRelation<?>) membershipData.getValueAt(row, 0))
     840                .collect(Collectors.toList());
    820841    }
    821842
Note: See TracChangeset for help on using the changeset viewer.