Commit 895647f32cb2a2f0eb6671d7fe1399b768898b96

Authored by Mickael Boiziot
1 parent 12f747f6
Exists in master

Allow to change between JSON and RegTAP registry

src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
... ... @@ -33,8 +33,9 @@ import eu.omp.irap.vespa.epntapclient.epntap.ServiceResultInterface;
33 33 import eu.omp.irap.vespa.epntapclient.epntap.service.ServicesList;
34 34 import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl;
35 35 import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultsPanelCtrl;
36   -import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl;
37   -import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelJsonCtrl;
  36 +//import eu.omp.irap.vespa.epntapclient.gui.servicespanel.json.ServicesPanelJsonCtrl;
  37 +//import eu.omp.irap.vespa.epntapclient.gui.servicespanel.registry.ServicesPanelRegistryCtrl;
  38 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicePanelCtrl;
38 39  
39 40 /**
40 41 * @author N. Jourdane
... ... @@ -64,11 +65,7 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener
64 65 * file to get the list of services.
65 66 */
66 67 public MainPanelCtrl(boolean fromRegistry) {
67   - if (fromRegistry) {
68   - servicesPanelCtrl = new ServicesPanelCtrl(this);
69   - } else {
70   - servicesPanelCtrl = new ServicesPanelJsonCtrl(this);
71   - }
  68 + servicesPanelCtrl = new ServicePanelCtrl(this, fromRegistry);
72 69 requestPanelCtrl = new RequestPanelCtrl(this);
73 70 resultsPanelCtrl = new ResultsPanelCtrl(this);
74 71 view = new MainPanelView(this);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicePanelCtrl.java 0 → 100644
... ... @@ -0,0 +1,151 @@
  1 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  2 +
  3 +import javax.swing.JPanel;
  4 +
  5 +import eu.omp.irap.vespa.epntapclient.epntap.ServiceResultInterface;
  6 +import eu.omp.irap.vespa.epntapclient.epntap.service.ServicesList;
  7 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.json.ServicesPanelJsonCtrl;
  8 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.registry.ServicesPanelRegistryCtrl;
  9 +import eu.omp.irap.vespa.votable.Consts;
  10 +
  11 +/**
  12 + * Service Panel controller.
  13 + */
  14 +public class ServicePanelCtrl implements ServiceResultInterface {
  15 +
  16 + private ServicesListener listener;
  17 + private ServicePanelView view;
  18 + private ServicesPanelJsonCtrl jsonCtrl;
  19 + private ServicesPanelRegistryCtrl registryCtrl;
  20 + private boolean fromRegistry;
  21 + private String urlRegistry;
  22 +
  23 +
  24 + /**
  25 + * Constructor.
  26 + *
  27 + * @param listener The listener of the main panel.
  28 + * @param fromRegistry True to use by default tap registry, false to use JSON.
  29 + */
  30 + public ServicePanelCtrl(ServicesListener listener, boolean fromRegistry) {
  31 + this.listener = listener;
  32 + this.fromRegistry = fromRegistry;
  33 + this.urlRegistry = Consts.DEFAULT_REGISTRY_URL;
  34 + }
  35 +
  36 + /**
  37 + * Return the current controller.
  38 + *
  39 + * @return the current controller.
  40 + */
  41 + private ServiceResultInterface getCurrentCtrl() {
  42 + if (fromRegistry) {
  43 + return getServicesPanelRegistryCtrl();
  44 + }
  45 + return getServicesPanelJsonCtrl();
  46 + }
  47 +
  48 + /**
  49 + * Create if needed then return the controller for JSON.
  50 + *
  51 + * @return the controller for JSON.
  52 + */
  53 + private ServicesPanelJsonCtrl getServicesPanelJsonCtrl() {
  54 + if (jsonCtrl == null) {
  55 + jsonCtrl = new ServicesPanelJsonCtrl(this.listener);
  56 + }
  57 + return jsonCtrl;
  58 + }
  59 +
  60 + /**
  61 + * Create if needed then return the controller for tap registry.
  62 + *
  63 + * @return the controller for tap registry.
  64 + */
  65 + private ServicesPanelRegistryCtrl getServicesPanelRegistryCtrl() {
  66 + if (registryCtrl == null) {
  67 + registryCtrl = new ServicesPanelRegistryCtrl(this.listener, this.urlRegistry);
  68 + }
  69 + return registryCtrl;
  70 + }
  71 +
  72 + @Override
  73 + public ServicesList getServices() {
  74 + return getCurrentCtrl().getServices();
  75 + }
  76 +
  77 + @Override
  78 + public JPanel getView() {
  79 + if (view == null) {
  80 + view = new ServicePanelView(this);
  81 + }
  82 + return view;
  83 + }
  84 +
  85 + /**
  86 + * Remove (set to null) current controller.
  87 + */
  88 + private void removeCurrent() {
  89 + if (fromRegistry) {
  90 + registryCtrl = null;
  91 + }
  92 + jsonCtrl = null;
  93 + }
  94 +
  95 + @Override
  96 + public void acquire() {
  97 + removeCurrent();
  98 + getCurrentCtrl().acquire();
  99 + view.refresh();
  100 + }
  101 +
  102 + @Override
  103 + public void acquireService(String defaultRegistryUrl, String query) {
  104 + getCurrentCtrl().acquireService(defaultRegistryUrl, query);
  105 + }
  106 +
  107 + /**
  108 + * Set to true to use RegTAP registry, false to use JSON.
  109 + *
  110 + * @param fromRegistry Set to true to use RegTAP registry, false to use JSON
  111 + */
  112 + public void setFromRegistry(boolean fromRegistry) {
  113 + this.fromRegistry = fromRegistry;
  114 + }
  115 +
  116 + /**
  117 + * Return true to use RegTAP registry, false to use JSON.
  118 + *
  119 + * @return true to use RegTAP registry, false to use JSON.
  120 + */
  121 + public boolean isFromRegistry() {
  122 + return fromRegistry;
  123 + }
  124 +
  125 + /**
  126 + * Return the URL of the RegTAP registry.
  127 + *
  128 + * @return the URL of the RegTAP registry.
  129 + */
  130 + public String getUrl() {
  131 + return urlRegistry;
  132 + }
  133 +
  134 + /**
  135 + * Change the URL of the RegTAP registry.
  136 + *
  137 + * @param newUrl the URL of the RegTAP registry.
  138 + */
  139 + public void setUrl(String newUrl) {
  140 + urlRegistry = newUrl;
  141 + }
  142 +
  143 + /**
  144 + * Return the table view.
  145 + *
  146 + * @return the table view.
  147 + */
  148 + public JPanel getSubView() {
  149 + return getCurrentCtrl().getView();
  150 + }
  151 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicePanelView.java 0 → 100644
... ... @@ -0,0 +1,125 @@
  1 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  2 +
  3 +import java.awt.BorderLayout;
  4 +import java.awt.event.ActionEvent;
  5 +import java.awt.event.ActionListener;
  6 +
  7 +import javax.swing.JButton;
  8 +import javax.swing.JComboBox;
  9 +import javax.swing.JPanel;
  10 +import javax.swing.JTextField;
  11 +
  12 +/**
  13 + * View class for service panel allowing to change between JSON and registry.
  14 + */
  15 +public class ServicePanelView extends JPanel {
  16 +
  17 + private static final long serialVersionUID = -7327954767825468491L;
  18 + private JPanel topPanel;
  19 + private JComboBox<String> registryTypeCombobox;
  20 + private JTextField registryUrlTextField;
  21 + private JButton queryButton;
  22 + private ServicePanelCtrl control;
  23 +
  24 +
  25 + /**
  26 + * Constructor.
  27 + *
  28 + * @param control The controller.
  29 + */
  30 + public ServicePanelView(ServicePanelCtrl control) {
  31 + this.control = control;
  32 + this.refresh();
  33 + }
  34 +
  35 + /**
  36 + * Create if needed then return the registry type combobox.
  37 + *
  38 + * @return the registry type combobox.
  39 + */
  40 + public JComboBox<String> getRegistryTypeCombobox() {
  41 + if (registryTypeCombobox == null) {
  42 + registryTypeCombobox = new JComboBox<String>(new String[] { "REGTAP", "JSON" });
  43 + int index = control.isFromRegistry() ? 0 : 1;
  44 + registryTypeCombobox.setSelectedIndex(index);
  45 + registryTypeCombobox.setEditable(false);
  46 + registryTypeCombobox.addActionListener(new ActionListener() {
  47 +
  48 + @Override
  49 + public void actionPerformed(ActionEvent e) {
  50 + String selected = (String) registryTypeCombobox.getSelectedItem();
  51 + boolean isRegistry = "REGTAP".equals(selected);
  52 + control.setFromRegistry(isRegistry);
  53 + getRegistryUrlTextField().setEnabled(isRegistry);
  54 + }
  55 + });
  56 + }
  57 + return registryTypeCombobox;
  58 + }
  59 +
  60 + /**
  61 + * Create if needed then return the registry URL text field.
  62 + *
  63 + * @return the registry URL text field.
  64 + */
  65 + public JTextField getRegistryUrlTextField() {
  66 + if (registryUrlTextField == null) {
  67 + registryUrlTextField = new JTextField(30);
  68 + registryUrlTextField.setText(control.getUrl());
  69 + registryUrlTextField.setEnabled(control.isFromRegistry());
  70 + }
  71 + return registryUrlTextField;
  72 + }
  73 +
  74 + /**
  75 + * Create if needed then return the query button.
  76 + *
  77 + * @return the query button.
  78 + */
  79 + public JButton getQueryButton() {
  80 + if (queryButton == null) {
  81 + queryButton = new JButton("Query");
  82 + queryButton.addActionListener(new ActionListener() {
  83 +
  84 + @Override
  85 + public void actionPerformed(ActionEvent e) {
  86 + if (control.isFromRegistry()) {
  87 + String url = getRegistryUrlTextField().getText();
  88 + control.setUrl(url);
  89 + }
  90 + control.acquire();
  91 + }
  92 + });
  93 + }
  94 + return queryButton;
  95 + }
  96 +
  97 + /**
  98 + * Create if needed then return the top panel (registry type selection,
  99 + * URL text field, query button).
  100 + *
  101 + * @return the top panel.
  102 + */
  103 + public JPanel getTopPanel() {
  104 + if (topPanel == null) {
  105 + topPanel = new JPanel(new BorderLayout());
  106 + topPanel.add(getRegistryTypeCombobox(), BorderLayout.WEST);
  107 + topPanel.add(getRegistryUrlTextField(), BorderLayout.CENTER);
  108 + topPanel.add(getQueryButton(), BorderLayout.EAST);
  109 + }
  110 + return topPanel;
  111 + }
  112 +
  113 + /**
  114 + * Remove then recreate the UI.
  115 + */
  116 + public void refresh() {
  117 + this.removeAll();
  118 + this.setLayout(new BorderLayout());
  119 + this.add(getTopPanel(), BorderLayout.NORTH);
  120 + this.add(control.getSubView(), BorderLayout.CENTER);
  121 + this.revalidate();
  122 + this.repaint();
  123 + }
  124 +
  125 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelViewInterface.java deleted
... ... @@ -1,5 +0,0 @@
1   -package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
2   -
3   -public interface ServicesPanelViewInterface {
4   -
5   -}
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelJsonCtrl.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/json/ServicesPanelJsonCtrl.java
1   -package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  1 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel.json;
2 2  
3 3 import java.util.ArrayList;
4 4 import java.util.Arrays;
... ... @@ -8,10 +8,12 @@ import org.json.JSONObject;
8 8  
9 9 import eu.omp.irap.vespa.epntapclient.epntap.ServiceResultInterface;
10 10 import eu.omp.irap.vespa.epntapclient.epntap.service.ServicesList;
  11 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesListener;
  12 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelListener;
11 13 import eu.omp.irap.vespa.epntapclient.utils.JsonUtils;
12 14 import eu.omp.irap.vespa.votable.utils.CantSendQueryException;
13 15  
14   -public class ServicesPanelJsonCtrl implements ServicesPanelListener, ServiceResultInterface{
  16 +public class ServicesPanelJsonCtrl implements ServicesPanelListener, ServiceResultInterface {
15 17  
16 18 /** The separator used between each services in the custom service text fields. */
17 19 private static final String CUSTOM_SERVICES_SEPARATOR = ";";
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelJsonView.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/json/ServicesPanelJsonView.java
... ... @@ -14,7 +14,7 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  17 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel.json;
18 18  
19 19 import java.awt.BorderLayout;
20 20 import java.awt.Component;
... ... @@ -45,6 +45,9 @@ import javax.swing.table.TableRowSorter;
45 45 import org.json.JSONArray;
46 46 import org.json.JSONObject;
47 47  
  48 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesListener;
  49 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelListener;
  50 +
48 51  
49 52 /**
50 53 * @author N. Jourdane
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/registry/ServicesPanelRegistryCtrl.java
... ... @@ -14,7 +14,7 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  17 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel.registry;
18 18  
19 19 import java.util.ArrayList;
20 20 import java.util.Arrays;
... ... @@ -24,14 +24,15 @@ import eu.omp.irap.vespa.epntapclient.epntap.ServiceResultInterface;
24 24 import eu.omp.irap.vespa.epntapclient.epntap.service.Queries;
25 25 import eu.omp.irap.vespa.epntapclient.epntap.service.ServiceCore;
26 26 import eu.omp.irap.vespa.epntapclient.epntap.service.ServicesList;
27   -import eu.omp.irap.vespa.votable.Consts;
  27 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesListener;
  28 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelListener;
28 29 import eu.omp.irap.vespa.votable.gui.VOTablePanelListener;
29 30 import eu.omp.irap.vespa.votable.votable.VOTableCtrl;
30 31  
31 32 /**
32 33 * @author N. Jourdane
33 34 */
34   -public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListener, VOTablePanelListener , ServiceResultInterface {
  35 +public class ServicesPanelRegistryCtrl extends VOTableCtrl implements ServicesPanelListener, VOTablePanelListener , ServiceResultInterface {
35 36  
36 37 /** The separator used between each services in the custom service text fields. */
37 38 private static final String CUSTOM_SERVICES_SEPARATOR = ";";
... ... @@ -43,25 +44,30 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe
43 44 private ServicesList services;
44 45  
45 46 /** The view of the services panel. */
46   - private ServicesPanelView view;
  47 + private ServicesPanelRegistryView view;
  48 +
  49 + /** URL of the registry to query. */
  50 + private String url;
47 51  
48 52  
49 53 /**
50   - * Constructor of ServicesPanelCtrl
  54 + * Constructor of ServicesPanelRegistryCtrl
51 55 *
52 56 * @param listener The listener of the main panel.
53 57 */
54   - public ServicesPanelCtrl(ServicesListener listener) {
  58 + public ServicesPanelRegistryCtrl(ServicesListener listener, String url) {
55 59 this.listener = listener;
  60 + this.url = url;
56 61 services = new ServicesList();
57   - view = new ServicesPanelView(this);
  62 + view = new ServicesPanelRegistryView(this);
58 63 }
59 64  
60 65 /** Download and parse the list of services. */
  66 + @Override
61 67 public void acquire() {
62 68 String getServicesQuery = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
63 69 ServiceCore.EPNCORE);
64   - acquireService(Consts.DEFAULT_REGISTRY_URL, getServicesQuery);
  70 + acquireService(this.url, getServicesQuery);
65 71 }
66 72  
67 73 @Override
... ... @@ -90,7 +96,7 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe
90 96 * @return The view of the services panel. Used in MainPanelCtrl to add panels in the main
91 97 * window.
92 98 */
93   - public ServicesPanelView getView() {
  99 + public ServicesPanelRegistryView getView() {
94 100 return view;
95 101 }
96 102  
... ... @@ -135,4 +141,12 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe
135 141 public void acquireService(String defaultRegistryUrl, String query) {
136 142 acquireVOTable(defaultRegistryUrl, query);
137 143 }
  144 +
  145 +// public String getUrl() {
  146 +// return url;
  147 +// }
  148 +//
  149 +// public void setUrl(String url) {
  150 +// this.url = url;
  151 +// }
138 152 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelView.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/registry/ServicesPanelRegistryView.java
... ... @@ -14,7 +14,7 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.gui.servicespanel;
  17 +package eu.omp.irap.vespa.epntapclient.gui.servicespanel.registry;
18 18  
19 19 import java.awt.BorderLayout;
20 20 import java.io.File;
... ... @@ -27,12 +27,14 @@ import javax.swing.event.DocumentEvent;
27 27 import javax.swing.event.DocumentListener;
28 28  
29 29 import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener;
  30 +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelListener;
  31 +import eu.omp.irap.vespa.votable.Consts;
30 32 import eu.omp.irap.vespa.votable.gui.VOTablePanelView;
31 33  
32 34 /**
33 35 * @author N. Jourdane
34 36 */
35   -public class ServicesPanelView extends VOTablePanelView {
  37 +public class ServicesPanelRegistryView extends VOTablePanelView {
36 38  
37 39 /** The serial version UID. */
38 40 private static final long serialVersionUID = 1L;
... ... @@ -53,7 +55,7 @@ public class ServicesPanelView extends VOTablePanelView {
53 55 *
54 56 * @param listener The listener of the services panel.
55 57 */
56   - public ServicesPanelView(final ServicesPanelCtrl listener) {
  58 + public ServicesPanelRegistryView(final ServicesPanelRegistryCtrl listener) {
57 59 super(listener);
58 60 this.listener = listener;
59 61 buildServicesPanel();
... ... @@ -120,7 +122,7 @@ public class ServicesPanelView extends VOTablePanelView {
120 122  
121 123 public static void main(String[] args) {
122 124 JFrame frame = new JFrame();
123   - ServicesPanelCtrl servicesPanelCtrl = new ServicesPanelCtrl(new MainPanelListener() {
  125 + ServicesPanelRegistryCtrl servicesPanelCtrl = new ServicesPanelRegistryCtrl(new MainPanelListener() {
124 126  
125 127 @Override
126 128 public void updateQuery() {
... ... @@ -151,7 +153,7 @@ public class ServicesPanelView extends VOTablePanelView {
151 153 public void displayError(String message, Exception error) {
152 154 // TODO Auto-generated method stub
153 155 }
154   - });
  156 + }, Consts.DEFAULT_REGISTRY_URL);
155 157 servicesPanelCtrl.acquire();
156 158 frame.getContentPane().add(servicesPanelCtrl.getView());
157 159 frame.pack();
... ...