Changeset 7556 in josm for trunk/src


Ignore:
Timestamp:
2014-09-18T02:23:15+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #8262 - Relation editor: filter autocompletion of roles by relation type

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r7432 r7556  
    163163    }
    164164
    165     @Override public void accept(Visitor visitor) {
     165    @Override
     166    public void accept(Visitor visitor) {
    166167        visitor.visit(this);
    167168    }
    168169
    169     @Override public void accept(PrimitiveVisitor visitor) {
     170    @Override
     171    public void accept(PrimitiveVisitor visitor) {
    170172        visitor.visit(this);
    171173    }
     
    223225    }
    224226
    225     @Override public void cloneFrom(OsmPrimitive osm) {
     227    @Override
     228    public void cloneFrom(OsmPrimitive osm) {
    226229        boolean locked = writeLock();
    227230        try {
     
    234237    }
    235238
    236     @Override public void load(PrimitiveData data) {
     239    @Override
     240    public void load(PrimitiveData data) {
    237241        boolean locked = writeLock();
    238242        try {
     
    548552        return false;
    549553    }
     554
     555    /**
     556     * Returns the set of roles used in this relation.
     557     * @return the set of roles used in this relation. Can be empty but never null
     558     * @since 7556
     559     */
     560    public Set<String> getMemberRoles() {
     561        Set<String> result = new HashSet<>();
     562        for (RelationMember rm : members) {
     563            String role = rm.getRole();
     564            if (!role.isEmpty()) {
     565                result.add(role);
     566            }
     567        }
     568        return result;
     569    }
    550570}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r7546 r7556  
    9292/**
    9393 * This dialog is for editing relations.
    94  *
     94 * @since 343
    9595 */
    9696public class GenericRelationEditor extends RelationEditor  {
     
    172172        tagEditorPanel.getModel().ensureOneTag();
    173173
    174         JSplitPane pane = buildSplitPane();
     174        JSplitPane pane = buildSplitPane(relation);
    175175        pane.setPreferredSize(new Dimension(100, 100));
    176176
     
    293293     */
    294294    protected JPanel buildMemberEditorPanel() {
    295         final JPanel pnl = new JPanel();
    296         pnl.setLayout(new GridBagLayout());
     295        final JPanel pnl = new JPanel(new GridBagLayout());
    297296        // setting up the member table
    298         memberTable = new MemberTable(getLayer(),memberTableModel);
     297        memberTable = new MemberTable(getLayer(), getRelation(), memberTableModel);
    299298        memberTable.addMouseListener(new MemberTableDblClickAdapter());
    300299        memberTableModel.addMemberModelListener(memberTable);
     
    350349                        if (list != null) {
    351350                            list.clear();
    352                             getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list);
     351                            getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list, getRelation());
    353352                        }
    354353                    }
     
    454453     * @return the split panel
    455454     */
    456     protected JSplitPane buildSplitPane() {
     455    protected JSplitPane buildSplitPane(Relation relation) {
    457456        final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    458457        pane.setTopComponent(buildTagEditorPanel());
     
    16031602
    16041603    /**
    1605      * Creates a new relation with a copy of the current editor state
    1606      *
     1604     * Creates a new relation with a copy of the current editor state.
    16071605     */
    16081606    class DuplicateRelationAction extends AbstractAction {
     
    16261624
    16271625    /**
    1628      * Action for editing the currently selected relation
    1629      *
    1630      *
     1626     * Action for editing the currently selected relation.
    16311627     */
    16321628    class EditAction extends AbstractAction implements ListSelectionListener {
     
    17361732            }
    17371733        }
    1738 
    17391734    }
    17401735
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java

    r6246 r7556  
    1010
    1111import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.Relation;
    1213import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    1314import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     
    1516public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
    1617    private AutoCompletingTextField editor = null;
    17     private DataSet ds;
     18    private final DataSet ds;
     19    private final Relation relation;
    1820
    1921    /** user input is matched against this list of auto completion items */
     
    2123
    2224    /**
    23      * constructor
     25     * Constructs a new {@code MemberRoleCellEditor}.
     26     * @param ds the data set. Must not be null
     27     * @param relation the relation. Can be null
    2428     */
    25     public MemberRoleCellEditor(DataSet ds) {
     29    public MemberRoleCellEditor(DataSet ds, Relation relation) {
    2630        this.ds = ds;
     31        this.relation = relation;
    2732        editor = new AutoCompletingTextField();
    2833        editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
     
    3136    }
    3237
    33     /**
    34      * replies the table cell editor
    35      */
    3638    @Override
    3739    public Component getTableCellEditorComponent(JTable table,
     
    4143        editor.setText(role);
    4244        autoCompletionList.clear();
    43         ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList);
     45        ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList, relation);
    4446        return editor;
    4547    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java

    r7005 r7556  
    2929import org.openstreetmap.josm.actions.ZoomToAction;
    3030import org.openstreetmap.josm.data.osm.OsmPrimitive;
     31import org.openstreetmap.josm.data.osm.Relation;
    3132import org.openstreetmap.josm.data.osm.RelationMember;
    3233import org.openstreetmap.josm.data.osm.Way;
     
    5051     * constructor for relation member table
    5152     *
    52      * @param layer the data layer of the relation
     53     * @param layer the data layer of the relation. Must not be null
     54     * @param relation the relation. Can be null
    5355     * @param model the table model
    5456     */
    55     public MemberTable(OsmDataLayer layer, MemberTableModel model) {
    56         super(model, new MemberTableColumnModel(layer.data), model.getSelectionModel());
     57    public MemberTable(OsmDataLayer layer, Relation relation, MemberTableModel model) {
     58        super(model, new MemberTableColumnModel(layer.data, relation), model.getSelectionModel());
    5759        setLayer(layer);
    5860        model.addMemberModelListener(this);
     
    157159     * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row
    158160     * when the user leaves the last cell in the table</li></ul>
    159      *
    160      *
    161161     */
    162162    class SelectNextColumnCellAction extends AbstractAction {
     
    191191     * Action to be run when the user navigates to the previous cell in the table, for instance by
    192192     * pressing Shift-TAB
    193      *
    194193     */
    195194    private class SelectPreviousColumnCellAction extends AbstractAction {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java

    r6296 r7556  
    88
    99import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.data.osm.Relation;
    1011
    1112public class MemberTableColumnModel extends DefaultTableColumnModel {
    1213
    13     public MemberTableColumnModel(DataSet ds) {
     14    /**
     15     * Constructs a new {@code MemberTableColumnModel}.
     16     * @param ds the data set. Must not be null
     17     * @param relation the relation. Can be null
     18     */
     19    public MemberTableColumnModel(DataSet ds, Relation relation) {
    1420        TableColumn col = null;
    1521
     
    2026        col.setPreferredWidth(100);
    2127        col.setCellRenderer(new MemberTableRoleCellRenderer());
    22         col.setCellEditor(new MemberRoleCellEditor(ds));
     28        col.setCellEditor(new MemberRoleCellEditor(ds, relation));
    2329        addColumn(col);
    2430
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r7005 r7556  
    2929import org.openstreetmap.josm.gui.tagging.TaggingPresetItem;
    3030import org.openstreetmap.josm.gui.tagging.TaggingPresetItems;
     31import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Role;
     32import org.openstreetmap.josm.tools.CheckParameterUtil;
    3133import org.openstreetmap.josm.tools.MultiMap;
     34import org.openstreetmap.josm.tools.Utils;
    3235
    3336/**
     
    210213
    211214    /**
    212      * Populates the an {@link AutoCompletionList} with the currently cached
     215     * Populates the {@link AutoCompletionList} with the currently cached
    213216     * member roles.
    214217     *
     
    218221        list.add(presetRoleCache, AutoCompletionItemPriority.IS_IN_STANDARD);
    219222        list.add(getRoleCache(), AutoCompletionItemPriority.IS_IN_DATASET);
     223    }
     224
     225    /**
     226     * Populates the {@link AutoCompletionList} with the roles used in this relation
     227     * plus the ones defined in its applicable presets, if any. If the relation type is unknown,
     228     * then all the roles known globally will be added, as in {@link #populateWithMemberRoles(AutoCompletionList)}.
     229     *
     230     * @param list the list to populate
     231     * @param r the relation to get roles from
     232     * @throws IllegalArgumentException if list is null
     233     * @since 7556
     234     */
     235    public void populateWithMemberRoles(AutoCompletionList list, Relation r) {
     236        CheckParameterUtil.ensureParameterNotNull(list, "list");
     237        Collection<TaggingPreset> presets = r != null ? TaggingPreset.getMatchingPresets(null, r.getKeys(), false) : null;
     238        if (r != null && presets != null && !presets.isEmpty()) {
     239            for (TaggingPreset tp : presets) {
     240                if (tp.roles != null) {
     241                    list.add(Utils.transform(tp.roles.roles, new Utils.Function<Role, String>() {
     242                        public String apply(Role x) {
     243                            return x.key;
     244                        }
     245                    }), AutoCompletionItemPriority.IS_IN_STANDARD);
     246                }
     247            }
     248            list.add(r.getMemberRoles(), AutoCompletionItemPriority.IS_IN_DATASET);
     249        } else {
     250            populateWithMemberRoles(list);
     251        }
    220252    }
    221253
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7473 r7556  
    625625        return new AbstractList<B>() {
    626626
    627 
    628627            @Override
    629628            public int size() {
     
    635634                return f.apply(l.get(index));
    636635            }
    637 
    638 
    639636        };
    640637    }
Note: See TracChangeset for help on using the changeset viewer.