001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.dialogs.relation.actions; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.event.ActionEvent; 007 008import org.openstreetmap.josm.tools.ImageProvider; 009 010/** 011 * Selects members in the relation editor which refer to primitives in the current selection of the context layer. 012 * @since 9496 013 */ 014public class SelectedMembersForSelectionAction extends AddFromSelectionAction { 015 private static final long serialVersionUID = 1L; 016 017 /** 018 * Constructs a new {@code SelectedMembersForSelectionAction}. 019 * @param editorAccess An interface to access the relation editor contents. 020 */ 021 public SelectedMembersForSelectionAction(IRelationEditorActionAccess editorAccess) { 022 super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE); 023 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection")); 024 new ImageProvider("dialogs/relation", "selectmembers").getResource().attachImageIcon(this, true); 025 updateEnabledState(); 026 } 027 028 @Override 029 protected void updateEnabledState() { 030 boolean enabled = getSelectionTableModel().getRowCount() > 0 031 && !editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).isEmpty(); 032 033 if (enabled) { 034 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to {0} objects in the current selection", 035 editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).size())); 036 } else { 037 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection")); 038 } 039 setEnabled(enabled); 040 } 041 042 @Override 043 public void actionPerformed(ActionEvent e) { 044 editorAccess.getMemberTableModel().selectMembersReferringTo(getLayer().data.getSelected()); 045 } 046}