From f00cb6bb29bf6e943301c56677b206aca5bb3dd6 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Thu, 10 Mar 2016 10:17:34 +0100 Subject: [PATCH] Add a JComboBox for TargetNameField --- src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java index 1ed8098..870c1c4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.Objects; import javax.swing.BoxLayout; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; @@ -161,22 +162,35 @@ public abstract class ParamField extends JPanel { } public static class TargetNameField extends ParamField { + JComboBox comboBox; JTextField field; + String lastContent; TargetNameField(RequestView requestView, String paramName) { super(requestView, paramName); - field = new JTextField(); + comboBox = new JComboBox(); + comboBox.setEditable(true); + field = (JTextField) comboBox.getEditor().getEditorComponent(); addChangeListener(field, e -> onUpdate()); - field.setEditable(true); - this.add(field); + this.add(comboBox); + } + + private String[] getTargetNames(String begining) { + String[] targetNames = { begining + "Bird", begining + "Cat", begining + "Dog" }; + return targetNames; } private void onUpdate() { - // TODO: add resolver - if ("".equals(field.getText())) { - requestView.updateParam(paramName, null); - } else { - requestView.updateParam(paramName, field.getText()); + String content = field.getText(); + if (content.length() >= 2 && !content.equals(lastContent)) { + lastContent = content; + int nbItems = comboBox.getItemCount(); + comboBox.removeAllItems(); + for (String s : getTargetNames(content)) { + comboBox.addItem(s); + } + field.setText(content); + requestView.updateParam(paramName, content); } } } @@ -186,7 +200,7 @@ public abstract class ParamField extends JPanel { DataProductTypeField(RequestView requestView, String paramName) { super(requestView, paramName); - field = new JTextField(); + JTextField field = new JTextField(); // TODO: listbox with enumerated values instead of JTextField addChangeListener(field, e -> onUpdate()); this.add(field); -- libgit2 0.21.2