[2512] | 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;
|
---|
[4238] | 7 | import javax.swing.BorderFactory;
|
---|
[2512] | 8 | import javax.swing.JTable;
|
---|
| 9 | import javax.swing.table.TableCellEditor;
|
---|
| 10 |
|
---|
[3210] | 11 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[7556] | 12 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
[3210] | 13 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
[2512] | 14 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
|
---|
| 15 |
|
---|
| 16 | public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
|
---|
| 17 | private AutoCompletingTextField editor = null;
|
---|
[8308] | 18 | private final transient DataSet ds;
|
---|
| 19 | private final transient Relation relation;
|
---|
[2512] | 20 |
|
---|
| 21 | /** user input is matched against this list of auto completion items */
|
---|
| 22 | private AutoCompletionList autoCompletionList = null;
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
[7556] | 25 | * Constructs a new {@code MemberRoleCellEditor}.
|
---|
| 26 | * @param ds the data set. Must not be null
|
---|
| 27 | * @param relation the relation. Can be null
|
---|
[2512] | 28 | */
|
---|
[7556] | 29 | public MemberRoleCellEditor(DataSet ds, Relation relation) {
|
---|
[3210] | 30 | this.ds = ds;
|
---|
[7556] | 31 | this.relation = relation;
|
---|
[8005] | 32 | editor = new AutoCompletingTextField(0, false);
|
---|
[6070] | 33 | editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
|
---|
[2512] | 34 | autoCompletionList = new AutoCompletionList();
|
---|
| 35 | editor.setAutoCompletionList(autoCompletionList);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[6084] | 38 | @Override
|
---|
[2512] | 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);
|
---|
[3214] | 44 | autoCompletionList.clear();
|
---|
[7556] | 45 | ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList, relation);
|
---|
[2512] | 46 | return editor;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[6084] | 49 | @Override
|
---|
[2512] | 50 | public Object getCellEditorValue() {
|
---|
| 51 | return editor.getText();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[4238] | 54 | /** Returns the edit field for this cell editor. */
|
---|
| 55 | public AutoCompletingTextField getEditor() {
|
---|
| 56 | return editor;
|
---|
| 57 | }
|
---|
[2512] | 58 | }
|
---|