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.gui.tagging.ac.AutoCompletingTextField;
|
---|
13 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
|
---|
14 |
|
---|
15 | public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
|
---|
16 | private AutoCompletingTextField editor = null;
|
---|
17 | private DataSet ds;
|
---|
18 |
|
---|
19 | /** user input is matched against this list of auto completion items */
|
---|
20 | private AutoCompletionList autoCompletionList = null;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * constructor
|
---|
24 | */
|
---|
25 | public MemberRoleCellEditor(DataSet ds) {
|
---|
26 | this.ds = ds;
|
---|
27 | editor = new AutoCompletingTextField();
|
---|
28 | editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
|
---|
29 | autoCompletionList = new AutoCompletionList();
|
---|
30 | editor.setAutoCompletionList(autoCompletionList);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * replies the table cell editor
|
---|
35 | */
|
---|
36 | @Override
|
---|
37 | public Component getTableCellEditorComponent(JTable table,
|
---|
38 | Object value, boolean isSelected, int row, int column) {
|
---|
39 |
|
---|
40 | String role = (String)value;
|
---|
41 | editor.setText(role);
|
---|
42 | autoCompletionList.clear();
|
---|
43 | ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList);
|
---|
44 | return editor;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public Object getCellEditorValue() {
|
---|
49 | return editor.getText();
|
---|
50 | }
|
---|
51 |
|
---|
52 | /** Returns the edit field for this cell editor. */
|
---|
53 | public AutoCompletingTextField getEditor() {
|
---|
54 | return editor;
|
---|
55 | }
|
---|
56 | }
|
---|