Commit b9fc63f5874932e6d2799f6cbe4dca935bbf2b90

Authored by Nathanael Jourdane
1 parent 419a23a7
Exists in master

Add the possibility to query both selected and custom services.

src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
... ... @@ -130,6 +130,8 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
130 130 public void sendQuery() {
131 131 List<String> servicesUrls = servicesPanelCtrl.getSelectedServicesUrls();
132 132 List<String> tableNames = servicesPanelCtrl.getSelectedTablesNames();
  133 + servicesUrls.addAll(servicesPanelCtrl.getCustomServicesUrls());
  134 + tableNames.addAll(servicesPanelCtrl.getCustomTablesNames());
133 135 try {
134 136 for (int i = 0; i < servicesUrls.size(); i++) {
135 137 String query = requestPanelCtrl.getQuery(tableNames.get(i));
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/ParamField.java
... ... @@ -102,7 +102,8 @@ public abstract class ParamField extends JPanel {
102 102 * @param changeListener The listener of text fields.
103 103 * @param field The field to listen.
104 104 */
105   - static void addChangeListener(final TextFieldListener changeListener, final JTextField field) {
  105 + public static void addChangeListener(final TextFieldListener changeListener,
  106 + final JTextField field) {
106 107  
107 108 field.getDocument().addDocumentListener(new DocumentListener() {
108 109  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java
... ... @@ -20,7 +20,6 @@ import java.io.File;
20 20 import java.io.IOException;
21 21 import java.nio.file.Files;
22 22 import java.nio.file.Paths;
23   -import java.util.List;
24 23 import java.util.logging.Level;
25 24 import java.util.logging.Logger;
26 25  
... ... @@ -66,8 +65,8 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis
66 65 }
67 66  
68 67 @Override
69   - public void onRowsSelected(List<Integer> selectedRows) {
70   - LOGGER.info("Selected row: " + StringJoiner.join(selectedRows));
  68 + public void onRowsSelected() {
  69 + LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows()));
71 70 }
72 71  
73 72 @Override
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java
... ... @@ -17,6 +17,7 @@
17 17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
18 18  
19 19 import java.util.ArrayList;
  20 +import java.util.Arrays;
20 21 import java.util.List;
21 22 import java.util.logging.Logger;
22 23  
... ... @@ -50,6 +51,12 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
50 51 /** The list of services target Urls selected by the user on the service panel. */
51 52 private List<String> selectedServicesUrls;
52 53  
  54 + /** The list of services table names selected by the user on the service panel. */
  55 + private List<String> customTablesNames;
  56 +
  57 + /** The list of services target Urls selected by the user on the service panel. */
  58 + private List<String> customServicesUrls;
  59 +
53 60 /** The listener of the main panel. */
54 61 private MainPanelListener listener;
55 62  
... ... @@ -87,28 +94,58 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
87 94 return selectedServicesUrls;
88 95 }
89 96  
  97 + /**
  98 + * @return The list of services table names entered by the user in the text field.
  99 + */
  100 + public List<String> getCustomTablesNames() {
  101 + return customTablesNames;
  102 + }
  103 +
  104 + /**
  105 + * @return The list of services target Urls entered by the user in the text field.
  106 + */
  107 + public List<String> getCustomServicesUrls() {
  108 + return customServicesUrls;
  109 + }
  110 +
90 111 @Override
91   - public void onRowsSelected(List<Integer> selectedRows) {
  112 + public void onRowsSelected() {
92 113 List<String> servicesUrls = new ArrayList<>();
93 114 List<String> tableNames = new ArrayList<>();
94   - String customServiceUrl = view.getServiceUrlTextField().getText();
95   - String customTableName = view.getTableNameTextField().getText();
96 115  
97   - for (int row : selectedRows) {
  116 + for (int row : view.getSelectedRows()) {
98 117 servicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row));
99 118 tableNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row));
100 119 }
101   - if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) {
102   - servicesUrls.add(customServiceUrl);
103   - tableNames.add(customTableName);
104   - }
105 120  
106 121 selectedServicesUrls = servicesUrls;
107 122 selectedTablesNames = tableNames;
108   - LOGGER.info("Selected services URLs: " + StringJoiner.join(selectedServicesUrls));
109   - LOGGER.info("Selected tables names: " + StringJoiner.join(selectedTablesNames));
110 123  
111 124 listener.updateQuery();
  125 + LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedServicesUrls));
  126 + LOGGER.info("Updated selected tables names: " + StringJoiner.join(selectedTablesNames));
112 127 }
113 128  
  129 + @Override
  130 + public void onCustomServiceUpdated() {
  131 + String customServiceUrl = view.getServiceUrlTextField().getText();
  132 + String customTableName = view.getTableNameTextField().getText();
  133 +
  134 + if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) {
  135 + List<String> servicesUrls = new ArrayList<>();
  136 + List<String> tableNames = new ArrayList<>();
  137 +
  138 + servicesUrls.addAll(Arrays.asList(customServiceUrl.split(";")));
  139 + tableNames.addAll(Arrays.asList(customTableName.split(";")));
  140 +
  141 + if (servicesUrls.size() == tableNames.size()) {
  142 + // TODO: regex to check valid url / table name
  143 + customServicesUrls = servicesUrls;
  144 + customTablesNames = tableNames;
  145 + LOGGER.info(
  146 + "Updated custom services URLs: " + StringJoiner.join(customServicesUrls));
  147 + LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTablesNames));
  148 + }
  149 + }
  150 + }
114 151 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelListener.java
... ... @@ -23,4 +23,5 @@ import eu.omp.irap.vespa.votable.view.VOTableViewListener;
23 23 */
24 24 public interface ServicesPanelListener extends VOTableViewListener {
25 25  
  26 + public void onCustomServiceUpdated();
26 27 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java
... ... @@ -17,13 +17,12 @@
17 17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
18 18  
19 19 import java.awt.BorderLayout;
20   -import java.awt.event.ActionEvent;
21   -import java.awt.event.ActionListener;
22 20  
23   -import javax.swing.JButton;
24 21 import javax.swing.JLabel;
25 22 import javax.swing.JPanel;
26 23 import javax.swing.JTextField;
  24 +import javax.swing.event.DocumentEvent;
  25 +import javax.swing.event.DocumentListener;
27 26  
28 27 import eu.omp.irap.vespa.votable.view.VOTableView;
29 28  
... ... @@ -38,12 +37,6 @@ public class ServicesPanelView extends VOTableView {
38 37 /** The listener of the services panel view. */
39 38 ServicesPanelListener listener;
40 39  
41   - /**
42   - * The button which update the query based on the table name textField and the service URL
43   - * textField.
44   - */
45   - private JButton serviceButton;
46   -
47 40 /** The text field to manually set the service URL. */
48 41 private JTextField serviceUrlTextField;
49 42  
... ... @@ -65,23 +58,47 @@ public class ServicesPanelView extends VOTableView {
65 58  
66 59 /** Build the service panel and add the graphical elements on it. */
67 60 private void buildServicesPanel() {
  61 + serviceUrlTextField = new JTextField(10);
  62 + addEventListener(serviceUrlTextField);
  63 + tableNameTextField = new JTextField(10);
  64 + addEventListener(tableNameTextField);
  65 +
68 66 JPanel addServicePanel = new JPanel();
69 67 addServicePanel.add(new JLabel("Service URL"));
70   - addServicePanel.add(getServiceUrlTextField());
  68 + addServicePanel.add(serviceUrlTextField);
71 69 addServicePanel.add(new JLabel("Table name"));
72   - addServicePanel.add(getTableNameTextField());
73   - addServicePanel.add(getServiceButton());
  70 + addServicePanel.add(tableNameTextField);
74 71  
75 72 add(addServicePanel, BorderLayout.SOUTH);
76 73 }
77 74  
  75 + public void addEventListener(JTextField textField) {
  76 + textField.getDocument().addDocumentListener(new DocumentListener() {
  77 +
  78 + @Override
  79 + public void changedUpdate(DocumentEvent e) {
  80 + listener.onCustomServiceUpdated();
  81 + }
  82 +
  83 + @Override
  84 + public void removeUpdate(DocumentEvent e) {
  85 + listener.onCustomServiceUpdated();
  86 + }
  87 +
  88 + @Override
  89 + public void insertUpdate(DocumentEvent e) {
  90 + listener.onCustomServiceUpdated();
  91 + }
  92 + });
  93 + }
  94 +
78 95 /**
79 96 * Returns the field to set a custom table name. Create it if doesn't exist.
80 97 *
81 98 * @return The table name JTextField.
82 99 */
83 100 public JTextField getTableNameTextField() {
84   - return tableNameTextField == null ? new JTextField(10) : tableNameTextField;
  101 + return tableNameTextField;
85 102 }
86 103  
87 104 /**
... ... @@ -90,28 +107,7 @@ public class ServicesPanelView extends VOTableView {
90 107 * @return The service URL JTextField.
91 108 */
92 109 public JTextField getServiceUrlTextField() {
93   - return serviceUrlTextField == null ? new JTextField(10) : serviceUrlTextField;
94   - }
95   -
96   - /**
97   - * Returns the button which update the query based on the table name textField and the service
98   - * URL textField. Create it if doesn't exist.
99   - *
100   - * @return The JButton to set the custom service, create it if doesn't exist.
101   - */
102   - private JButton getServiceButton() {
103   - if (serviceButton == null) {
104   - serviceButton = new JButton("Set service");
105   -
106   - serviceButton.addActionListener(new ActionListener() {
107   -
108   - @Override
109   - public void actionPerformed(ActionEvent e) {
110   - listener.onRowsSelected(null);
111   - }
112   - });
113   - }
114   - return serviceButton;
  110 + return serviceUrlTextField;
115 111 }
116 112  
117 113 }
... ...