Commit 5ea2b82c8a302ee50a09896a806f8c30b188ede9

Authored by Nathanael Jourdane
1 parent 78b61aa3
Exists in master

Implement several types of parameter fields

src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java
@@ -18,24 +18,27 @@ package eu.omp.irap.vespa.epntapclient.view; @@ -18,24 +18,27 @@ package eu.omp.irap.vespa.epntapclient.view;
18 18
19 import java.awt.BorderLayout; 19 import java.awt.BorderLayout;
20 import java.awt.Dimension; 20 import java.awt.Dimension;
21 -import java.awt.GridLayout;  
22 import java.awt.event.ActionEvent; 21 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener; 22 import java.awt.event.ActionListener;
  23 +import java.util.ArrayList;
24 import java.util.HashMap; 24 import java.util.HashMap;
  25 +import java.util.List;
25 import java.util.Map; 26 import java.util.Map;
26 27
27 import javax.swing.BorderFactory; 28 import javax.swing.BorderFactory;
28 import javax.swing.BoxLayout; 29 import javax.swing.BoxLayout;
29 import javax.swing.JButton; 30 import javax.swing.JButton;
30 -import javax.swing.JLabel;  
31 import javax.swing.JPanel; 31 import javax.swing.JPanel;
32 import javax.swing.JTextArea; 32 import javax.swing.JTextArea;
33 -import javax.swing.JTextField;  
34 33
35 import org.apache.logging.log4j.LogManager; 34 import org.apache.logging.log4j.LogManager;
36 import org.apache.logging.log4j.Logger; 35 import org.apache.logging.log4j.Logger;
37 36
38 import eu.omp.irap.vespa.epntapclient.utils.Queries; 37 import eu.omp.irap.vespa.epntapclient.utils.Queries;
  38 +import eu.omp.irap.vespa.epntapclient.view.ParamField.DataProductTypeField;
  39 +import eu.omp.irap.vespa.epntapclient.view.ParamField.DateRangeField;
  40 +import eu.omp.irap.vespa.epntapclient.view.ParamField.FloatRangeField;
  41 +import eu.omp.irap.vespa.epntapclient.view.ParamField.TargetNameField;
39 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; 42 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException;
40 43
41 /** 44 /**
@@ -56,18 +59,17 @@ public class RequestView extends JPanel implements ActionListener { @@ -56,18 +59,17 @@ public class RequestView extends JPanel implements ActionListener {
56 private JTextArea queryArea; 59 private JTextArea queryArea;
57 60
58 // TODO: Use one map for paramFields, paramValues, paramTypes. 61 // TODO: Use one map for paramFields, paramValues, paramTypes.
  62 +
59 /** 63 /**
60 * The parameters fields for the request. 64 * The parameters fields for the request.
61 */ 65 */
62 - private Map<String, JTextField> paramFields; 66 + private List<ParamField> paramFields;
63 67
64 /** 68 /**
65 * The parameters fields for the request. 69 * The parameters fields for the request.
66 */ 70 */
67 private Map<String, Object> paramValues; 71 private Map<String, Object> paramValues;
68 72
69 - private Map<String, Class> paramTypes;  
70 -  
71 /** The height of the buttons panel. */ 73 /** The height of the buttons panel. */
72 private static final int BUTTON_PANEL_HEIGHT = 15; 74 private static final int BUTTON_PANEL_HEIGHT = 15;
73 75
@@ -81,15 +83,6 @@ public class RequestView extends JPanel implements ActionListener { @@ -81,15 +83,6 @@ public class RequestView extends JPanel implements ActionListener {
81 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 83 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
82 84
83 // TODO: Get max row number from the GUI 85 // TODO: Get max row number from the GUI
84 - // TODO: auto-building range field by checking *_min / *_max attribute names  
85 -  
86 - paramTypes = new HashMap<>();  
87 - paramTypes.put("target_name", String.class);  
88 - paramTypes.put("dataproduct_type", String.class);  
89 - paramTypes.put("minTime", Float.class);  
90 - paramTypes.put("maxTime", Float.class);  
91 - paramTypes.put("spectral_range_min", Float.class);  
92 - paramTypes.put("spectral_range_max", Float.class);  
93 86
94 paramValues = new HashMap<>(); 87 paramValues = new HashMap<>();
95 88
@@ -102,26 +95,21 @@ public class RequestView extends JPanel implements ActionListener { @@ -102,26 +95,21 @@ public class RequestView extends JPanel implements ActionListener {
102 * @return A JPanel containing graphical elements for the service parameters. 95 * @return A JPanel containing graphical elements for the service parameters.
103 */ 96 */
104 private JPanel buildParamPanel() { 97 private JPanel buildParamPanel() {
105 - paramFields = new HashMap();  
106 -  
107 - // TODO: Find a way to set numerical value to "" by default.  
108 // TODO: new GUI field column to allow the user to select the comparison operator: 98 // TODO: new GUI field column to allow the user to select the comparison operator:
109 // - if the field is a String: listbox with 'xx', '%xx', 'xx%', and '%xx%'. 99 // - if the field is a String: listbox with 'xx', '%xx', 'xx%', and '%xx%'.
110 // - if the field is a numeric value: listbox with <, <=, =, =>, >. 100 // - if the field is a numeric value: listbox with <, <=, =, =>, >.
111 - for (Map.Entry<String, Class> paramType : paramTypes.entrySet()) {  
112 - paramFields.put(paramType.getKey(),  
113 - new ParamField(this, paramType.getKey(), paramType.getValue()));  
114 - }  
115 -  
116 - JPanel paramPanel = new JPanel(new GridLayout(0, 2)); 101 + paramFields = new ArrayList();
  102 + paramFields.add(new TargetNameField(this, "target_name"));
  103 + paramFields.add(new DateRangeField(this, "time_"));
  104 + paramFields.add(new FloatRangeField(this, "spectral_range_"));
  105 + paramFields.add(new DataProductTypeField(this, "dataproduct_type"));
  106 +
  107 + JPanel paramPanel = new JPanel();
  108 + paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.Y_AXIS));
117 paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters")); 109 paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters"));
118 110
119 - for (Map.Entry<String, JTextField> e : paramFields.entrySet()) {  
120 - JLabel label = new JLabel(e.getKey());  
121 - paramPanel.add(label);  
122 -  
123 - // TODO: Add tooltip text based on rr.table_column.column_description  
124 - paramPanel.add(e.getValue()); 111 + for (ParamField field : paramFields) {
  112 + paramPanel.add(field);
125 } 113 }
126 114
127 return paramPanel; 115 return paramPanel;
@@ -145,6 +133,7 @@ public class RequestView extends JPanel implements ActionListener { @@ -145,6 +133,7 @@ public class RequestView extends JPanel implements ActionListener {
145 public void updateParam(String paramName, Object value) { 133 public void updateParam(String paramName, Object value) {
146 logger.info("uploading " + paramName + ": " + value); 134 logger.info("uploading " + paramName + ": " + value);
147 paramValues.put(paramName, value); 135 paramValues.put(paramName, value);
  136 + updateQueryArea();
148 } 137 }
149 138
150 /** 139 /**