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,6 +130,8 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
130 public void sendQuery() { 130 public void sendQuery() {
131 List<String> servicesUrls = servicesPanelCtrl.getSelectedServicesUrls(); 131 List<String> servicesUrls = servicesPanelCtrl.getSelectedServicesUrls();
132 List<String> tableNames = servicesPanelCtrl.getSelectedTablesNames(); 132 List<String> tableNames = servicesPanelCtrl.getSelectedTablesNames();
  133 + servicesUrls.addAll(servicesPanelCtrl.getCustomServicesUrls());
  134 + tableNames.addAll(servicesPanelCtrl.getCustomTablesNames());
133 try { 135 try {
134 for (int i = 0; i < servicesUrls.size(); i++) { 136 for (int i = 0; i < servicesUrls.size(); i++) {
135 String query = requestPanelCtrl.getQuery(tableNames.get(i)); 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,7 +102,8 @@ public abstract class ParamField extends JPanel {
102 * @param changeListener The listener of text fields. 102 * @param changeListener The listener of text fields.
103 * @param field The field to listen. 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 field.getDocument().addDocumentListener(new DocumentListener() { 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,7 +20,6 @@ import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.nio.file.Files; 21 import java.nio.file.Files;
22 import java.nio.file.Paths; 22 import java.nio.file.Paths;
23 -import java.util.List;  
24 import java.util.logging.Level; 23 import java.util.logging.Level;
25 import java.util.logging.Logger; 24 import java.util.logging.Logger;
26 25
@@ -66,8 +65,8 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis @@ -66,8 +65,8 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis
66 } 65 }
67 66
68 @Override 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 @Override 72 @Override
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel; 17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
18 18
19 import java.util.ArrayList; 19 import java.util.ArrayList;
  20 +import java.util.Arrays;
20 import java.util.List; 21 import java.util.List;
21 import java.util.logging.Logger; 22 import java.util.logging.Logger;
22 23
@@ -50,6 +51,12 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane @@ -50,6 +51,12 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
50 /** The list of services target Urls selected by the user on the service panel. */ 51 /** The list of services target Urls selected by the user on the service panel. */
51 private List<String> selectedServicesUrls; 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 /** The listener of the main panel. */ 60 /** The listener of the main panel. */
54 private MainPanelListener listener; 61 private MainPanelListener listener;
55 62
@@ -87,28 +94,58 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane @@ -87,28 +94,58 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane
87 return selectedServicesUrls; 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 @Override 111 @Override
91 - public void onRowsSelected(List<Integer> selectedRows) { 112 + public void onRowsSelected() {
92 List<String> servicesUrls = new ArrayList<>(); 113 List<String> servicesUrls = new ArrayList<>();
93 List<String> tableNames = new ArrayList<>(); 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 servicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row)); 117 servicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row));
99 tableNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row)); 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 selectedServicesUrls = servicesUrls; 121 selectedServicesUrls = servicesUrls;
107 selectedTablesNames = tableNames; 122 selectedTablesNames = tableNames;
108 - LOGGER.info("Selected services URLs: " + StringJoiner.join(selectedServicesUrls));  
109 - LOGGER.info("Selected tables names: " + StringJoiner.join(selectedTablesNames));  
110 123
111 listener.updateQuery(); 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,4 +23,5 @@ import eu.omp.irap.vespa.votable.view.VOTableViewListener;
23 */ 23 */
24 public interface ServicesPanelListener extends VOTableViewListener { 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,13 +17,12 @@
17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel; 17 package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
18 18
19 import java.awt.BorderLayout; 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 import javax.swing.JLabel; 21 import javax.swing.JLabel;
25 import javax.swing.JPanel; 22 import javax.swing.JPanel;
26 import javax.swing.JTextField; 23 import javax.swing.JTextField;
  24 +import javax.swing.event.DocumentEvent;
  25 +import javax.swing.event.DocumentListener;
27 26
28 import eu.omp.irap.vespa.votable.view.VOTableView; 27 import eu.omp.irap.vespa.votable.view.VOTableView;
29 28
@@ -38,12 +37,6 @@ public class ServicesPanelView extends VOTableView { @@ -38,12 +37,6 @@ public class ServicesPanelView extends VOTableView {
38 /** The listener of the services panel view. */ 37 /** The listener of the services panel view. */
39 ServicesPanelListener listener; 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 /** The text field to manually set the service URL. */ 40 /** The text field to manually set the service URL. */
48 private JTextField serviceUrlTextField; 41 private JTextField serviceUrlTextField;
49 42
@@ -65,23 +58,47 @@ public class ServicesPanelView extends VOTableView { @@ -65,23 +58,47 @@ public class ServicesPanelView extends VOTableView {
65 58
66 /** Build the service panel and add the graphical elements on it. */ 59 /** Build the service panel and add the graphical elements on it. */
67 private void buildServicesPanel() { 60 private void buildServicesPanel() {
  61 + serviceUrlTextField = new JTextField(10);
  62 + addEventListener(serviceUrlTextField);
  63 + tableNameTextField = new JTextField(10);
  64 + addEventListener(tableNameTextField);
  65 +
68 JPanel addServicePanel = new JPanel(); 66 JPanel addServicePanel = new JPanel();
69 addServicePanel.add(new JLabel("Service URL")); 67 addServicePanel.add(new JLabel("Service URL"));
70 - addServicePanel.add(getServiceUrlTextField()); 68 + addServicePanel.add(serviceUrlTextField);
71 addServicePanel.add(new JLabel("Table name")); 69 addServicePanel.add(new JLabel("Table name"));
72 - addServicePanel.add(getTableNameTextField());  
73 - addServicePanel.add(getServiceButton()); 70 + addServicePanel.add(tableNameTextField);
74 71
75 add(addServicePanel, BorderLayout.SOUTH); 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 * Returns the field to set a custom table name. Create it if doesn't exist. 96 * Returns the field to set a custom table name. Create it if doesn't exist.
80 * 97 *
81 * @return The table name JTextField. 98 * @return The table name JTextField.
82 */ 99 */
83 public JTextField getTableNameTextField() { 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,28 +107,7 @@ public class ServicesPanelView extends VOTableView {
90 * @return The service URL JTextField. 107 * @return The service URL JTextField.
91 */ 108 */
92 public JTextField getServiceUrlTextField() { 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 }