Commit f00cb6bb29bf6e943301c56677b206aca5bb3dd6

Authored by Nathanael Jourdane
1 parent 667dd80c
Exists in master

Add a JComboBox for TargetNameField

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... ... @@ -10,6 +10,7 @@ import java.util.Locale;
10 10 import java.util.Objects;
11 11  
12 12 import javax.swing.BoxLayout;
  13 +import javax.swing.JComboBox;
13 14 import javax.swing.JLabel;
14 15 import javax.swing.JPanel;
15 16 import javax.swing.JTextField;
... ... @@ -161,22 +162,35 @@ public abstract class ParamField extends JPanel {
161 162 }
162 163  
163 164 public static class TargetNameField extends ParamField {
  165 + JComboBox<String> comboBox;
164 166 JTextField field;
  167 + String lastContent;
165 168  
166 169 TargetNameField(RequestView requestView, String paramName) {
167 170 super(requestView, paramName);
168   - field = new JTextField();
  171 + comboBox = new JComboBox();
  172 + comboBox.setEditable(true);
  173 + field = (JTextField) comboBox.getEditor().getEditorComponent();
169 174 addChangeListener(field, e -> onUpdate());
170   - field.setEditable(true);
171   - this.add(field);
  175 + this.add(comboBox);
  176 + }
  177 +
  178 + private String[] getTargetNames(String begining) {
  179 + String[] targetNames = { begining + "Bird", begining + "Cat", begining + "Dog" };
  180 + return targetNames;
172 181 }
173 182  
174 183 private void onUpdate() {
175   - // TODO: add resolver
176   - if ("".equals(field.getText())) {
177   - requestView.updateParam(paramName, null);
178   - } else {
179   - requestView.updateParam(paramName, field.getText());
  184 + String content = field.getText();
  185 + if (content.length() >= 2 && !content.equals(lastContent)) {
  186 + lastContent = content;
  187 + int nbItems = comboBox.getItemCount();
  188 + comboBox.removeAllItems();
  189 + for (String s : getTargetNames(content)) {
  190 + comboBox.addItem(s);
  191 + }
  192 + field.setText(content);
  193 + requestView.updateParam(paramName, content);
180 194 }
181 195 }
182 196 }
... ... @@ -186,7 +200,7 @@ public abstract class ParamField extends JPanel {
186 200  
187 201 DataProductTypeField(RequestView requestView, String paramName) {
188 202 super(requestView, paramName);
189   - field = new JTextField();
  203 + JTextField field = new JTextField();
190 204 // TODO: listbox with enumerated values instead of JTextField
191 205 addChangeListener(field, e -> onUpdate());
192 206 this.add(field);
... ...