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,6 +10,7 @@ import java.util.Locale;
10 import java.util.Objects; 10 import java.util.Objects;
11 11
12 import javax.swing.BoxLayout; 12 import javax.swing.BoxLayout;
  13 +import javax.swing.JComboBox;
13 import javax.swing.JLabel; 14 import javax.swing.JLabel;
14 import javax.swing.JPanel; 15 import javax.swing.JPanel;
15 import javax.swing.JTextField; 16 import javax.swing.JTextField;
@@ -161,22 +162,35 @@ public abstract class ParamField extends JPanel { @@ -161,22 +162,35 @@ public abstract class ParamField extends JPanel {
161 } 162 }
162 163
163 public static class TargetNameField extends ParamField { 164 public static class TargetNameField extends ParamField {
  165 + JComboBox<String> comboBox;
164 JTextField field; 166 JTextField field;
  167 + String lastContent;
165 168
166 TargetNameField(RequestView requestView, String paramName) { 169 TargetNameField(RequestView requestView, String paramName) {
167 super(requestView, paramName); 170 super(requestView, paramName);
168 - field = new JTextField(); 171 + comboBox = new JComboBox();
  172 + comboBox.setEditable(true);
  173 + field = (JTextField) comboBox.getEditor().getEditorComponent();
169 addChangeListener(field, e -> onUpdate()); 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 private void onUpdate() { 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,7 +200,7 @@ public abstract class ParamField extends JPanel {
186 200
187 DataProductTypeField(RequestView requestView, String paramName) { 201 DataProductTypeField(RequestView requestView, String paramName) {
188 super(requestView, paramName); 202 super(requestView, paramName);
189 - field = new JTextField(); 203 + JTextField field = new JTextField();
190 // TODO: listbox with enumerated values instead of JTextField 204 // TODO: listbox with enumerated values instead of JTextField
191 addChangeListener(field, e -> onUpdate()); 205 addChangeListener(field, e -> onUpdate());
192 this.add(field); 206 this.add(field);