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 e3ffdbf..c21cebc 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 @@ -2,6 +2,8 @@ package eu.omp.irap.vespa.epntapclient.view; import java.awt.Color; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.text.DateFormat; import java.text.ParseException; @@ -184,7 +186,7 @@ public abstract class ParamField extends JPanel { this.add(comboBox); } - private String[] getTargetNames(String begining) { + private String[] getItems(String begining) { StringBuilder resolverResult = null; try { resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); @@ -209,7 +211,7 @@ public abstract class ParamField extends JPanel { lastContent = content; int nbItems = comboBox.getItemCount(); comboBox.removeAllItems(); - for (String s : getTargetNames(content)) { + for (String s : getItems(content)) { comboBox.addItem(s); } field.setText(content); @@ -219,42 +221,54 @@ public abstract class ParamField extends JPanel { } public static class DataProductTypeField extends ParamField { - JTextField field; + JComboBox comboBox; DataProductTypeField(RequestView requestView, String paramName) { super(requestView, paramName); - JTextField field = new JTextField(); - // TODO: listbox with enumerated values instead of JTextField - addChangeListener(field, e -> onUpdate()); - this.add(field); + comboBox = new JComboBox(getItems()); + comboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + onUpdate(); + } + }); + this.add(comboBox); + } + + private String[] getItems() { + return new String[] { "All", "Image", "Spectrum", "Dynamic spectrum", "Spectral cube", + "Profile", "Volume", "Movie", "Cube" }; } private void onUpdate() { - if ("".equals(field.getText())) { - requestView.updateParam(paramName, null); - } else { - requestView.updateParam(paramName, field.getText()); - } + String value = comboBox.getSelectedItem().toString().replace(" ", "-").toLowerCase(); + requestView.updateParam(paramName, "All".equals(value) ? null : value); } } public static class TargetClassField extends ParamField { - JTextField field; + JComboBox comboBox; TargetClassField(RequestView requestView, String paramName) { super(requestView, paramName); - JTextField field = new JTextField(); - // TODO: listbox with enumerated values instead of JTextField - addChangeListener(field, e -> onUpdate()); - this.add(field); + comboBox = new JComboBox(getItems()); + comboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + onUpdate(); + } + }); + this.add(comboBox); + } + + private String[] getItems() { + return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring", + "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" }; } private void onUpdate() { - if ("".equals(field.getText())) { - requestView.updateParam(paramName, null); - } else { - requestView.updateParam(paramName, field.getText()); - } + String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase(); + requestView.updateParam(paramName, "All".equals(value) ? null : value); } } -- libgit2 0.21.2