From b9fc63f5874932e6d2799f6cbe4dca935bbf2b90 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Fri, 20 May 2016 13:06:47 +0200 Subject: [PATCH] Add the possibility to query both selected and custom services. --- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java | 2 ++ src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java | 3 ++- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java | 5 ++--- src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++---------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java | 1 + src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java | 66 +++++++++++++++++++++++++++++++----------------------------------- 6 files changed, 85 insertions(+), 49 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java index 58d4ed4..693f1f5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java @@ -130,6 +130,8 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener public void sendQuery() { List servicesUrls = servicesPanelCtrl.getSelectedServicesUrls(); List tableNames = servicesPanelCtrl.getSelectedTablesNames(); + servicesUrls.addAll(servicesPanelCtrl.getCustomServicesUrls()); + tableNames.addAll(servicesPanelCtrl.getCustomTablesNames()); try { for (int i = 0; i < servicesUrls.size(); i++) { String query = requestPanelCtrl.getQuery(tableNames.get(i)); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java index e0b3854..fd1904c 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java @@ -102,7 +102,8 @@ public abstract class ParamField extends JPanel { * @param changeListener The listener of text fields. * @param field The field to listen. */ - static void addChangeListener(final TextFieldListener changeListener, final JTextField field) { + public static void addChangeListener(final TextFieldListener changeListener, + final JTextField field) { field.getDocument().addDocumentListener(new DocumentListener() { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java index 0dbef22..5388d0f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -66,8 +65,8 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis } @Override - public void onRowsSelected(List selectedRows) { - LOGGER.info("Selected row: " + StringJoiner.join(selectedRows)); + public void onRowsSelected() { + LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows())); } @Override diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java index 4b4f461..bc6a7ec 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java @@ -17,6 +17,7 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Logger; @@ -50,6 +51,12 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane /** The list of services target Urls selected by the user on the service panel. */ private List selectedServicesUrls; + /** The list of services table names selected by the user on the service panel. */ + private List customTablesNames; + + /** The list of services target Urls selected by the user on the service panel. */ + private List customServicesUrls; + /** The listener of the main panel. */ private MainPanelListener listener; @@ -87,28 +94,58 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane return selectedServicesUrls; } + /** + * @return The list of services table names entered by the user in the text field. + */ + public List getCustomTablesNames() { + return customTablesNames; + } + + /** + * @return The list of services target Urls entered by the user in the text field. + */ + public List getCustomServicesUrls() { + return customServicesUrls; + } + @Override - public void onRowsSelected(List selectedRows) { + public void onRowsSelected() { List servicesUrls = new ArrayList<>(); List tableNames = new ArrayList<>(); - String customServiceUrl = view.getServiceUrlTextField().getText(); - String customTableName = view.getTableNameTextField().getText(); - for (int row : selectedRows) { + for (int row : view.getSelectedRows()) { servicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row)); tableNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row)); } - if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) { - servicesUrls.add(customServiceUrl); - tableNames.add(customTableName); - } selectedServicesUrls = servicesUrls; selectedTablesNames = tableNames; - LOGGER.info("Selected services URLs: " + StringJoiner.join(selectedServicesUrls)); - LOGGER.info("Selected tables names: " + StringJoiner.join(selectedTablesNames)); listener.updateQuery(); + LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedServicesUrls)); + LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTablesNames)); } + @Override + public void onCustomServiceUpdated() { + String customServiceUrl = view.getServiceUrlTextField().getText(); + String customTableName = view.getTableNameTextField().getText(); + + if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) { + List servicesUrls = new ArrayList<>(); + List tableNames = new ArrayList<>(); + + servicesUrls.addAll(Arrays.asList(customServiceUrl.split(";"))); + tableNames.addAll(Arrays.asList(customTableName.split(";"))); + + if (servicesUrls.size() == tableNames.size()) { + // TODO: regex to check valid url / table name + customServicesUrls = servicesUrls; + customTablesNames = tableNames; + LOGGER.info( + "Updated custom services URLs: " + StringJoiner.join(customServicesUrls)); + LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTablesNames)); + } + } + } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java index a7d876d..4e465f9 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java @@ -23,4 +23,5 @@ import eu.omp.irap.vespa.votable.view.VOTableViewListener; */ public interface ServicesPanelListener extends VOTableViewListener { + public void onCustomServiceUpdated(); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java index 21a9c27..32182a9 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java @@ -17,13 +17,12 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import eu.omp.irap.vespa.votable.view.VOTableView; @@ -38,12 +37,6 @@ public class ServicesPanelView extends VOTableView { /** The listener of the services panel view. */ ServicesPanelListener listener; - /** - * The button which update the query based on the table name textField and the service URL - * textField. - */ - private JButton serviceButton; - /** The text field to manually set the service URL. */ private JTextField serviceUrlTextField; @@ -65,23 +58,47 @@ public class ServicesPanelView extends VOTableView { /** Build the service panel and add the graphical elements on it. */ private void buildServicesPanel() { + serviceUrlTextField = new JTextField(10); + addEventListener(serviceUrlTextField); + tableNameTextField = new JTextField(10); + addEventListener(tableNameTextField); + JPanel addServicePanel = new JPanel(); addServicePanel.add(new JLabel("Service URL")); - addServicePanel.add(getServiceUrlTextField()); + addServicePanel.add(serviceUrlTextField); addServicePanel.add(new JLabel("Table name")); - addServicePanel.add(getTableNameTextField()); - addServicePanel.add(getServiceButton()); + addServicePanel.add(tableNameTextField); add(addServicePanel, BorderLayout.SOUTH); } + public void addEventListener(JTextField textField) { + textField.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void changedUpdate(DocumentEvent e) { + listener.onCustomServiceUpdated(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + listener.onCustomServiceUpdated(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + listener.onCustomServiceUpdated(); + } + }); + } + /** * Returns the field to set a custom table name. Create it if doesn't exist. * * @return The table name JTextField. */ public JTextField getTableNameTextField() { - return tableNameTextField == null ? new JTextField(10) : tableNameTextField; + return tableNameTextField; } /** @@ -90,28 +107,7 @@ public class ServicesPanelView extends VOTableView { * @return The service URL JTextField. */ public JTextField getServiceUrlTextField() { - return serviceUrlTextField == null ? new JTextField(10) : serviceUrlTextField; - } - - /** - * Returns the button which update the query based on the table name textField and the service - * URL textField. Create it if doesn't exist. - * - * @return The JButton to set the custom service, create it if doesn't exist. - */ - private JButton getServiceButton() { - if (serviceButton == null) { - serviceButton = new JButton("Set service"); - - serviceButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - listener.onRowsSelected(null); - } - }); - } - return serviceButton; + return serviceUrlTextField; } } -- libgit2 0.21.2