Commit 3591966860cee5eedffbcae468eee5e19f792f7d

Authored by Nathanael Jourdane
1 parent 204e830a
Exists in master

Update the query when changing request parameters.

src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java
... ... @@ -49,8 +49,14 @@ public final class Queries {
49 49 /** Minimal query to get TAP all services of the registry, using GloTS. */
50 50 public static final String GET_TAP_SERVICES = "SELECT ivoid, accessurl FROM glots.services";
51 51  
52   - /** A sample query for tests. */
53   - public static final String SAMPLE_AMDA_QUERY = "SELECT TOP 5 index, resource_type, time_min, time_max FROM amdadb.epn_core";
  52 + /**
  53 + * The default query, with these parameters, respectively: max_rows, target_name, time_min,
  54 + * time_max, dataproduct_type, spectral_range_min, spectral_range_max.
  55 + */
  56 + public static final String SAMPLE_AMDA_QUERY = "SELECT TOP %s target_name, resource_type, instrument_name "
  57 + + "FROM amdadb.epn_core "
  58 + + "WHERE target_name = '%s', time_min=%f, time_max=%f, dataproduct_type=%s, "
  59 + + "spectral_range_min=%f, spectral_range_max=%f";
54 60  
55 61 /** Constructor to hide the implicit public one. */
56 62 private Queries() {
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java
... ... @@ -57,7 +57,7 @@ public class EpnTapMainView extends JPanel {
57 57 /** The minimum width of the left panel (services view). */
58 58 static final int LEFT_PANEL_MIN_WIDTH = 100;
59 59 /** The width of the right panel (request view). */
60   - static final int RIGHT_PANEL_WIDTH = 300;
  60 + static final int RIGHT_PANEL_WIDTH = 400;
61 61 /** The minimum width of the right panel (request view). */
62 62 static final int RIGHT_PANEL_MIN_WIDTH = 100;
63 63  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java
... ... @@ -30,6 +30,8 @@ import javax.swing.JLabel;
30 30 import javax.swing.JPanel;
31 31 import javax.swing.JTextArea;
32 32 import javax.swing.JTextField;
  33 +import javax.swing.event.DocumentEvent;
  34 +import javax.swing.event.DocumentListener;
33 35  
34 36 import org.apache.logging.log4j.LogManager;
35 37 import org.apache.logging.log4j.Logger;
... ... @@ -74,7 +76,46 @@ public class RequestView extends JPanel implements ActionListener {
74 76 /**
75 77 * @return A JPanel containing graphical elements for the service parameters.
76 78 */
77   - private static JPanel buildParamPanel() {
  79 + private JPanel buildParamPanel() {
  80 + JTextField jtfTargetName = new JTextField("Jupiter");
  81 + JFormattedTextField jtfMinTime = new JFormattedTextField(new Float(0.0));
  82 + JFormattedTextField jtfMaxTime = new JFormattedTextField(new Float(1.0));
  83 + JTextField jtfProductType = new JTextField("SpectralRange");
  84 + JFormattedTextField jtfMinSpectralRange = new JFormattedTextField(new Float(0.0));
  85 + JFormattedTextField jtfMaxSpectralRange = new JFormattedTextField(new Float(1.0));
  86 + JFormattedTextField jtfMaxRows = new JFormattedTextField(new Integer(100));
  87 +
  88 + DocumentListener paramListener = new DocumentListener() {
  89 + @Override
  90 + public void insertUpdate(DocumentEvent de) {
  91 + try {
  92 + int maxRows = Integer.parseInt(jtfMaxRows.getText());
  93 + String targetName = jtfTargetName.getText();
  94 + float minTime = (float) jtfMinTime.getValue();
  95 + float maxTime = (float) jtfMaxTime.getValue();
  96 + String productType = jtfProductType.getText();
  97 + float minSpectralRange = (float) jtfMinSpectralRange.getValue();
  98 + float maxSpectralRange = (float) jtfMaxSpectralRange.getValue();
  99 +
  100 + updateQueryArea(maxRows, targetName, minTime, maxTime, productType,
  101 + minSpectralRange, maxSpectralRange);
  102 + } catch (Exception e) {
  103 + logger.error("Can not parse parameters.", e);
  104 + }
  105 +
  106 + }
  107 +
  108 + @Override
  109 + public void removeUpdate(DocumentEvent de) {
  110 + insertUpdate(de);
  111 + }
  112 +
  113 + @Override
  114 + public void changedUpdate(DocumentEvent de) {
  115 + insertUpdate(de);
  116 + }
  117 + };
  118 +
78 119 JPanel paramPanel = new JPanel(new GridLayout(0, 2));
79 120 paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters"));
80 121  
... ... @@ -82,38 +123,54 @@ public class RequestView extends JPanel implements ActionListener {
82 123 JLabel targetNameLabel = new JLabel("Target name");
83 124 paramPanel.add(targetNameLabel);
84 125  
85   - JTextField targetName = new JTextField(10);
86   - targetName.setToolTipText("The target name, for example 'Jupiter'.");
87   - paramPanel.add(targetName);
  126 + jtfTargetName.getDocument().addDocumentListener(paramListener);
  127 + jtfTargetName.setToolTipText("The target name, for example 'Jupiter'.");
  128 + paramPanel.add(jtfTargetName);
88 129  
89 130 // Time
90 131 JLabel timeLabel = new JLabel("Time (min, max)");
91 132 paramPanel.add(timeLabel);
92   -
93 133 JPanel timePanel = new JPanel(new GridLayout(0, 2));
94   - JFormattedTextField minTime = new JFormattedTextField(new Float(0.0));
95   - minTime.setToolTipText("The minimum time, for example '0.01'.");
96   - timePanel.add(minTime);
97   - JFormattedTextField maxTime = new JFormattedTextField(new Float(0.0));
98   - maxTime.setToolTipText("The maximum time, for example '1.50'.");
99   - timePanel.add(maxTime);
  134 +
  135 + jtfMinTime.getDocument().addDocumentListener(paramListener);
  136 + jtfMinTime.setToolTipText("The minimum time, for example '0.01'.");
  137 + timePanel.add(jtfMinTime);
  138 +
  139 + jtfMaxTime.getDocument().addDocumentListener(paramListener);
  140 + jtfMaxTime.setToolTipText("The maximum time, for example '1.50'.");
  141 + timePanel.add(jtfMaxTime);
100 142 paramPanel.add(timePanel);
101 143  
102 144 // Data product type
103   - JLabel productTypeLabel = new JLabel("Data product type");
  145 + JLabel productTypeLabel = new JLabel("Product type");
104 146 paramPanel.add(productTypeLabel);
105 147  
106   - JTextField productType = new JTextField(10);
107   - productType.setToolTipText("The product type, for example '...'.");
108   - paramPanel.add(productType);
  148 + jtfProductType.getDocument().addDocumentListener(paramListener);
  149 + jtfProductType.setToolTipText("The product type, for example '...'.");
  150 + paramPanel.add(jtfProductType);
109 151  
110   - // Spectral range
111 152 JLabel spectralRangeLabel = new JLabel("Spectral range");
112 153 paramPanel.add(spectralRangeLabel);
  154 + JPanel spectralRangePanel = new JPanel(new GridLayout(0, 2));
113 155  
114   - JTextField spectralRange = new JTextField(10);
115   - spectralRange.setToolTipText("The spectral range, for example '...'.");
116   - paramPanel.add(spectralRange);
  156 + jtfMinSpectralRange.getDocument().addDocumentListener(paramListener);
  157 + jtfMinSpectralRange.setToolTipText("The minimum spectral range, for example '0.01'.");
  158 + spectralRangePanel.add(jtfMinSpectralRange);
  159 +
  160 + jtfMaxSpectralRange.getDocument().addDocumentListener(paramListener);
  161 + jtfMaxSpectralRange.setToolTipText("The maximum spectral range, for example '1.50'.");
  162 + spectralRangePanel.add(jtfMaxSpectralRange);
  163 +
  164 + paramPanel.add(spectralRangePanel);
  165 +
  166 + // Number rows limit
  167 + JLabel maxRowsLabel = new JLabel("Rows limit");
  168 + paramPanel.add(maxRowsLabel);
  169 +
  170 + jtfMaxRows.setName("targetName");
  171 + jtfMaxRows.addActionListener(this);
  172 + jtfMaxRows.setToolTipText("The maximum number of rows to display.");
  173 + paramPanel.add(jtfMaxRows);
117 174  
118 175 return paramPanel;
119 176 }
... ... @@ -124,7 +181,7 @@ public class RequestView extends JPanel implements ActionListener {
124 181 private JPanel buildQueryPanel() {
125 182 JPanel queryPanel = new JPanel();
126 183 queryPanel.setBorder(BorderFactory.createTitledBorder("Query for the selected service(s)"));
127   - queryArea = new JTextArea(Queries.SAMPLE_AMDA_QUERY);
  184 + queryArea = new JTextArea("");
128 185 queryArea.setToolTipText("The query sent to the service(s).");
129 186 queryArea.setLineWrap(true);
130 187 queryPanel.setLayout(new BorderLayout());
... ... @@ -134,6 +191,21 @@ public class RequestView extends JPanel implements ActionListener {
134 191 }
135 192  
136 193 /**
  194 + * @param max_rows
  195 + * @param target_name
  196 + * @param time_min
  197 + * @param time_max
  198 + * @param dataproduct_type
  199 + * @param spectral_range_min
  200 + * @param spectral_range_max
  201 + */
  202 + private void updateQueryArea(int max_rows, String target_name, float time_min, float time_max,
  203 + String dataproduct_type, float spectral_range_min, float spectral_range_max) {
  204 + queryArea.setText(String.format(Queries.SAMPLE_AMDA_QUERY, max_rows, target_name, time_min,
  205 + time_max, dataproduct_type, spectral_range_min, spectral_range_max));
  206 + }
  207 +
  208 + /**
137 209 * @return A JPanel containing the button(s).
138 210 */
139 211 private JPanel buildButtonPanel() {
... ... @@ -144,11 +216,13 @@ public class RequestView extends JPanel implements ActionListener {
144 216 buttonPanel.add(btnSend);
145 217 buttonPanel.setMaximumSize(
146 218 new Dimension(EpnTapMainView.RIGHT_PANEL_WIDTH, BUTTON_PANEL_HEIGHT));
  219 +
147 220 return buttonPanel;
148 221 }
149 222  
150 223 @Override
151 224 public void actionPerformed(ActionEvent evt) {
  225 + System.out.println("blah");
152 226 if (((JButton) evt.getSource()).getName() == "btnSend") {
153 227 try {
154 228 mainView.getController().sendQuery(queryArea.getText());
... ...