Commit 5af53be70ea4e57d24f2f054740499e3ce2f69f8

Authored by Nathanael Jourdane
1 parent c57c07b1
Exists in master

Make the application more MVC.

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java
... ... @@ -45,8 +45,8 @@ public class EpnTapMainApp {
45 45 SwingUtilities.invokeLater(new Runnable() {
46 46 @Override
47 47 public void run() {
48   - EpnTapController epnTapControl = new EpnTapController();
49 48 logger.info("Lauching EPN-TAP application...");
  49 + EpnTapController epnTapControl = new EpnTapController();
50 50 if (args.length != 0) {
51 51 System.console().writer().println("Usage: EpnTapMainApp");
52 52 return;
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
... ... @@ -16,24 +16,28 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.controller;
18 18  
  19 +import java.util.HashMap;
  20 +import java.util.Map;
  21 +import java.util.logging.Level;
19 22 import java.util.logging.Logger;
20 23  
21 24 import eu.omp.irap.vespa.epntapclient.utils.Const;
22 25 import eu.omp.irap.vespa.epntapclient.utils.Queries;
23 26 import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
  27 +import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView.MainViewListener;
  28 +import eu.omp.irap.vespa.epntapclient.view.Event;
24 29 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
25 30 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException;
26   -import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
27 31  
28 32 /**
29 33 * @author N. Jourdane
30 34 */
31   -public class EpnTapController {
  35 +public class EpnTapController implements MainViewListener {
32 36 /** The logger for the class EpnTapController. */
33 37 Logger logger = Logger.getLogger(EpnTapController.class.getName());
34 38  
35 39 /** The view of EPN-TAP application. */
36   - EpnTapMainView view;
  40 + EpnTapMainView mainView;
37 41  
38 42 /** The controller of the VOTable displaying the list of services. */
39 43 VOTableController servicesController;
... ... @@ -48,17 +52,21 @@ public class EpnTapController {
48 52 String selectedTableServiceURL;
49 53  
50 54 /**
  55 + * The parameters fields for the request.
  56 + */
  57 + private Map<String, Object> paramValues = new HashMap<>();
  58 +
  59 + /**
51 60 * Method constructor
52 61 */
53 62 public EpnTapController() {
54 63 servicesController = new VOTableController(Const.DEFAULT_REGISTRY_URL, "ADQL",
55 64 Queries.GET_EPN_TAP_SERVICES);
56   -
57 65 resultsController = new VOTableController();
58 66  
59   - VOTableView serviceView = servicesController.getView();
60   - VOTableView resultsView = resultsController.getView();
61   - view = new EpnTapMainView(this, serviceView, resultsView);
  67 + mainView = new EpnTapMainView(this, servicesController.getView(),
  68 + resultsController.getView());
  69 + mainView.addMainViewListener(this);
62 70 updateSelected(0);
63 71 }
64 72  
... ... @@ -66,7 +74,7 @@ public class EpnTapController {
66 74 * @return the EPN-TAP view.
67 75 */
68 76 public EpnTapMainView getView() {
69   - return view;
  77 + return mainView;
70 78 }
71 79  
72 80 /**
... ... @@ -87,19 +95,32 @@ public class EpnTapController {
87 95 * @param row The row selected by the user on the Jtable.
88 96 */
89 97 public void updateSelected(int row) {
90   - String serviceURL = (String) view.getServicesView().getValueAt(5, row);
91   - String tableName = (String) view.getServicesView().getValueAt(2, row);
  98 + String serviceURL = mainView.getServicesPanel().getServiceURL(row);
  99 + String tableName = mainView.getServicesPanel().getTableName(row);
92 100 if (!tableName.equals(selectedTableName)) {
93 101 selectedTableServiceURL = serviceURL;
94 102 selectedTableName = tableName;
95   - view.getRequestView().updateQueryArea();
  103 + updateQueryArea();
96 104 logger.info("Selected table: " + selectedTableName + " - service: "
97 105 + selectedTableServiceURL);
98 106 }
99 107 }
100 108  
101   - public String getSelectedTable() {
102   - return selectedTableName;
  109 + public void removeParameter(String paramName) {
  110 + paramValues.remove(paramName);
  111 + updateQueryArea();
  112 + logger.info("removed " + paramName);
  113 + }
  114 +
  115 + public void updateParameter(String paramName, Object value) {
  116 + paramValues.put(paramName, value);
  117 + updateQueryArea();
  118 + logger.info("uploaded " + paramName + ": " + value);
  119 + }
  120 +
  121 + private void updateQueryArea() {
  122 + String query = Queries.getQuery(selectedTableName, paramValues, 10);
  123 + mainView.getRequestPanel().updateQueryArea(query);
103 124 }
104 125  
105 126 /**
... ... @@ -110,4 +131,35 @@ public class EpnTapController {
110 131 logger.info("Sending query: " + query + " on " + selectedTableServiceURL);
111 132 resultsController.fillTable(selectedTableServiceURL, "ADQL", query);
112 133 }
  134 +
  135 + /**
  136 + * @param event
  137 + * @param args
  138 + */
  139 + public void event(Event event, Object[] args) {
  140 + logger.info("new event: " + event.toString());
  141 +
  142 + try {
  143 + switch (event) {
  144 + case serviceSelected:
  145 + updateSelected((int) args[0]);
  146 + break;
  147 + case btnSearchClicked:
  148 + sendQuery((String) args[0]);
  149 + break;
  150 + case paramChanged:
  151 + updateParameter((String) args[0], args[1]);
  152 + break;
  153 + case paramRemoved:
  154 + removeParameter((String) args[0]);
  155 + break;
  156 + default:
  157 + logger.warning("Event " + event.toString() + " detected but is not implemented.");
  158 + }
  159 + } catch (Exception e) {
  160 + mainView.displayError("Error", "An unexpected error occured: " + e.getMessage()
  161 + + ".\nPlease report it to the developper team.");
  162 + logger.log(Level.SEVERE, "Error occured when " + event.toString(), e);
  163 + }
  164 + }
113 165 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/Dim.java 0 โ†’ 100644
... ... @@ -0,0 +1,42 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.view;
  18 +
  19 +/**
  20 + * A simple class containing GUI panel and elements dimensions.
  21 + *
  22 + * @author N. Jourdane
  23 + */
  24 +public class Dim {
  25 + /** The width of the left panel (services view). */
  26 + public static final int LEFT_PANEL_WIDTH = 400;
  27 + /** The minimum width of the left panel (services view). */
  28 + public static final int LEFT_PANEL_MIN_WIDTH = 150;
  29 + /** The width of the right panel (request view). */
  30 + public static final int RIGHT_PANEL_WIDTH = 400;
  31 + /** The minimum width of the right panel (request view). */
  32 + public static final int RIGHT_PANEL_MIN_WIDTH = 220;
  33 +
  34 + /** The height of the top panel (request view and services view). */
  35 + public static final int TOP_PANEL_HEIGHT = 250;
  36 + /** The minimum height of the top panel (request view and services view). */
  37 + public static final int TOP_PANEL_MIN_HEIGHT = 190;
  38 + /** The height of the bottom panel (result view). */
  39 + public static final int BOTTOM_PANEL_HEIGHT = 150;
  40 + /** The minimum height of the bottom panel (result view). */
  41 + public static final int BOTTOM_PANEL_MIN_HEIGHT = 100;
  42 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java
... ... @@ -17,16 +17,17 @@
17 17 package eu.omp.irap.vespa.epntapclient.view;
18 18  
19 19 import java.awt.BorderLayout;
20   -import java.awt.Dimension;
21 20 import java.util.logging.Logger;
22 21  
23 22 import javax.swing.JOptionPane;
24 23 import javax.swing.JPanel;
25 24 import javax.swing.JSplitPane;
26   -import javax.swing.event.ListSelectionEvent;
27   -import javax.swing.event.ListSelectionListener;
28 25  
29 26 import eu.omp.irap.vespa.epntapclient.controller.EpnTapController;
  27 +import eu.omp.irap.vespa.epntapclient.view.panels.BottomBarPanel;
  28 +import eu.omp.irap.vespa.epntapclient.view.panels.RequestPanel;
  29 +import eu.omp.irap.vespa.epntapclient.view.panels.ResultsPanel;
  30 +import eu.omp.irap.vespa.epntapclient.view.panels.ServicesPanel;
30 31 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
31 32  
32 33 /**
... ... @@ -39,124 +40,89 @@ public class EpnTapMainView extends JPanel {
39 40 /** The serial version UID (affected with a random number). */
40 41 private static final long serialVersionUID = -1233290271099283814L;
41 42  
  43 + /** The main EPN-TAP main controller */
  44 + private EpnTapController controller;
  45 +
42 46 /** The JPanel where the VOTable results is displayed. */
43   - private VOTableView resultsView;
  47 + private ResultsPanel resultsPanel;
44 48  
45 49 /** The JPanel where the list of services is displayed. */
46   - private VOTableView servicesView;
  50 + private ServicesPanel servicesPanel;
47 51  
48 52 /** The JPanel where the user put requests. */
49   - private RequestView requestView;
  53 + private RequestPanel requestPanel;
50 54  
51 55 /** The JPanel where the user put requests. */
52   - private BottomBar bottomBar;
  56 + private BottomBarPanel bottomBarPanel;
53 57  
54   - /** The main EPN-TAP main controller */
55   - private EpnTapController controller;
  58 + private MainViewListener mainViewListener;
56 59  
57   - /** The width of the left panel (services view). */
58   - static final int LEFT_PANEL_WIDTH = 400;
59   - /** The minimum width of the left panel (services view). */
60   - static final int LEFT_PANEL_MIN_WIDTH = 150;
61   - /** The width of the right panel (request view). */
62   - static final int RIGHT_PANEL_WIDTH = 400;
63   - /** The minimum width of the right panel (request view). */
64   - static final int RIGHT_PANEL_MIN_WIDTH = 220;
65   -
66   - /** The height of the top panel (request view and services view). */
67   - static final int TOP_PANEL_HEIGHT = 250;
68   - /** The minimum height of the top panel (request view and services view). */
69   - static final int TOP_PANEL_MIN_HEIGHT = 190;
70   - /** The height of the bottom panel (result view). */
71   - static final int BOTTOM_PANEL_HEIGHT = 150;
72   - /** The minimum height of the bottom panel (result view). */
73   - static final int BOTTOM_PANEL_MIN_HEIGHT = 100;
  60 + public interface MainViewListener {
  61 + void event(Event event, Object... args);
  62 + }
74 63  
75 64 /**
76   - * The constructor of the view.
  65 + * The constructor of the view. TODO: controlleur = รฉcouteur de la vue
77 66 *
78 67 * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events.
79   - * @param servicesView The JPanel representing the table of services.
80   - * @param resultsView The JPanel representing the table of results.
81 68 */
82   - public EpnTapMainView(final EpnTapController controller, final VOTableView servicesView,
83   - VOTableView resultsView) {
  69 +
  70 + public EpnTapMainView(final EpnTapController controller, VOTableView voTableServicesView,
  71 + VOTableView voTableResultsView) {
84 72 this.controller = controller;
85   - this.servicesView = servicesView;
86   - this.resultsView = resultsView;
87   - this.requestView = new RequestView(this);
88   - this.bottomBar = new BottomBar(this);
89 73  
  74 + this.servicesPanel = new ServicesPanel(this, voTableServicesView);
  75 + this.resultsPanel = new ResultsPanel(this, voTableResultsView);
  76 + this.requestPanel = new RequestPanel(this);
  77 + this.bottomBarPanel = new BottomBarPanel(this);
90 78 setLayout(new BorderLayout());
91 79 buildWindow();
92   -
93   - // TODO: Support multi-selection
94   - servicesView.getTable().getSelectionModel()
95   - .addListSelectionListener(new ListSelectionListener() {
96   - public void valueChanged(ListSelectionEvent evt) {
97   - controller.updateSelected(servicesView.getTable().getSelectedRow());
98   - }
99   - });
100 80 }
101 81  
102   - /**
103   - * @return The main EPNT-TAP controller.
104   - */
105   - public EpnTapController getController() {
106   - return controller;
  82 + public void addMainViewListener(MainViewListener listener) {
  83 + mainViewListener = listener;
107 84 }
108 85  
109 86 /**
110 87 * @return The JPanel where the VOTable results is displayed.
111 88 */
112   - public VOTableView getResultsView() {
113   - return resultsView;
  89 + public ResultsPanel getResultsPanel() {
  90 + return resultsPanel;
114 91 }
115 92  
116 93 /**
117 94 * @return The JPanel where the GUI elements to make the request are displayed.
118 95 */
119   - public RequestView getRequestView() {
120   - return requestView;
  96 + public RequestPanel getRequestPanel() {
  97 + return requestPanel;
121 98 }
122 99  
123 100 /**
124 101 * @return The JPanel where the list of services is displayed.
125 102 */
126   - public VOTableView getServicesView() {
127   - return servicesView;
  103 + public ServicesPanel getServicesPanel() {
  104 + return servicesPanel;
128 105 }
129 106  
130 107 /**
131 108 * @return The JPanel where the list of services is displayed.
132 109 */
133   - public BottomBar getBottomBar() {
134   - return bottomBar;
  110 + public BottomBarPanel getBottomBarPanel() {
  111 + return bottomBarPanel;
135 112 }
136 113  
137 114 /**
138 115 * Build and fill the GUI.
139 116 */
140 117 public void buildWindow() {
141   - JSplitPane northPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, servicesView,
142   - requestView);
143   -
144   - servicesView.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, TOP_PANEL_HEIGHT));
145   - servicesView.setMinimumSize(new Dimension(LEFT_PANEL_MIN_WIDTH, TOP_PANEL_MIN_HEIGHT));
  118 + JSplitPane northPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, servicesPanel,
  119 + requestPanel);
146 120  
147 121 // TODO: put requestView inside a JScrollPane.
148   - requestView.setPreferredSize(new Dimension(RIGHT_PANEL_WIDTH, TOP_PANEL_HEIGHT));
149   - requestView.setMinimumSize(new Dimension(RIGHT_PANEL_MIN_WIDTH, TOP_PANEL_MIN_HEIGHT));
150 122  
151   - resultsView.setPreferredSize(
152   - new Dimension(LEFT_PANEL_WIDTH + RIGHT_PANEL_WIDTH, BOTTOM_PANEL_HEIGHT));
153   - resultsView.setMinimumSize(
154   - new Dimension(LEFT_PANEL_MIN_WIDTH + RIGHT_PANEL_MIN_WIDTH,
155   - BOTTOM_PANEL_MIN_HEIGHT));
156   -
157   - JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, northPanel, resultsView);
  123 + JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, northPanel, resultsPanel);
158 124 add(mainPanel, BorderLayout.CENTER);
159   - add(bottomBar, BorderLayout.SOUTH);
  125 + add(bottomBarPanel, BorderLayout.SOUTH);
160 126 }
161 127  
162 128 /**
... ... @@ -170,4 +136,8 @@ public class EpnTapMainView extends JPanel {
170 136 JOptionPane.ERROR_MESSAGE);
171 137 }
172 138  
  139 + public void event(Event event, Object... args) {
  140 + mainViewListener.event(event, args);
  141 + }
  142 +
173 143 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java 0 โ†’ 100644
... ... @@ -0,0 +1,24 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.view;
  18 +
  19 +/**
  20 + * @author N. Jourdane
  21 + */
  22 +public enum Event {
  23 + serviceSelected, btnSearchClicked, paramRemoved, paramChanged;
  24 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/ParamField.java
... ... @@ -61,11 +61,15 @@ public abstract class ParamField extends JPanel {
61 61 private static final String MIN_SUFFIX = "min";
62 62 private static final String MAX_SUFFIX = "max";
63 63  
64   - protected static RequestView requestView;
  64 + protected static EpnTapMainView mainView;
65 65 protected String paramName;
66 66  
67   - public ParamField(RequestView requestView, String paramName) {
  67 + public ParamField(EpnTapMainView mainView, String paramName) {
68 68 super();
  69 +
  70 + this.mainView = mainView;
  71 + this.paramName = paramName;
  72 +
69 73 this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
70 74 this.setMaximumSize(new Dimension(MAX_FIELD_WIDTH, FIELD_HEIGHT));
71 75 String strLabel = paramName.replaceAll("_", " ").trim();
... ... @@ -73,15 +77,13 @@ public abstract class ParamField extends JPanel {
73 77 label.setPreferredSize(new Dimension(LABEL_WIDTH, FIELD_HEIGHT));
74 78 this.add(label);
75 79 // TODO: Add tooltip text based on rr.table_column.column_description
76   - this.requestView = requestView;
77   - this.paramName = paramName;
78 80 }
79 81  
80 82 public static class StringField extends ParamField implements TextFieldListener {
81 83 JTextField field;
82 84  
83   - StringField(RequestView requestView, String paramName) {
84   - super(requestView, paramName);
  85 + public StringField(EpnTapMainView mainView, String paramName) {
  86 + super(mainView, paramName);
85 87 field = new JTextField();
86 88 addChangeListener(this, field);
87 89 this.add(field);
... ... @@ -89,9 +91,9 @@ public abstract class ParamField extends JPanel {
89 91  
90 92 public void update(JTextField field) {
91 93 if ("".equals(field.getText())) {
92   - requestView.updateParam(paramName, null);
  94 + mainView.event(Event.paramChanged, paramName, null);
93 95 } else {
94   - requestView.updateParam(paramName, field.getText());
  96 + mainView.event(Event.paramChanged, paramName, field.getText());
95 97 }
96 98 }
97 99 }
... ... @@ -99,8 +101,8 @@ public abstract class ParamField extends JPanel {
99 101 public static class FloatField extends ParamField implements TextFieldListener {
100 102 JTextField field;
101 103  
102   - FloatField(RequestView requestView, String paramName) {
103   - super(requestView, paramName);
  104 + public FloatField(EpnTapMainView mainView, String paramName) {
  105 + super(mainView, paramName);
104 106 field = new JTextField();
105 107 addChangeListener(this, field);
106 108 this.add(field);
... ... @@ -109,10 +111,11 @@ public abstract class ParamField extends JPanel {
109 111 public void update(JTextField field) {
110 112 if ("".equals(field.getText())) {
111 113 field.setBackground(Color.WHITE);
112   - requestView.updateParam(paramName, null);
  114 + mainView.event(Event.paramRemoved, paramName);
113 115 } else {
114 116 try {
115   - requestView.updateParam(paramName, Float.parseFloat(field.getText()));
  117 + mainView.event(Event.paramChanged, paramName,
  118 + Float.parseFloat(field.getText()));
116 119 field.setBackground(Color.WHITE);
117 120 } catch (NumberFormatException e) {
118 121 field.setBackground(Color.PINK);
... ... @@ -125,8 +128,8 @@ public abstract class ParamField extends JPanel {
125 128 JTextField fieldMin;
126 129 JTextField fieldMax;
127 130  
128   - DateRangeField(RequestView requestView, String paramName) {
129   - super(requestView, paramName);
  131 + public DateRangeField(EpnTapMainView mainView, String paramName) {
  132 + super(mainView, paramName);
130 133 this.add(new JLabel("min "));
131 134 fieldMin = new JTextField();
132 135 fieldMin.setName(MIN_SUFFIX);
... ... @@ -146,12 +149,12 @@ public abstract class ParamField extends JPanel {
146 149 DateFormat df = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
147 150 if ("".equals(field.getText())) {
148 151 field.setBackground(Color.WHITE);
149   - requestView.updateParam(paramName + field.getName(), null);
  152 + mainView.event(Event.paramRemoved, paramName + field.getName());
150 153 } else if (field.getText().matches(DATE_REGEX)) {
151 154 try {
152 155 long date = df.parse(field.getText()).getTime();
153   - date = (Math.round((date / 86400000.0) + 2440587.5)); // to JD
154   - requestView.updateParam(paramName + field.getName(), date);
  156 + date = Math.round((date / 86400000.0) + 2440587.5); // to JD
  157 + mainView.event(Event.paramChanged, paramName + field.getName(), date);
155 158 field.setBackground(Color.WHITE);
156 159 } catch (ParseException e) {
157 160 field.setBackground(Color.PINK);
... ... @@ -167,8 +170,8 @@ public abstract class ParamField extends JPanel {
167 170 JTextField fieldMin;
168 171 JTextField fieldMax;
169 172  
170   - FloatRangeField(RequestView requestView, String paramName) {
171   - super(requestView, paramName);
  173 + public FloatRangeField(EpnTapMainView mainView, String paramName) {
  174 + super(mainView, paramName);
172 175 fieldMin = new JTextField();
173 176 fieldMin.setName(MIN_SUFFIX);
174 177 addChangeListener(this, fieldMin);
... ... @@ -183,10 +186,10 @@ public abstract class ParamField extends JPanel {
183 186 public void update(JTextField field) {
184 187 if ("".equals(field.getText())) {
185 188 field.setBackground(Color.WHITE);
186   - requestView.updateParam(paramName + field.getName(), null);
  189 + mainView.event(Event.paramRemoved, paramName + field.getName());
187 190 } else {
188 191 try {
189   - requestView.updateParam(paramName + field.getName(),
  192 + mainView.event(Event.paramChanged, paramName + field.getName(),
190 193 Float.parseFloat(field.getText()));
191 194 field.setBackground(Color.WHITE);
192 195 } catch (NumberFormatException e) {
... ... @@ -201,8 +204,8 @@ public abstract class ParamField extends JPanel {
201 204 JTextField field;
202 205 String lastContent;
203 206  
204   - TargetNameField(RequestView requestView, String paramName) {
205   - super(requestView, paramName);
  207 + public TargetNameField(EpnTapMainView mainView, String paramName) {
  208 + super(mainView, paramName);
206 209 comboBox = new JComboBox();
207 210 comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
208 211  
... ... @@ -234,16 +237,21 @@ public abstract class ParamField extends JPanel {
234 237 Runnable updateComboBox = new Runnable() {
235 238 @Override
236 239 public void run() {
237   - System.out.println("run updateComboBox");
238 240 String content = field.getText();
239   - if (content.length() >= 2 && !content.equals(lastContent)) {
240   - lastContent = content;
241   - comboBox.removeAllItems();
242   - for (String s : getItems(content)) {
243   - comboBox.addItem(s);
  241 + if (!content.equals(lastContent)) {
  242 + if (content.length() >= 2) {
  243 + lastContent = content;
  244 + comboBox.removeAllItems();
  245 + for (String s : getItems(content)) {
  246 + comboBox.addItem(s);
  247 + }
  248 + comboBox.getEditor().setItem(content);
  249 + }
  250 + if ("".equals(content)) {
  251 + mainView.event(Event.paramRemoved, paramName);
  252 + } else {
  253 + mainView.event(Event.paramChanged, paramName, content);
244 254 }
245   - comboBox.getEditor().setItem(content);
246   - requestView.updateParam(paramName, content);
247 255 }
248 256 }
249 257 };
... ... @@ -256,8 +264,8 @@ public abstract class ParamField extends JPanel {
256 264 public static class DataProductTypeField extends ParamField {
257 265 JComboBox<String> comboBox;
258 266  
259   - DataProductTypeField(RequestView requestView, String paramName) {
260   - super(requestView, paramName);
  267 + public DataProductTypeField(EpnTapMainView mainView, String paramName) {
  268 + super(mainView, paramName);
261 269 comboBox = new JComboBox(getItems().keySet().toArray());
262 270 comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
263 271 comboBox.addActionListener(new ActionListener() {
... ... @@ -291,15 +299,19 @@ public abstract class ParamField extends JPanel {
291 299 List<String> item = new ArrayList();
292 300 item.add(key.replace(" ", "-").toLowerCase());
293 301 item.add(getItems().get(key));
294   - requestView.updateParam(paramName, "All".equals(key) ? null : item);
  302 + if ("All".equals(key)) {
  303 + mainView.event(Event.paramRemoved, paramName);
  304 + } else {
  305 + mainView.event(Event.paramChanged, paramName, item);
  306 + }
295 307 }
296 308 }
297 309  
298 310 public static class TargetClassField extends ParamField {
299 311 JComboBox<String> comboBox;
300 312  
301   - TargetClassField(RequestView requestView, String paramName) {
302   - super(requestView, paramName);
  313 + public TargetClassField(EpnTapMainView mainView, String paramName) {
  314 + super(mainView, paramName);
303 315 comboBox = new JComboBox(getItems());
304 316 comboBox.setPreferredSize(new Dimension(MIN_FIELD_WIDTH, FIELD_HEIGHT));
305 317 comboBox.addActionListener(new ActionListener() {
... ... @@ -318,7 +330,11 @@ public abstract class ParamField extends JPanel {
318 330  
319 331 private void onUpdate() {
320 332 String value = comboBox.getSelectedItem().toString().replace(" ", "_").toLowerCase();
321   - requestView.updateParam(paramName, "All".equals(value) ? null : value);
  333 + if ("All".equals(value)) {
  334 + mainView.event(Event.paramRemoved, paramName);
  335 + } else {
  336 + mainView.event(Event.paramChanged, paramName, value);
  337 + }
322 338 }
323 339 }
324 340  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/BottomBar.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java
... ... @@ -14,7 +14,7 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.view;
  17 +package eu.omp.irap.vespa.epntapclient.view.panels;
18 18  
19 19 import java.awt.BorderLayout;
20 20 import java.util.logging.Logger;
... ... @@ -23,15 +23,17 @@ import javax.swing.JButton;
23 23 import javax.swing.JLabel;
24 24 import javax.swing.JPanel;
25 25  
  26 +import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
  27 +
26 28 /**
27 29 * @author N. Jourdane
28 30 */
29   -public class BottomBar extends JPanel {
  31 +public class BottomBarPanel extends JPanel {
30 32 /** The logger for the class BottomBar. */
31   - private static final Logger logger = Logger.getLogger(BottomBar.class.getName());
  33 + private static final Logger logger = Logger.getLogger(BottomBarPanel.class.getName());
32 34 JLabel infoLabel;
33 35  
34   - BottomBar(EpnTapMainView mainView) {
  36 + public BottomBarPanel(EpnTapMainView mainView) {
35 37 setLayout(new BorderLayout());
36 38 infoLabel = new JLabel();
37 39 this.add(infoLabel);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java renamed to src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/RequestPanel.java
... ... @@ -14,16 +14,14 @@
14 14 * <http://www.gnu.org/licenses/>.
15 15 */
16 16  
17   -package eu.omp.irap.vespa.epntapclient.view;
  17 +package eu.omp.irap.vespa.epntapclient.view.panels;
18 18  
19 19 import java.awt.BorderLayout;
20 20 import java.awt.Dimension;
21 21 import java.awt.event.ActionEvent;
22 22 import java.awt.event.ActionListener;
23 23 import java.util.ArrayList;
24   -import java.util.HashMap;
25 24 import java.util.List;
26   -import java.util.Map;
27 25 import java.util.logging.Logger;
28 26  
29 27 import javax.swing.BorderFactory;
... ... @@ -32,23 +30,27 @@ import javax.swing.JButton;
32 30 import javax.swing.JPanel;
33 31 import javax.swing.JTextArea;
34 32  
35   -import eu.omp.irap.vespa.epntapclient.utils.Queries;
  33 +import eu.omp.irap.vespa.epntapclient.view.Dim;
  34 +import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
  35 +import eu.omp.irap.vespa.epntapclient.view.Event;
  36 +import eu.omp.irap.vespa.epntapclient.view.ParamField;
36 37 import eu.omp.irap.vespa.epntapclient.view.ParamField.DataProductTypeField;
37 38 import eu.omp.irap.vespa.epntapclient.view.ParamField.DateRangeField;
38 39 import eu.omp.irap.vespa.epntapclient.view.ParamField.FloatRangeField;
39 40 import eu.omp.irap.vespa.epntapclient.view.ParamField.TargetNameField;
40   -import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException;
41 41  
42 42 /**
43 43 * @author N. Jourdane
44 44 */
45   -public class RequestView extends JPanel implements ActionListener {
  45 +public class RequestPanel extends JPanel implements ActionListener {
46 46 /** The logger for the class RequestView. */
47   - private static final Logger logger = Logger.getLogger(RequestView.class.getName());
  47 + private static final Logger logger = Logger.getLogger(RequestPanel.class.getName());
48 48  
49 49 /** The serial version UID (affected with a random number). */
50 50 private static final long serialVersionUID = 1262856496809315405L;
51 51  
  52 + private static final String BTN_NAME = "btnSend";
  53 +
52 54 /** The EPN-TAP main view. */
53 55 private EpnTapMainView mainView;
54 56  
... ... @@ -62,11 +64,6 @@ public class RequestView extends JPanel implements ActionListener {
62 64 */
63 65 private List<ParamField> paramFields;
64 66  
65   - /**
66   - * The parameters fields for the request.
67   - */
68   - private Map<String, Object> paramValues;
69   -
70 67 /** The height of the buttons panel. */
71 68 private static final int BUTTON_PANEL_HEIGHT = 20;
72 69  
... ... @@ -75,19 +72,23 @@ public class RequestView extends JPanel implements ActionListener {
75 72 *
76 73 * @param mainView The EPN-TAP main view.
77 74 */
78   - public RequestView(EpnTapMainView mainView) {
  75 + public RequestPanel(EpnTapMainView mainView) {
79 76 this.mainView = mainView;
80 77 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  78 + setPreferredSize(new Dimension(Dim.RIGHT_PANEL_WIDTH, Dim.TOP_PANEL_HEIGHT));
  79 + setMinimumSize(new Dimension(Dim.RIGHT_PANEL_MIN_WIDTH, Dim.TOP_PANEL_MIN_HEIGHT));
81 80  
82 81 // TODO: Get max row number from the GUI
83 82  
84   - paramValues = new HashMap<>();
85   -
86 83 this.add(buildParamPanel(), this);
87 84 this.add(buildQueryPanel(), this);
88 85 this.add(buildButtonPanel(), this);
89 86 }
90 87  
  88 + public EpnTapMainView getMainView() {
  89 + return mainView;
  90 + }
  91 +
91 92 /**
92 93 * @return A JPanel containing graphical elements for the service parameters.
93 94 */
... ... @@ -96,10 +97,10 @@ public class RequestView extends JPanel implements ActionListener {
96 97 // - if the field is a String: listbox with 'xx', '%xx', 'xx%', and '%xx%'.
97 98 // - if the field is a numeric value: listbox with <, <=, =, =>, >.
98 99 paramFields = new ArrayList();
99   - paramFields.add(new TargetNameField(this, "target_name"));
100   - paramFields.add(new DateRangeField(this, "time_"));
101   - paramFields.add(new FloatRangeField(this, "spectral_range_"));
102   - paramFields.add(new DataProductTypeField(this, "dataproduct_type"));
  100 + paramFields.add(new TargetNameField(mainView, "target_name"));
  101 + paramFields.add(new DateRangeField(mainView, "time_"));
  102 + paramFields.add(new FloatRangeField(mainView, "spectral_range_"));
  103 + paramFields.add(new DataProductTypeField(mainView, "dataproduct_type"));
103 104 JPanel paramPanel = new JPanel();
104 105 paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.Y_AXIS));
105 106 paramPanel.setBorder(BorderFactory.createTitledBorder("Query parameters"));
... ... @@ -126,23 +127,11 @@ public class RequestView extends JPanel implements ActionListener {
126 127 return queryPanel;
127 128 }
128 129  
129   - public void updateParam(String paramName, Object value) {
130   - if (value == null) {
131   - paramValues.remove(paramName);
132   - logger.info("removed " + paramName);
133   - } else {
134   - paramValues.put(paramName, value);
135   - logger.info("uploaded " + paramName + ": " + value);
136   - }
137   - updateQueryArea();
138   - }
139   -
140 130 /**
141 131 * Update the query JTextArea according to the parameters values.
142 132 */
143   - public void updateQueryArea() {
144   - String tableName = mainView.getController().getSelectedTable();
145   - queryArea.setText(Queries.getQuery(tableName, paramValues, 10));
  133 + public void updateQueryArea(String query) {
  134 + queryArea.setText(query);
146 135 }
147 136  
148 137 /**
... ... @@ -151,23 +140,18 @@ public class RequestView extends JPanel implements ActionListener {
151 140 private JPanel buildButtonPanel() {
152 141 JPanel buttonPanel = new JPanel();
153 142 JButton btnSend = new JButton("Send query");
154   - btnSend.setName("btnSend");
  143 + btnSend.setName(BTN_NAME);
155 144 btnSend.addActionListener(this);
156 145 buttonPanel.add(btnSend);
157   - buttonPanel.setMaximumSize(
158   - new Dimension(1000, BUTTON_PANEL_HEIGHT));
  146 + buttonPanel.setMaximumSize(new Dimension(1000, BUTTON_PANEL_HEIGHT));
159 147  
160 148 return buttonPanel;
161 149 }
162 150  
163 151 @Override
164 152 public void actionPerformed(ActionEvent evt) {
165   - if (((JButton) evt.getSource()).getName() == "btnSend") {
166   - try {
167   - mainView.getController().sendQuery(queryArea.getText());
168   - } catch (VOTableException e) {
169   - logger.warning("Can not send query when clicking on the send button." + e);
170   - }
  153 + if (((JButton) evt.getSource()).getName() == BTN_NAME) {
  154 + this.mainView.event(Event.btnSearchClicked, queryArea.getText());
171 155 }
172 156 }
173 157  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ResultsPanel.java 0 โ†’ 100644
... ... @@ -0,0 +1,54 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.view.panels;
  18 +
  19 +import java.awt.BorderLayout;
  20 +import java.awt.Dimension;
  21 +import java.util.logging.Logger;
  22 +
  23 +import javax.swing.JPanel;
  24 +
  25 +import eu.omp.irap.vespa.epntapclient.view.Dim;
  26 +import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
  27 +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
  28 +
  29 +/**
  30 + * @author N. Jourdane
  31 + */
  32 +public class ResultsPanel extends JPanel {
  33 + /** The logger for the class ResultPanel. */
  34 + private static final Logger logger = Logger.getLogger(ResultsPanel.class.getName());
  35 +
  36 + EpnTapMainView mainView;
  37 + VOTableView voTableView;
  38 +
  39 + public ResultsPanel(EpnTapMainView mainView, VOTableView voTableView) {
  40 + super();
  41 +
  42 + this.mainView = mainView;
  43 + this.voTableView = voTableView;
  44 +
  45 + this.setLayout(new BorderLayout());
  46 + this.add(voTableView);
  47 +
  48 + setPreferredSize(new Dimension(Dim.LEFT_PANEL_WIDTH + Dim.RIGHT_PANEL_WIDTH,
  49 + Dim.BOTTOM_PANEL_HEIGHT));
  50 + setMinimumSize(new Dimension(Dim.LEFT_PANEL_MIN_WIDTH + Dim.RIGHT_PANEL_MIN_WIDTH,
  51 + Dim.BOTTOM_PANEL_MIN_HEIGHT));
  52 +
  53 + }
  54 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/ServicesPanel.java 0 โ†’ 100644
... ... @@ -0,0 +1,70 @@
  1 +/*
  2 + * This file is a part of EpnTAPClient.
  3 + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
  4 + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
  5 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planรฉtologie.
  6 + *
  7 + * This program is free software: you can
  8 + * redistribute it and/or modify it under the terms of the GNU General Public License as published
  9 + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later
  10 + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12 + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of
  13 + * the GNU General Public License along with this program. If not, see
  14 + * <http://www.gnu.org/licenses/>.
  15 + */
  16 +
  17 +package eu.omp.irap.vespa.epntapclient.view.panels;
  18 +
  19 +import java.awt.BorderLayout;
  20 +import java.awt.Dimension;
  21 +import java.util.logging.Logger;
  22 +
  23 +import javax.swing.JPanel;
  24 +import javax.swing.event.ListSelectionEvent;
  25 +import javax.swing.event.ListSelectionListener;
  26 +
  27 +import eu.omp.irap.vespa.epntapclient.view.Dim;
  28 +import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
  29 +import eu.omp.irap.vespa.epntapclient.view.Event;
  30 +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
  31 +
  32 +/**
  33 + * @author N. Jourdane
  34 + */
  35 +public class ServicesPanel extends JPanel {
  36 + /** The logger for the class ServicesView. */
  37 + private static final Logger logger = Logger.getLogger(ServicesPanel.class.getName());
  38 +
  39 + EpnTapMainView mainView;
  40 + VOTableView voTableView;
  41 +
  42 + public ServicesPanel(final EpnTapMainView mainView, final VOTableView voTableView) {
  43 + super();
  44 + this.mainView = mainView;
  45 + this.voTableView = voTableView;
  46 +
  47 + this.setLayout(new BorderLayout());
  48 + this.add(voTableView);
  49 +
  50 + setPreferredSize(new Dimension(Dim.LEFT_PANEL_WIDTH, Dim.TOP_PANEL_HEIGHT));
  51 + setMinimumSize(new Dimension(Dim.LEFT_PANEL_MIN_WIDTH, Dim.TOP_PANEL_MIN_HEIGHT));
  52 +
  53 + // TODO: Support multi-selection
  54 + voTableView.getTable().getSelectionModel()
  55 + .addListSelectionListener(new ListSelectionListener() {
  56 + public void valueChanged(ListSelectionEvent evt) {
  57 + mainView.event(Event.serviceSelected,
  58 + voTableView.getTable().getSelectedRow());
  59 + }
  60 + });
  61 + }
  62 +
  63 + public String getServiceURL(int row) {
  64 + return (String) this.voTableView.getValueAt(5, row);
  65 + }
  66 +
  67 + public String getTableName(int row) {
  68 + return (String) this.voTableView.getValueAt(2, row);
  69 + }
  70 +}
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
... ... @@ -29,6 +29,8 @@ import javax.swing.event.TableModelEvent;
29 29 import javax.swing.event.TableModelListener;
30 30 import javax.swing.table.DefaultTableModel;
31 31  
  32 +import eu.omp.irap.vespa.epntapclient.votable.Utils;
  33 +
32 34 /**
33 35 * The main class of the View of the application.
34 36 *
... ... @@ -79,6 +81,7 @@ public class VOTableView extends JPanel implements TableModelListener {
79 81 */
80 82 public void fillTable(String[] columns, List<Object[]> data) {
81 83 Object[][] values = data.toArray(new Object[data.size()][]);
  84 + Utils.printObject("tableData", values);
82 85 tableData.setDataVector(values, columns);
83 86 table.setRowSelectionInterval(0, 0);
84 87 }
... ... @@ -97,6 +100,7 @@ public class VOTableView extends JPanel implements TableModelListener {
97 100 * content.
98 101 */
99 102 public Object getValueAt(int column, int row) {
  103 + Object val = tableData.getValueAt(row, column);
100 104 return tableData.getValueAt(row, column);
101 105 }
102 106  
... ...