Commit a99d92fa850d8cce41953cc83031189a0e5f9449

Authored by Nathanael Jourdane
1 parent 05b140ed
Exists in master

Add JComboBox for dataProductType and targetClass

src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
@@ -2,6 +2,8 @@ package eu.omp.irap.vespa.epntapclient.view; @@ -2,6 +2,8 @@ package eu.omp.irap.vespa.epntapclient.view;
2 2
3 import java.awt.Color; 3 import java.awt.Color;
4 import java.awt.Dimension; 4 import java.awt.Dimension;
  5 +import java.awt.event.ActionEvent;
  6 +import java.awt.event.ActionListener;
5 import java.beans.PropertyChangeEvent; 7 import java.beans.PropertyChangeEvent;
6 import java.text.DateFormat; 8 import java.text.DateFormat;
7 import java.text.ParseException; 9 import java.text.ParseException;
@@ -184,7 +186,7 @@ public abstract class ParamField extends JPanel { @@ -184,7 +186,7 @@ public abstract class ParamField extends JPanel {
184 this.add(comboBox); 186 this.add(comboBox);
185 } 187 }
186 188
187 - private String[] getTargetNames(String begining) { 189 + private String[] getItems(String begining) {
188 StringBuilder resolverResult = null; 190 StringBuilder resolverResult = null;
189 try { 191 try {
190 resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\""); 192 resolverResult = VOTableConnection.sendGet(RESOLVER_URL, "q=\"" + begining + "\"");
@@ -209,7 +211,7 @@ public abstract class ParamField extends JPanel { @@ -209,7 +211,7 @@ public abstract class ParamField extends JPanel {
209 lastContent = content; 211 lastContent = content;
210 int nbItems = comboBox.getItemCount(); 212 int nbItems = comboBox.getItemCount();
211 comboBox.removeAllItems(); 213 comboBox.removeAllItems();
212 - for (String s : getTargetNames(content)) { 214 + for (String s : getItems(content)) {
213 comboBox.addItem(s); 215 comboBox.addItem(s);
214 } 216 }
215 field.setText(content); 217 field.setText(content);
@@ -219,42 +221,54 @@ public abstract class ParamField extends JPanel { @@ -219,42 +221,54 @@ public abstract class ParamField extends JPanel {
219 } 221 }
220 222
221 public static class DataProductTypeField extends ParamField { 223 public static class DataProductTypeField extends ParamField {
222 - JTextField field; 224 + JComboBox<String> comboBox;
223 225
224 DataProductTypeField(RequestView requestView, String paramName) { 226 DataProductTypeField(RequestView requestView, String paramName) {
225 super(requestView, paramName); 227 super(requestView, paramName);
226 - JTextField field = new JTextField();  
227 - // TODO: listbox with enumerated values instead of JTextField  
228 - addChangeListener(field, e -> onUpdate());  
229 - this.add(field); 228 + comboBox = new JComboBox(getItems());
  229 + comboBox.addActionListener(new ActionListener() {
  230 + @Override
  231 + public void actionPerformed(ActionEvent e) {
  232 + onUpdate();
  233 + }
  234 + });
  235 + this.add(comboBox);
  236 + }
  237 +
  238 + private String[] getItems() {
  239 + return new String[] { "All", "Image", "Spectrum", "Dynamic spectrum", "Spectral cube",
  240 + "Profile", "Volume", "Movie", "Cube" };
230 } 241 }
231 242
232 private void onUpdate() { 243 private void onUpdate() {
233 - if ("".equals(field.getText())) {  
234 - requestView.updateParam(paramName, null);  
235 - } else {  
236 - requestView.updateParam(paramName, field.getText());  
237 - } 244 + String value = comboBox.getSelectedItem().toString().replace(" ", "-").toLowerCase();
  245 + requestView.updateParam(paramName, "All".equals(value) ? null : value);
238 } 246 }
239 } 247 }
240 248
241 public static class TargetClassField extends ParamField { 249 public static class TargetClassField extends ParamField {
242 - JTextField field; 250 + JComboBox<String> comboBox;
243 251
244 TargetClassField(RequestView requestView, String paramName) { 252 TargetClassField(RequestView requestView, String paramName) {
245 super(requestView, paramName); 253 super(requestView, paramName);
246 - JTextField field = new JTextField();  
247 - // TODO: listbox with enumerated values instead of JTextField  
248 - addChangeListener(field, e -> onUpdate());  
249 - this.add(field); 254 + comboBox = new JComboBox(getItems());
  255 + comboBox.addActionListener(new ActionListener() {
  256 + @Override
  257 + public void actionPerformed(ActionEvent e) {
  258 + onUpdate();
  259 + }
  260 + });
  261 + this.add(comboBox);
  262 + }
  263 +
  264 + private String[] getItems() {
  265 + return new String[] { "All", "Comet", "Exoplanet", "Interplanetary medium", "Ring",
  266 + "Sample", "Sky", "Spacecraft", "Spacejunk", "Star" };
250 } 267 }
251 268
252 private void onUpdate() { 269 private void onUpdate() {
253 - if ("".equals(field.getText())) {  
254 - requestView.updateParam(paramName, null);  
255 - } else {  
256 - requestView.updateParam(paramName, field.getText());  
257 - } 270 + String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase();
  271 + requestView.updateParam(paramName, "All".equals(value) ? null : value);
258 } 272 }
259 } 273 }
260 274