From 3591966860cee5eedffbcae468eee5e19f792f7d Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 2 Mar 2016 15:54:32 +0100 Subject: [PATCH] Update the query when changing request parameters. --- src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java | 10 ++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 103 insertions(+), 23 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java index 10477a3..16193f1 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/utils/Queries.java @@ -49,8 +49,14 @@ public final class Queries { /** Minimal query to get TAP all services of the registry, using GloTS. */ public static final String GET_TAP_SERVICES = "SELECT ivoid, accessurl FROM glots.services"; - /** A sample query for tests. */ - public static final String SAMPLE_AMDA_QUERY = "SELECT TOP 5 index, resource_type, time_min, time_max FROM amdadb.epn_core"; + /** + * The default query, with these parameters, respectively: max_rows, target_name, time_min, + * time_max, dataproduct_type, spectral_range_min, spectral_range_max. + */ + public static final String SAMPLE_AMDA_QUERY = "SELECT TOP %s target_name, resource_type, instrument_name " + + "FROM amdadb.epn_core " + + "WHERE target_name = '%s', time_min=%f, time_max=%f, dataproduct_type=%s, " + + "spectral_range_min=%f, spectral_range_max=%f"; /** Constructor to hide the implicit public one. */ private Queries() { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java index b7c438b..a281c9f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java @@ -57,7 +57,7 @@ public class EpnTapMainView extends JPanel { /** The minimum width of the left panel (services view). */ static final int LEFT_PANEL_MIN_WIDTH = 100; /** The width of the right panel (request view). */ - static final int RIGHT_PANEL_WIDTH = 300; + static final int RIGHT_PANEL_WIDTH = 400; /** The minimum width of the right panel (request view). */ static final int RIGHT_PANEL_MIN_WIDTH = 100; diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java index b1653ff..9fec11e 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java @@ -30,6 +30,8 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -74,7 +76,46 @@ public class RequestView extends JPanel implements ActionListener { /** * @return A JPanel containing graphical elements for the service parameters. */ - private static JPanel buildParamPanel() { + private JPanel buildParamPanel() { + JTextField jtfTargetName = new JTextField("Jupiter"); + JFormattedTextField jtfMinTime = new JFormattedTextField(new Float(0.0)); + JFormattedTextField jtfMaxTime = new JFormattedTextField(new Float(1.0)); + JTextField jtfProductType = new JTextField("SpectralRange"); + JFormattedTextField jtfMinSpectralRange = new JFormattedTextField(new Float(0.0)); + JFormattedTextField jtfMaxSpectralRange = new JFormattedTextField(new Float(1.0)); + JFormattedTextField jtfMaxRows = new JFormattedTextField(new Integer(100)); + + DocumentListener paramListener = new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent de) { + try { + int maxRows = Integer.parseInt(jtfMaxRows.getText()); + String targetName = jtfTargetName.getText(); + float minTime = (float) jtfMinTime.getValue(); + float maxTime = (float) jtfMaxTime.getValue(); + String productType = jtfProductType.getText(); + float minSpectralRange = (float) jtfMinSpectralRange.getValue(); + float maxSpectralRange = (float) jtfMaxSpectralRange.getValue(); + + updateQueryArea(maxRows, targetName, minTime, maxTime, productType, + minSpectralRange, maxSpectralRange); + } catch (Exception e) { + logger.error("Can not parse parameters.", e); + } + + } + + @Override + public void removeUpdate(DocumentEvent de) { + insertUpdate(de); + } + + @Override + public void changedUpdate(DocumentEvent de) { + insertUpdate(de); + } + }; + JPanel paramPanel = new JPanel(new GridLayout(0, 2)); paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters")); @@ -82,38 +123,54 @@ public class RequestView extends JPanel implements ActionListener { JLabel targetNameLabel = new JLabel("Target name"); paramPanel.add(targetNameLabel); - JTextField targetName = new JTextField(10); - targetName.setToolTipText("The target name, for example 'Jupiter'."); - paramPanel.add(targetName); + jtfTargetName.getDocument().addDocumentListener(paramListener); + jtfTargetName.setToolTipText("The target name, for example 'Jupiter'."); + paramPanel.add(jtfTargetName); // Time JLabel timeLabel = new JLabel("Time (min, max)"); paramPanel.add(timeLabel); - JPanel timePanel = new JPanel(new GridLayout(0, 2)); - JFormattedTextField minTime = new JFormattedTextField(new Float(0.0)); - minTime.setToolTipText("The minimum time, for example '0.01'."); - timePanel.add(minTime); - JFormattedTextField maxTime = new JFormattedTextField(new Float(0.0)); - maxTime.setToolTipText("The maximum time, for example '1.50'."); - timePanel.add(maxTime); + + jtfMinTime.getDocument().addDocumentListener(paramListener); + jtfMinTime.setToolTipText("The minimum time, for example '0.01'."); + timePanel.add(jtfMinTime); + + jtfMaxTime.getDocument().addDocumentListener(paramListener); + jtfMaxTime.setToolTipText("The maximum time, for example '1.50'."); + timePanel.add(jtfMaxTime); paramPanel.add(timePanel); // Data product type - JLabel productTypeLabel = new JLabel("Data product type"); + JLabel productTypeLabel = new JLabel("Product type"); paramPanel.add(productTypeLabel); - JTextField productType = new JTextField(10); - productType.setToolTipText("The product type, for example '...'."); - paramPanel.add(productType); + jtfProductType.getDocument().addDocumentListener(paramListener); + jtfProductType.setToolTipText("The product type, for example '...'."); + paramPanel.add(jtfProductType); - // Spectral range JLabel spectralRangeLabel = new JLabel("Spectral range"); paramPanel.add(spectralRangeLabel); + JPanel spectralRangePanel = new JPanel(new GridLayout(0, 2)); - JTextField spectralRange = new JTextField(10); - spectralRange.setToolTipText("The spectral range, for example '...'."); - paramPanel.add(spectralRange); + jtfMinSpectralRange.getDocument().addDocumentListener(paramListener); + jtfMinSpectralRange.setToolTipText("The minimum spectral range, for example '0.01'."); + spectralRangePanel.add(jtfMinSpectralRange); + + jtfMaxSpectralRange.getDocument().addDocumentListener(paramListener); + jtfMaxSpectralRange.setToolTipText("The maximum spectral range, for example '1.50'."); + spectralRangePanel.add(jtfMaxSpectralRange); + + paramPanel.add(spectralRangePanel); + + // Number rows limit + JLabel maxRowsLabel = new JLabel("Rows limit"); + paramPanel.add(maxRowsLabel); + + jtfMaxRows.setName("targetName"); + jtfMaxRows.addActionListener(this); + jtfMaxRows.setToolTipText("The maximum number of rows to display."); + paramPanel.add(jtfMaxRows); return paramPanel; } @@ -124,7 +181,7 @@ public class RequestView extends JPanel implements ActionListener { private JPanel buildQueryPanel() { JPanel queryPanel = new JPanel(); queryPanel.setBorder(BorderFactory.createTitledBorder("Query for the selected service(s)")); - queryArea = new JTextArea(Queries.SAMPLE_AMDA_QUERY); + queryArea = new JTextArea(""); queryArea.setToolTipText("The query sent to the service(s)."); queryArea.setLineWrap(true); queryPanel.setLayout(new BorderLayout()); @@ -134,6 +191,21 @@ public class RequestView extends JPanel implements ActionListener { } /** + * @param max_rows + * @param target_name + * @param time_min + * @param time_max + * @param dataproduct_type + * @param spectral_range_min + * @param spectral_range_max + */ + private void updateQueryArea(int max_rows, String target_name, float time_min, float time_max, + String dataproduct_type, float spectral_range_min, float spectral_range_max) { + queryArea.setText(String.format(Queries.SAMPLE_AMDA_QUERY, max_rows, target_name, time_min, + time_max, dataproduct_type, spectral_range_min, spectral_range_max)); + } + + /** * @return A JPanel containing the button(s). */ private JPanel buildButtonPanel() { @@ -144,11 +216,13 @@ public class RequestView extends JPanel implements ActionListener { buttonPanel.add(btnSend); buttonPanel.setMaximumSize( new Dimension(EpnTapMainView.RIGHT_PANEL_WIDTH, BUTTON_PANEL_HEIGHT)); + return buttonPanel; } @Override public void actionPerformed(ActionEvent evt) { + System.out.println("blah"); if (((JButton) evt.getSource()).getName() == "btnSend") { try { mainView.getController().sendQuery(queryArea.getText()); -- libgit2 0.21.2