From 285505bef9aa4b24212d5d4255580250464709ad Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 23 May 2016 17:43:44 +0200 Subject: [PATCH] Remove complex code from panel controllers, let their superclasses do the stuff. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java | 89 ++++++++++++++++++++++++++--------------------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java | 6 ++++-- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java | 6 +++--- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java | 60 +++++++++++++++++------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java | 10 +--------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java | 4 ++-- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java | 2 +- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java | 9 ++------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java | 27 ++++++++++++++------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java | 9 +-------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java | 7 +------ src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java | 69 +++++++++++++++++++++++++++++++++++++-------------------------------- src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java | 2 -- src/test/java/eu/omp/irap/vespa/epntapclient/granule/GranuleTest.java | 4 ++-- 21 files changed, 268 insertions(+), 295 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java index 226e382..f105fb3 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -16,84 +16,83 @@ package eu.omp.irap.vespa.epntapclient; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.service.Queries; import eu.omp.irap.vespa.epntapclient.service.ServiceCore; import eu.omp.irap.vespa.votable.Consts; -import eu.omp.irap.vespa.votable.controller.VOTableException; import eu.omp.irap.vespa.votable.controller.VOTableController; +import eu.omp.irap.vespa.votable.controller.VOTableException; +import eu.omp.irap.vespa.votable.utils.StringJoiner; /** * The main controller which manage views and controllers. * * @author N. Jourdane */ -public class EpnTapController { +public abstract class EpnTapController { /** The logger for the class EpnTapController. */ private static final Logger LOGGER = Logger.getLogger(EpnTapController.class.getName()); - /** The controller of the VOTable displaying the list of services. */ - private VOTableController servicesCtrl; - - /** The controller of the VOTable displaying the result. */ - private VOTableController resultsCtrl; - - /** The request controller, to manage requests. */ - private RequestCtrl requestCtrl; - /** * The path of the VOTable to parse. Will be affected to a temporary folder if not assigned * through the controller. */ private String voTablePath; + /** The request controller, to manage requests. */ + private RequestCtrl requestCtrl; + + /** The controller of the VOTable displaying the result. */ + private VOTableController resultsCtrl; + + /** The controller of the VOTable displaying the list of services. */ + private VOTableController servicesCtrl; + /** * Method constructor, which initialize servicesController, resultsController and mainView. */ public EpnTapController() { + // TODO: Should not init controllers, because the default ctrl is called by subclasses. String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); } /** - * Get the services from the XML path or the targetURL / query. - */ - public void readServices() { - try { - servicesCtrl.readTable(); - } catch (VOTableException e) { - displayError("Can not get services.", e); - } - } - - /** - * display an error with the logger. + * Display an error with the logger. * * @param message A small error message. * @param e The error. */ - @SuppressWarnings("static-method") + @SuppressWarnings("static-method") // Because the method is overrided by a subclass. public void displayError(String message, Exception e) { LOGGER.log(Level.SEVERE, message, e); } /** - * Send the query to the specified service, download the result and update the voTable path. - * - * @param query An ADQL query to send. - * @param tableServiceURL the URL of the service. - * @throws VOTableException Can not get the VOTable. + * @return The request controller. */ - public void sendQuery(String query, String tableServiceURL) - throws VOTableException { - resultsCtrl = new VOTableController(tableServiceURL, query); - resultsCtrl.readTable(); - voTablePath = resultsCtrl.getVOTablePath(); + public RequestCtrl getRequestCtrl() { + return requestCtrl; + } + + /** + * @return The controller of the VOTable which displays the result of the query. + */ + public VOTableController getResultsCtrl() { + return resultsCtrl; + } + + /** + * @return The controller of the VOTable which displays the list of services. + */ + public VOTableController getServicesCtrl() { + return servicesCtrl; } /** @@ -104,24 +103,45 @@ public class EpnTapController { } /** - * @return The controller of the VOTable which displays the result of the query. + * Get the services from the XML path or the targetURL / query. */ - public VOTableController getResultsController() { - return resultsCtrl; + public void readServices() { + // Here getServicesCtrl() is used instead of class field servicesCtrl to get the + // subclass field, since subclasses overrides getServicesCtrl(). + try { + getServicesCtrl().readTable(); + } catch (VOTableException e) { + displayError("Can not get services.", e); + } } - /** - * @return The controller of the VOTable which displays the list of services. - */ - public VOTableController getServicesController() { - return servicesCtrl; + public void sendQuery(List tableNames, List servicesUrls) { + // Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl + // and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and + // getResultsCtrl(). + try { + LOGGER.info("Sending queries on " + StringJoiner.join(servicesUrls)); + for (int i = 0; i < tableNames.size(); i++) { + String query = getRequestCtrl().getQuery(tableNames.get(i)); + getResultsCtrl().updateVOTable(servicesUrls.get(i), query); + } + } catch (VOTableException e) { + displayError("Can not update the VOTable.", e); + } + } /** - * @return The request controller. + * Send the query to the specified service, download the result and update the voTable path. + * + * @param query An ADQL query to send. + * @param tableServiceURL the URL of the service. + * @throws VOTableException Can not get the VOTable. */ - public RequestCtrl getRequestCtrl() { - return requestCtrl; + public void sendQuery(String query, String tableServiceURL) throws VOTableException { + resultsCtrl = new VOTableController(tableServiceURL, query); + resultsCtrl.readTable(); + voTablePath = resultsCtrl.getVOTablePath(); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java index cf3bb2b..e480ab3 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java @@ -63,7 +63,7 @@ public class EpnTapMainApp { /** * Creates runnable used to run the application GUI. - * + * * @param voTableView The VOTable main view, created by the controller. * @param title The title of the application window. * @return The runnable. diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java index 70ae6fa..5a503c6 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -33,25 +34,40 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; */ public class RequestCtrl { + /** The text in the query to replaced by the actual table name. */ + private static final String KEYWORD_TABLE_NAME_ = "#tablename#"; + + /** The logger for the class RequestCtrl. */ + private static final Logger LOGGER = Logger.getLogger(RequestCtrl.class.getName()); + + /** The query template to get granules. */ + private static final String QUERY_TEMPLATE = "SELECT DISTINCT TOP %s %s FROM " + + KEYWORD_TABLE_NAME_ + "%s"; + /** The URL of the resolver used for the `target name` field. */ private static final String RESOLVER_URL = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete"; - /** The text in the query to replaced by the actual table name. */ - protected static final String TABLE_NAME_KEYWORD = "#tablename#"; + /** The names of the columns used in the SELECT keyword in the query. */ + protected List columnNames; - /** The query template to get granules. */ - private static final String QUERY = "SELECT DISTINCT TOP %s %s FROM " + TABLE_NAME_KEYWORD - + "%s"; + /** The maximum number of rows returned by the query. */ + protected int nbMaxResult; /** The parameters fields for the request. */ protected Map parameters = new HashMap<>(); - /** The maximum number of rows returned by the query. */ - private int nbMaxResult; + /** + * The query to send, with the name of the table is replaced by {@link #KEYWORD_TABLE_NAME_}. + */ + protected String query; - /** Constructor of RequestCtrl. */ + /** Default constructor of RequestCtrl. */ public RequestCtrl() { + List newColumnNames = new ArrayList<>(); + newColumnNames.add("target_name"); + newColumnNames.add("target_class"); + columnNames = newColumnNames; nbMaxResult = 20; } @@ -60,35 +76,9 @@ public class RequestCtrl { * * @param nbMaxResult The maximum number of rows returned by the query. */ - public RequestCtrl(int nbMaxResult) { + public RequestCtrl(int nbMaxResult, List columnNames) { this.nbMaxResult = nbMaxResult; - } - - /** - * Build an ADQL from the table name, the parameter values and the max results. - * - * @param tableName The names of the tables, to put in the FROM keyword. - * @return The query. - */ - public String buildQuery(List columnNames) { - StringJoiner addJoin = new StringJoiner(" AND "); - for (Map.Entry param : parameters.entrySet()) { - if (param.getValue() instanceof ArrayList) { - StringJoiner orJoin = new StringJoiner(" OR "); - @SuppressWarnings("unchecked") - List possibleValues = (List) param.getValue(); - for (String possibleValue : possibleValues) { - orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); - } - addJoin.add("(" + orJoin + ")"); - } else if (param.getValue() instanceof String) { - addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); - } else { - addJoin.add(param.getKey() + " = " + param.getValue().toString()); - } - } - String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; - return String.format(QUERY, nbMaxResult, StringJoiner.join(columnNames), where); + this.columnNames = columnNames; } /** @@ -114,23 +104,15 @@ public class RequestCtrl { return targetNames; } - /** - * Update a parameter in the query. If the parameter do not exists yet, create it. - * - * @param paramName The name of the parameter. - * @param paramValue The value of the parameter. - */ - public void updateParameter(String paramName, Object paramValue) { - parameters.put(paramName, paramValue); + public List getColumnNames() { + return columnNames; } /** - * Remove a parameter from the query. - * - * @param paramName The name of the parameter to remove. + * @return The maximum number of rows returned by the query. */ - public void removeParameter(String paramName) { - parameters.remove(paramName); + public int getNbMaxResult() { + return nbMaxResult; } /** @@ -142,11 +124,22 @@ public class RequestCtrl { return parameters; } + public String getQuery(String tableName) { + return query.replace(KEYWORD_TABLE_NAME_, tableName); + } + /** - * @return The maximum number of rows returned by the query. + * Remove a parameter from the query. + * + * @param paramName The name of the parameter to remove. */ - public int getNbMaxResult() { - return nbMaxResult; + public void removeParameter(String paramName) { + parameters.remove(paramName); + LOGGER.info("removed " + paramName); + } + + public void setColumnNames(List columnNames) { + this.columnNames = columnNames; } /** @@ -158,4 +151,46 @@ public class RequestCtrl { nbMaxResult = nbRows; } + public void setQuery(String query) { + this.query = query; + } + + /** + * Update a parameter in the query. If the parameter do not exists yet, create it. + * + * @param paramName The name of the parameter. + * @param paramValue The value of the parameter. + */ + public void updateParameter(String paramName, Object paramValue) { + parameters.put(paramName, paramValue); + LOGGER.info("updated " + paramName + ": " + paramValue); + + } + + /** + * Update the ADQL query, from the column names, the table name, the parameter values and the + * max results. + */ + public void updateQuery() { + StringJoiner addJoin = new StringJoiner(" AND "); + for (Map.Entry param : parameters.entrySet()) { + if (param.getValue() instanceof ArrayList) { + StringJoiner orJoin = new StringJoiner(" OR "); + @SuppressWarnings("unchecked") + List possibleValues = (List) param.getValue(); + for (String possibleValue : possibleValues) { + orJoin.add(param.getKey() + " LIKE '" + possibleValue + "'"); + } + addJoin.add("(" + orJoin + ")"); + } else if (param.getValue() instanceof String) { + addJoin.add(param.getKey() + " LIKE '" + param.getValue() + "'"); + } else { + addJoin.add(param.getKey() + " = " + param.getValue().toString()); + } + } + String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; + query = String.format(QUERY_TEMPLATE, nbMaxResult, StringJoiner.join(columnNames), where); + + } + } 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 693f1f5..d06aaea 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 @@ -17,8 +17,6 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JOptionPane; @@ -26,26 +24,21 @@ import eu.omp.irap.vespa.epntapclient.EpnTapController; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl; -import eu.omp.irap.vespa.votable.controller.VOTableException; -import eu.omp.irap.vespa.votable.utils.StringJoiner; /** * @author N. Jourdane */ public class MainPanelCtrl extends EpnTapController implements MainPanelListener { - /** The logger for the class GUIController. */ - private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); - /** The controller of the request panel. */ private RequestPanelCtrl requestPanelCtrl; + /** The controller of the result panel. */ + private ResultPanelCtrl resultsPanelCtrl; + /** The controller of the services panel. */ private ServicesPanelCtrl servicesPanelCtrl; - /** The controller of the result panel. */ - private ResultPanelCtrl resultPanelCtrl; - /** The main view of the application. */ private MainPanelView view; @@ -55,57 +48,44 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener */ public MainPanelCtrl() { servicesPanelCtrl = new ServicesPanelCtrl(this); - resultPanelCtrl = new ResultPanelCtrl(); + resultsPanelCtrl = new ResultPanelCtrl(this); requestPanelCtrl = new RequestPanelCtrl(this); view = new MainPanelView(this); } @Override - public void readServices() { - try { - servicesPanelCtrl.readTable(); - } catch (VOTableException e) { - displayError("Can not get services.", e); - } - view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); + public void displayError(String message, Exception e) { + super.displayError(message, e); + JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); } /** - * Send the specified query to the selected service and update the result table content. - * - * @param query The query to send. + * @return The controller of the request panel. */ - public void sendQuery(String query) { - List selectedServicesUrls = servicesPanelCtrl.getSelectedServicesUrls(); - LOGGER.info("Sending query: " + query + " on " + StringJoiner.join(selectedServicesUrls)); - try { - resultPanelCtrl.updateVOTable(StringJoiner.join(selectedServicesUrls), query); - view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); - } catch (VOTableException e) { - displayError("Can not send the query.", e); - LOGGER.log(Level.WARNING, "Can not send query.", e); - } + @Override + public RequestPanelCtrl getRequestCtrl() { + return requestPanelCtrl; } /** - * @return The controller of the request panel. + * @return The controller of the result panel. */ - public RequestPanelCtrl getRequestPanelCtrl() { - return requestPanelCtrl; + @Override + public ResultPanelCtrl getResultsCtrl() { + return resultsPanelCtrl; } /** * @return The controller of the service panel. */ - public ServicesPanelCtrl getServicePanelCtrl() { + @Override + public ServicesPanelCtrl getServicesCtrl() { return servicesPanelCtrl; } - /** - * @return The controller of the result panel. - */ - public ResultPanelCtrl getResultPanelCtrl() { - return resultPanelCtrl; + @Override + public List getTableNames() { + return servicesPanelCtrl.getTablesNames(); } /** @@ -116,35 +96,18 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener } @Override - public void displayError(String message, Exception e) { - LOGGER.log(Level.SEVERE, message, e); - JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); - } - - @Override - public void updateQuery() { - requestPanelCtrl.updateQueryArea(); + public void readServices() { + super.readServices(); + view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); } @Override 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)); - resultPanelCtrl.updateVOTable(servicesUrls.get(i), query); - } - } catch (VOTableException e) { - displayError("Can not update the VOTable.", e); - } - resultPanelCtrl.getView().fillTable(resultPanelCtrl.getVOTableData()); + sendQuery(servicesPanelCtrl.getTablesNames(), servicesPanelCtrl.getServicesUrls()); } @Override - public List getTableNames() { - return servicesPanelCtrl.getSelectedTablesNames(); + public void updateQuery() { + requestPanelCtrl.updateQuery(); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java index 79a236c..4fdcc35 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java @@ -23,9 +23,11 @@ import java.util.List; */ public interface MainPanelListener { - void updateQuery(); + List getTableNames(); void sendQuery(); - List getTableNames(); + void updateQuery(); + + void displayError(String message, Exception e); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java index 8efc5bb..d935e85 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java @@ -54,9 +54,9 @@ public class MainPanelView extends JPanel { */ public MainPanelView(MainPanelCtrl mainPanelCtrl) { - servicesPanel = mainPanelCtrl.getServicePanelCtrl().getView(); - resultPanel = mainPanelCtrl.getResultPanelCtrl().getView(); - requestPanel = mainPanelCtrl.getRequestPanelCtrl().getView(); + servicesPanel = mainPanelCtrl.getServicesCtrl().getView(); + resultPanel = mainPanelCtrl.getResultsCtrl().getView(); + requestPanel = mainPanelCtrl.getRequestCtrl().getView(); buildMainView(); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java index c0a7662..ac48611 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java @@ -16,13 +16,6 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.swing.JOptionPane; - import eu.omp.irap.vespa.epntapclient.RequestCtrl; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; @@ -31,9 +24,6 @@ import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; */ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListener { - /** The logger for the class RequestPanelCtrl. */ - private static final Logger LOGGER = Logger.getLogger(RequestPanelCtrl.class.getName()); - /** The controller of the main panel. */ private MainPanelListener listener; @@ -48,21 +38,28 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene */ public RequestPanelCtrl(MainPanelListener listener) { this.listener = listener; + // TODO: Add panel to enter column names and the max results. view = new RequestPanelView(this); } /** - * @return The view of the request panel. + * @return The view of the request panel. Used in MainPanelCtrl to add panels in the main + * window. */ public RequestPanelView getView() { return view; } - /** - * @return The text contained in the query area. - */ - public String getQuery(String tableName) { - return view.getQueryArea().getText().replace(TABLE_NAME_KEYWORD, tableName); + @Override + public void onParameterRemoved(String paramName) { + removeParameter(paramName); + updateQuery(); + } + + @Override + public void onParameterUpdated(String paramName, Object paramValue) { + updateParameter(paramName, paramValue); + updateQuery(); } @Override @@ -71,35 +68,12 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene } /** - * Update the query area with a working ADQL query, based on the parameters list. + * Update the query and the query area with a working ADQL query, based on the parameters list. */ - public void updateQueryArea() { - // TODO: several services - // TODO: Add panel to enter column names. - List columnNames = new ArrayList<>(); - columnNames.add("target_name"); - columnNames.add("target_class"); - String query = buildQuery(columnNames); - view.updateQueryArea(query); - } - - @Override - public void onParameterRemoved(String paramName) { - removeParameter(paramName); - updateQueryArea(); - LOGGER.info("removed " + paramName); - } - @Override - public void onParameterChanged(String paramName, Object paramValue) { - updateParameter(paramName, paramValue); - updateQueryArea(); - LOGGER.info("uploaded " + paramName + ": " + paramValue); + public void updateQuery() { + super.updateQuery(); + view.updateQueryArea(query); } - @Override - public void onError(Exception e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); - JOptionPane.showMessageDialog(view, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java index aa73e3e..e8be638 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java @@ -39,13 +39,5 @@ public interface RequestPanelListener { * @param paramName The name of the changed parameter. * @param paramValue The new value of the parameter. */ - void onParameterChanged(String paramName, Object paramValue); - - /** - * Display an error to the user. - * - * @param e The error to display to the user. - */ - public void onError(Exception e); - + void onParameterUpdated(String paramName, Object paramValue); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java index 3a9231b..44b5cd5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DataProductTypeField.java @@ -85,7 +85,7 @@ public class DataProductTypeField extends ParamField { if (DataProductType.ALL.equals(item)) { requestPanelListener.onParameterRemoved(paramName); } else { - requestPanelListener.onParameterChanged(paramName, item.query()); + requestPanelListener.onParameterUpdated(paramName, item.query()); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java index 55f78d5..66d9755 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/DateRangeField.java @@ -92,7 +92,7 @@ public class DateRangeField extends ParamField implements TextFieldListener { try { long date = df.parse(field.getText()).getTime(); date = Math.round(date / 86400000.0 + 2440587.5); // to JD - requestPanelListener.onParameterChanged(paramName + field.getName(), + requestPanelListener.onParameterUpdated(paramName + field.getName(), date); field.setBackground(Color.WHITE); } catch (@SuppressWarnings("unused") ParseException e) { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java index f92aaee..d379db8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatField.java @@ -62,7 +62,7 @@ public class FloatField extends ParamField implements TextFieldListener { } else { try { float value = Float.parseFloat(textField.getText()); - requestPanelListener.onParameterChanged(paramName, value); + requestPanelListener.onParameterUpdated(paramName, value); textField.setBackground(Color.WHITE); } catch (@SuppressWarnings("unused") NumberFormatException e) { textField.setBackground(Color.PINK); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java index 158aa12..b27be3d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/FloatRangeField.java @@ -70,7 +70,7 @@ public class FloatRangeField extends ParamField implements TextFieldListener { requestPanelListener.onParameterRemoved(paramName + field.getName()); } else { try { - requestPanelListener.onParameterChanged(paramName + field.getName(), + requestPanelListener.onParameterUpdated(paramName + field.getName(), Float.parseFloat(field.getText())); field.setBackground(Color.WHITE); } catch (@SuppressWarnings("unused") NumberFormatException e) { diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java index 594d4a5..2451c90 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/StringField.java @@ -54,9 +54,9 @@ public class StringField extends ParamField implements TextFieldListener { @Override public void update(JTextField textField) { if (textField.getText().isEmpty()) { - requestPanelListener.onParameterChanged(paramName, null); + requestPanelListener.onParameterUpdated(paramName, null); } else { - requestPanelListener.onParameterChanged(paramName, textField.getText()); + requestPanelListener.onParameterUpdated(paramName, textField.getText()); } } } \ No newline at end of file diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java index 6546392..38dc876 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetClassField.java @@ -70,7 +70,7 @@ public class TargetClassField extends ParamField { if (TargetClass.ALL.equals(value)) { requestPanelListener.onParameterRemoved(paramName); } else { - requestPanelListener.onParameterChanged(paramName, value.query()); + requestPanelListener.onParameterUpdated(paramName, value.query()); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java index 7b2d8b6..286e3e3 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java @@ -93,14 +93,9 @@ public class TargetNameField extends ParamField implements TextFieldListener { } @Override - public void onParameterChanged(String paramName, Object paramValue) { + public void onParameterUpdated(String paramName, Object paramValue) { /** No ParameterChanged event, we just want the field itself. */ } - - @Override - public void onError(Exception e) { - /** No Error event, we just want the field itself. */ - } }, paraName); } @@ -128,7 +123,7 @@ public class TargetNameField extends ParamField implements TextFieldListener { if (content.isEmpty()) { requestPanelListener.onParameterRemoved(paramName); } else { - requestPanelListener.onParameterChanged(paramName, content); + requestPanelListener.onParameterUpdated(paramName, content); } } } 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 5388d0f..596a6e6 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,13 +20,10 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JOptionPane; - +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; import eu.omp.irap.vespa.votable.controller.VOTableController; -import eu.omp.irap.vespa.votable.controller.VOTableException.CantSaveVOTableException; import eu.omp.irap.vespa.votable.utils.StringJoiner; /** @@ -40,38 +37,42 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis /** The result panel view. */ private ResultPanelView view; + /** The listener of the main panel. */ + private MainPanelListener listener; + /** * Constructor of ResultPanelCtrl. */ - public ResultPanelCtrl() { + public ResultPanelCtrl(MainPanelListener listener) { + this.listener = listener; view = new ResultPanelView(this); } @Override - public void onDownloadButtonClicked(File file) throws CantSaveVOTableException { + public void onDownloadButtonClicked(File file) { try { Files.copy(Paths.get(voTablePath), Paths.get(file.getAbsolutePath())); } catch (IOException e) { - throw new CantSaveVOTableException(file.getAbsolutePath(), e); + listener.displayError("Can not save the VOTable file.", e); } } /** - * @return The view of the result panel. + * @return The view of the result panel. Used in MainPanelCtrl to add panels in the main window. */ public ResultPanelView getView() { return view; } @Override - public void onRowsSelected() { - LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows())); + public void updateVOTable(String newTargetURL, String newQuery) + throws eu.omp.irap.vespa.votable.controller.VOTableException { + view.fillTable(voTableData); } @Override - public void onError(Exception e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); - JOptionPane.showMessageDialog(view, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + public void onRowsSelected() { + LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows())); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java index 7856f28..f19d99b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java @@ -33,12 +33,5 @@ public interface ResultPanelListener extends VOTableViewListener { * place where save the VOTable. * @throws CantSaveVOTableException The VOTable can not be saved at the specified location. */ - public void onDownloadButtonClicked(File file) throws CantSaveVOTableException; - - /** - * Display an error to the user. - * - * @param e The error to display to the user. - */ - public void onError(Exception e); + public void onDownloadButtonClicked(File file); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java index e0a9382..6ca1ec5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java @@ -25,7 +25,6 @@ import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; -import eu.omp.irap.vespa.votable.controller.VOTableException.CantSaveVOTableException; import eu.omp.irap.vespa.votable.view.VOTableView; /** @@ -100,11 +99,7 @@ public class ResultPanelView extends VOTableView { public void actionPerformed(ActionEvent evt) { final JFileChooser fc = new JFileChooser(); fc.showOpenDialog(ResultPanelView.this); - try { - listener.onDownloadButtonClicked(fc.getSelectedFile()); - } catch (CantSaveVOTableException e) { - listener.onError(e); - } + listener.onDownloadButtonClicked(fc.getSelectedFile()); } }); } 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 e356473..20c9110 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 @@ -49,6 +49,12 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane private ServicesPanelView view; /** The list of services table names selected by the user on the service panel. */ + private List tablesNames; + + /** The list of services target Urls selected by the user on the service panel. */ + private List servicesUrls; + + /** The list of services table names selected by the user on the service panel. */ private List selectedTablesNames; /** The list of services target Urls selected by the user on the service panel. */ @@ -79,7 +85,8 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane } /** - * @return The view of the services panel. + * @return The view of the services panel. Used in MainPanelCtrl to add panels in the main + * window. */ public ServicesPanelView getView() { return view; @@ -88,43 +95,34 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane /** * @return The list of services table names selected by the user on the service panel. */ - public List getSelectedTablesNames() { - return selectedTablesNames; + public List getTablesNames() { + return tablesNames; } /** * @return The list of services target Urls selected by the user on the service panel. */ - public List getSelectedServicesUrls() { - 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; + public List getServicesUrls() { + return servicesUrls; } @Override public void onRowsSelected() { - List servicesUrls = new ArrayList<>(); - List tableNames = new ArrayList<>(); + List newServicesUrls = new ArrayList<>(); + List newTablesNames = new ArrayList<>(); 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)); + newServicesUrls.add((String) view.getValueAt(SERVICE_URL_COLUMN_POSITION, row)); + newTablesNames.add((String) view.getValueAt(TABLE_NAME_COLUMN_POSITION, row)); } - selectedServicesUrls = servicesUrls; - selectedTablesNames = tableNames; + selectedServicesUrls = newServicesUrls; + selectedTablesNames = newTablesNames; + + servicesUrls = customServicesUrls; + tablesNames = customTablesNames; + servicesUrls.addAll(selectedServicesUrls); + tablesNames.addAll(customTablesNames); listener.updateQuery(); LOGGER.info("Updated selected services URLs: " + StringJoiner.join(selectedServicesUrls)); @@ -137,16 +135,23 @@ public class ServicesPanelCtrl extends VOTableController implements ServicesPane String customTableName = view.getTableNameTextField().getText(); if (!customServiceUrl.isEmpty() && !customTableName.isEmpty()) { - List servicesUrls = new ArrayList<>(); - List tableNames = new ArrayList<>(); + List newServicesUrls = new ArrayList<>(); + List newTablesNames = new ArrayList<>(); - servicesUrls.addAll(Arrays.asList(customServiceUrl.split(CUSTOM_SERVICES_SEPARATOR))); - tableNames.addAll(Arrays.asList(customTableName.split(CUSTOM_SERVICES_SEPARATOR))); + newServicesUrls + .addAll(Arrays.asList(customServiceUrl.split(CUSTOM_SERVICES_SEPARATOR))); + newTablesNames.addAll(Arrays.asList(customTableName.split(CUSTOM_SERVICES_SEPARATOR))); - if (servicesUrls.size() == tableNames.size()) { + if (newServicesUrls.size() == newTablesNames.size()) { // TODO: regex to check valid url / table name - customServicesUrls = servicesUrls; - customTablesNames = tableNames; + customServicesUrls = newServicesUrls; + customTablesNames = newTablesNames; + + servicesUrls = selectedServicesUrls; + tablesNames = selectedTablesNames; + servicesUrls.addAll(customServicesUrls); + tablesNames.addAll(customTablesNames); + LOGGER.info( "Updated custom services URLs: " + StringJoiner.join(customServicesUrls)); LOGGER.info("Updated custom tables names: " + StringJoiner.join(customTablesNames)); diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java index a17739d..83472eb 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java @@ -34,7 +34,6 @@ import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; import eu.omp.irap.vespa.votable.controller.VOTableException; -import eu.omp.irap.vespa.votable.utils.Debug; import eu.omp.irap.vespa.votable.votabledata.VOTableData; /** @@ -348,7 +347,6 @@ public class EpnTapConnectionTest { assertEquals(8, granules.size()); Granule mars = null; for (Granule granule : granules) { - System.out.println(Debug.toJson(granule)); if ("Mars".equals(granule.getGranuleUid())) { mars = granule; } diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/granule/GranuleTest.java b/src/test/java/eu/omp/irap/vespa/epntapclient/granule/GranuleTest.java index 20d8b57..537b307 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/granule/GranuleTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/granule/GranuleTest.java @@ -83,12 +83,12 @@ public class GranuleTest { } @Test - public void isNotValidTest() { + public static void isNotValidTest() { assertFalse("The incomplete granule is valid.", createIncompleteGranule().isValid()); } @Test - public void isValidTest() { + public static void isValidTest() { assertTrue("The complete granule is not valid.", createCompleteGranule().isValid()); } -- libgit2 0.21.2