1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 |
|
---|
6 | import javax.swing.AbstractCellEditor;
|
---|
7 | import javax.swing.BorderFactory;
|
---|
8 | import javax.swing.JTable;
|
---|
9 | import javax.swing.table.TableCellEditor;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
12 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
13 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
14 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
|
---|
15 |
|
---|
16 | public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
|
---|
17 | private AutoCompletingTextField editor = null;
|
---|
18 | private final DataSet ds;
|
---|
19 | private final Relation relation;
|
---|
20 |
|
---|
21 | /** user input is matched against this list of auto completion items */
|
---|
22 | private AutoCompletionList autoCompletionList = null;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code MemberRoleCellEditor}.
|
---|
26 | * @param ds the data set. Must not be null
|
---|
27 | * @param relation the relation. Can be null
|
---|
28 | */
|
---|
29 | public MemberRoleCellEditor(DataSet ds, Relation relation) {
|
---|
30 | this.ds = ds;
|
---|
31 | this.relation = relation;
|
---|
32 | editor = new AutoCompletingTextField();
|
---|
33 | editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
|
---|
34 | autoCompletionList = new AutoCompletionList();
|
---|
35 | editor.setAutoCompletionList(autoCompletionList);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public Component getTableCellEditorComponent(JTable table,
|
---|
40 | Object value, boolean isSelected, int row, int column) {
|
---|
41 |
|
---|
42 | String role = (String)value;
|
---|
43 | editor.setText(role);
|
---|
44 | autoCompletionList.clear();
|
---|
45 | ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList, relation);
|
---|
46 | return editor;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public Object getCellEditorValue() {
|
---|
51 | return editor.getText();
|
---|
52 | }
|
---|
53 |
|
---|
54 | /** Returns the edit field for this cell editor. */
|
---|
55 | public AutoCompletingTextField getEditor() {
|
---|
56 | return editor;
|
---|
57 | }
|
---|
58 | }
|
---|