Ignore:
Timestamp:
2016-07-10T22:57:04+02:00 (8 years ago)
Author:
simon04
Message:

JOSM/wikipedia: allow to specify target key (such as operator:wikidata) - #josm12039

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikidataItemSearchDialog.java

    r32626 r32627  
    66import java.awt.Component;
    77import java.awt.Dimension;
     8import java.awt.GridBagLayout;
    89import java.awt.event.ActionEvent;
    910import java.awt.event.ActionListener;
     
    1516
    1617import javax.swing.DefaultListCellRenderer;
     18import javax.swing.JLabel;
    1719import javax.swing.JList;
     20import javax.swing.JPanel;
    1821
    1922import org.openstreetmap.josm.Main;
    2023import org.openstreetmap.josm.actions.JosmAction;
     24import org.openstreetmap.josm.data.osm.Tag;
    2125import org.openstreetmap.josm.gui.ExtendedDialog;
     26import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
     27import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    2228import org.openstreetmap.josm.gui.util.GuiHelper;
    2329import org.openstreetmap.josm.gui.widgets.SearchTextResultListPanel;
     30import org.openstreetmap.josm.tools.GBC;
    2431import org.openstreetmap.josm.tools.Utils;
    2532
     
    2734
    2835    private final Selector selector;
     36    private final AutoCompletingComboBox targetKey;
    2937    private static final WikidataItemSearchDialog INSTANCE = new WikidataItemSearchDialog();
    3038
    3139    private WikidataItemSearchDialog() {
    32         super(Main.parent, tr("Search Wikidata items"), new String[]{tr("Add ''wikipedia'' tag"), tr("Cancel")});
     40        super(Main.parent, tr("Search Wikidata items"), new String[]{tr("Add Tag"), tr("Cancel")});
    3341        this.selector = new Selector();
    3442        this.selector.setDblClickListener(new ActionListener() {
     
    3846            }
    3947        });
    40         setContent(selector, false);
     48        this.targetKey = new AutoCompletingComboBox();
     49        this.targetKey.setSelectedItem(new AutoCompletionListItem("wikidata"));
     50
     51        final JPanel panel = new JPanel(new GridBagLayout());
     52        panel.add(selector, GBC.eop().fill(GBC.BOTH));
     53        panel.add(new JLabel(tr("Target key: ")));
     54        panel.add(targetKey, GBC.eol().fill(GBC.HORIZONTAL));
     55        setContent(panel, false);
    4156        setPreferredSize(new Dimension(600, 300));
    4257    }
     
    5368    @Override
    5469    public ExtendedDialog showDialog() {
     70        initTargetKeys();
    5571        selector.init();
    5672        super.showDialog();
    5773        selector.clearSelection();
     74        selector.requestFocus();
    5875        return this;
     76    }
     77
     78    private void initTargetKeys() {
     79        final List<AutoCompletionListItem> keys = Main.getLayerManager().getEditLayer().data.getAutoCompletionManager().getKeys();
     80        targetKey.setPossibleACItems(keys);
     81        targetKey.setEditable(true);
    5982    }
    6083
     
    6588            return;
    6689        }
    67         WikipediaToggleDialog.AddWikipediaTagAction.addTag(selector.getSelectedItem());
     90        final WikipediaApp.WikidataEntry selected = selector.getSelectedItem();
     91        if (selected == null) {
     92            return;
     93        }
     94        final String key = Tag.removeWhiteSpaces(targetKey.getEditor().getItem().toString());
     95        final String value = selected.createWikipediaTag().getValue();
     96        WikipediaToggleDialog.AddWikipediaTagAction.addTag(new Tag(key, value));
    6897    }
    6998
Note: See TracChangeset for help on using the changeset viewer.