diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java index ea144f1..5f11d93 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java @@ -96,7 +96,6 @@ public class EpnTapConnection implements EpnTapInterface { @Override public VOTABLE getEPNServices(List keywords, List attributes) throws CantGetVOTableException { - // TODO: move this code to a new class in ServiceCtrl() attributes.add("res_subject"); String select = StringJoiner.join(attributes); List whereList = new ArrayList<>(); 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 622b0b6..ad6409f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java @@ -53,7 +53,6 @@ public class EpnTapController { String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); - requestCtrl = new RequestCtrl(this); } /** @@ -94,6 +93,10 @@ public class EpnTapController { voTablePath = resultsCtrl.getVOTablePath(); } + public String getVOTablePath() { + return voTablePath; + } + /** * @return The controller of the VOTable which displays the result of the query. */ 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 76fe0b1..6f7d02b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java @@ -23,8 +23,8 @@ import javax.swing.SwingUtilities; import com.google.gson.Gson; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelView; +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelView; /** * Simple class to have a main function to launch the EPNTap client. diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java b/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java index e0fccfc..7b8566f 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/Query.java @@ -28,15 +28,15 @@ public enum Query { // TBC // @format - private String query; + private String literalQuery; - Query(String query) { - this.query = query; + Query(String literalQuery) { + this.literalQuery = literalQuery; } @Override public String toString() { - return query; + return literalQuery; } } 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 530d2db..720cee1 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/RequestCtrl.java @@ -20,7 +20,6 @@ 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; @@ -34,23 +33,15 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; */ public class RequestCtrl { - /** The logger for the class RequestCtrl. */ - private static final Logger logger = Logger.getLogger(RequestCtrl.class.getName()); - /** 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 parameters fields for the request. */ protected Map paramValues = new HashMap<>(); - private EpnTapController epnTapCtrl; - public RequestCtrl() { - } - - public RequestCtrl(EpnTapController epnTapCtrl) { - this.epnTapCtrl = epnTapCtrl; + /* Subclasses initializes their own attributes, we don't want to initialize them twice. */ } /** @@ -59,9 +50,9 @@ public class RequestCtrl { * @param params A map of parameters, for the `WHERE` keywords. * @return The literal string of the query. */ - public static String getQuery(String tableName, Map params, int nbRow) { + public String getQuery(String tableName, int nbRow) { StringJoiner addJoin = new StringJoiner(" AND "); - for (Map.Entry param : params.entrySet()) { + for (Map.Entry param : paramValues.entrySet()) { if (param.getValue() instanceof ArrayList) { StringJoiner orJoin = new StringJoiner(" OR "); @SuppressWarnings("unchecked") @@ -77,6 +68,7 @@ public class RequestCtrl { } } String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; + return "SELECT TOP " + nbRow + " target_name, target_class FROM " + tableName + where; } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/GUIDim.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/GUIDim.java deleted file mode 100644 index 137fa1c..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/GUIDim.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.gui.mainPanel; - -/** - * A simple class containing GUI panel and elements dimensions. - * - * @author N. Jourdane - */ -public class GUIDim { - - /** The width of the left panel (services view). */ - public static final int LEFT_PANEL_WIDTH = 550; - - /** The minimum width of the left panel (services view). */ - public static final int LEFT_PANEL_MIN_WIDTH = 300; - - /** The width of the right panel (request view). */ - public static final int RIGHT_PANEL_WIDTH = 450; - - /** The minimum width of the right panel (request view). */ - public static final int RIGHT_PANEL_MIN_WIDTH = 220; - - /** The height of the top panel (request view and services view). */ - public static final int TOP_PANEL_HEIGHT = 400; - - /** The minimum height of the top panel (request view and services view). */ - public static final int TOP_PANEL_MIN_HEIGHT = 100; - - /** The height of the bottom panel (result view). */ - public static final int BOTTOM_PANEL_HEIGHT = 150; - - /** The minimum height of the bottom panel (result view). */ - public static final int BOTTOM_PANEL_MIN_HEIGHT = 100; - - - /** Private constructor to hide the implicit public one. */ - private GUIDim() { - } -} 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 deleted file mode 100644 index 2e2f2f5..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelCtrl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.gui.mainPanel; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.swing.JOptionPane; - -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.CantGetVOTableException; - -/** - * @author N. Jourdane - */ -public class MainPanelCtrl extends EpnTapController { - - /** The logger for the class GUIController. */ - private static final Logger logger = Logger.getLogger(MainPanelCtrl.class.getName()); - - private RequestPanelCtrl requestPanelCtrl; - - private ServicesPanelCtrl servicesPanelCtrl; - - private ResultPanelCtrl resultPanelCtrl; - - private MainPanelView view; - - private int nbMaxResult = 10; - - - public MainPanelCtrl() { - servicesPanelCtrl = new ServicesPanelCtrl(this); - resultPanelCtrl = new ResultPanelCtrl(this); - requestPanelCtrl = new RequestPanelCtrl(this); - view = new MainPanelView(this); - } - - @Override - public void readServices() { - try { - servicesPanelCtrl.readTable(); - } catch (CantGetVOTableException e) { - displayError("Can not get services.", e); - } - view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); - } - - public void sendQuery(String query) { - String serviceURL = servicesPanelCtrl.getSelectedServiceURL(); - logger.info("Sending query: " + query + " on " + serviceURL); - try { - resultPanelCtrl.updateVOTable(serviceURL, query); - view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); - } catch (CantGetVOTableException e) { - displayError("Can not send the query.", e); - MainPanelCtrl.logger.log(Level.WARNING, "Can not send query.", e); - } - } - - public RequestPanelCtrl getRequestPanelCtrl() { - return requestPanelCtrl; - } - - public ServicesPanelCtrl getServicePanelCtrl() { - return servicesPanelCtrl; - } - - public ResultPanelCtrl getResultPanelCtrl() { - return resultPanelCtrl; - } - - public MainPanelView getView() { - return view; - } - - @Override - public void displayError(String message, Exception e) { - logger.log(Level.SEVERE, message, e); - JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); - } - - /** - * @return the nb max of result - */ - public int getNbMaxResult() { - return nbMaxResult; - } - - /** - * set the nb max of result for a query - */ - public void setNbMaxResult(int nb) { - nbMaxResult = nb; - } - -} 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 deleted file mode 100644 index e438b3a..0000000 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainPanel/MainPanelView.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file is a part of EpnTAPClient. - * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. - * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 - * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. - * - * This program is free software: you can - * redistribute it and/or modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, or (at your option) any later - * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. You should have received a copy of - * the GNU General Public License along with this program. If not, see - * . - */ - -package eu.omp.irap.vespa.epntapclient.gui.mainPanel; - -import java.awt.BorderLayout; -import java.awt.Dimension; - -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; - -import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelView; -import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelView; -import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelView; - -/** - * The main view of the application, which manage all the other views. - * - * @author N. Jourdane - */ -public class MainPanelView extends JPanel { - - /** The serial version UID. */ - private static final long serialVersionUID = 1L; - - /** The JPanel where the VOTable results is displayed. */ - private ResultPanelView resultPanel; - - /** The JPanel where the list of services is displayed. */ - private ServicesPanelView servicesPanel; - - /** The JPanel where the user build the query. */ - private RequestPanelView requestPanel; - - - /** - * The main view constructor, which create all the panels. - * - * @param voTableServicesView The view to put in the services panel, built by ServicesController - * @param voTableResultsView The view to put in the results panel, built by ResultsController. - */ - - public MainPanelView(MainPanelCtrl mainPanelCtrl) { - servicesPanel = mainPanelCtrl.getServicePanelCtrl().getView(); - resultPanel = mainPanelCtrl.getResultPanelCtrl().getView(); - requestPanel = mainPanelCtrl.getRequestPanelCtrl().getView(); - buildMainView(); - } - - /** - * Build and fill the GUI. - */ - private void buildMainView() { - setLayout(new BorderLayout()); - - JSplitPane northPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, servicesPanel, - requestPanel); - JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, northPanel, resultPanel); - - add(mainPanel, BorderLayout.CENTER); - - revalidate(); - setSizes(); - } - - private void setSizes() { - servicesPanel.setPreferredSize( - new Dimension(GUIDim.LEFT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT)); - servicesPanel.setMinimumSize( - new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT)); - - requestPanel.setPreferredSize( - new Dimension(GUIDim.RIGHT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT)); - requestPanel.setMinimumSize( - new Dimension(GUIDim.RIGHT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT)); - - resultPanel.setPreferredSize( - new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH + GUIDim.RIGHT_PANEL_MIN_WIDTH, - GUIDim.BOTTOM_PANEL_HEIGHT)); - resultPanel.setMinimumSize( - new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH + GUIDim.RIGHT_PANEL_MIN_WIDTH, - GUIDim.BOTTOM_PANEL_MIN_HEIGHT)); - } - - /** - * @return The JPanel where the VOTable result is displayed. - */ - public ResultPanelView getResultsPanel() { - return resultPanel; - } - - /** - * @return The JPanel containing the GUI elements to build the query. - */ - public RequestPanelView getRequestPanel() { - return requestPanel; - } - - /** - * @return The JPanel where the list of services is displayed. - */ - public ServicesPanelView getServicesPanel() { - return servicesPanel; - } - - /** - * Display an error message. Usually used each time an error happens. - * - * @param title The title of the error. - * @param message The message of the error. - */ - public void displayError(String title, String message) { - JOptionPane.showMessageDialog(this, message, title, - JOptionPane.ERROR_MESSAGE); - } - -} diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/GUIDim.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/GUIDim.java new file mode 100644 index 0000000..a272645 --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/GUIDim.java @@ -0,0 +1,54 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.gui.mainpanel; + +/** + * A simple class containing GUI panel and elements dimensions. + * + * @author N. Jourdane + */ +public class GUIDim { + + /** The width of the left panel (services view). */ + public static final int LEFT_PANEL_WIDTH = 550; + + /** The minimum width of the left panel (services view). */ + public static final int LEFT_PANEL_MIN_WIDTH = 300; + + /** The width of the right panel (request view). */ + public static final int RIGHT_PANEL_WIDTH = 450; + + /** The minimum width of the right panel (request view). */ + public static final int RIGHT_PANEL_MIN_WIDTH = 220; + + /** The height of the top panel (request view and services view). */ + public static final int TOP_PANEL_HEIGHT = 400; + + /** The minimum height of the top panel (request view and services view). */ + public static final int TOP_PANEL_MIN_HEIGHT = 100; + + /** The height of the bottom panel (result view). */ + public static final int BOTTOM_PANEL_HEIGHT = 150; + + /** The minimum height of the bottom panel (result view). */ + public static final int BOTTOM_PANEL_MIN_HEIGHT = 100; + + + /** Private constructor to hide the implicit public one. */ + private GUIDim() { + } +} 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 new file mode 100644 index 0000000..e1cc29e --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java @@ -0,0 +1,114 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.gui.mainpanel; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.swing.JOptionPane; + +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.CantGetVOTableException; + +/** + * @author N. Jourdane + */ +public class MainPanelCtrl extends EpnTapController { + + /** The logger for the class GUIController. */ + private static final Logger logger = Logger.getLogger(MainPanelCtrl.class.getName()); + + private RequestPanelCtrl requestPanelCtrl; + + private ServicesPanelCtrl servicesPanelCtrl; + + private ResultPanelCtrl resultPanelCtrl; + + private MainPanelView view; + + private int nbMaxResult = 10; + + + public MainPanelCtrl() { + servicesPanelCtrl = new ServicesPanelCtrl(this); + resultPanelCtrl = new ResultPanelCtrl(this); + requestPanelCtrl = new RequestPanelCtrl(this); + view = new MainPanelView(this); + } + + @Override + public void readServices() { + try { + servicesPanelCtrl.readTable(); + } catch (CantGetVOTableException e) { + displayError("Can not get services.", e); + } + view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); + } + + public void sendQuery(String query) { + String serviceURL = servicesPanelCtrl.getSelectedServiceURL(); + logger.info("Sending query: " + query + " on " + serviceURL); + try { + resultPanelCtrl.updateVOTable(serviceURL, query); + view.getResultsPanel().fillTable(resultPanelCtrl.getVOTableData()); + } catch (CantGetVOTableException e) { + displayError("Can not send the query.", e); + MainPanelCtrl.logger.log(Level.WARNING, "Can not send query.", e); + } + } + + public RequestPanelCtrl getRequestPanelCtrl() { + return requestPanelCtrl; + } + + public ServicesPanelCtrl getServicePanelCtrl() { + return servicesPanelCtrl; + } + + public ResultPanelCtrl getResultPanelCtrl() { + return resultPanelCtrl; + } + + public MainPanelView getView() { + return view; + } + + @Override + public void displayError(String message, Exception e) { + logger.log(Level.SEVERE, message, e); + JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); + } + + /** + * @return the nb max of result + */ + public int getNbMaxResult() { + return nbMaxResult; + } + + /** + * set the nb max of result for a query + */ + public void setNbMaxResult(int nb) { + nbMaxResult = nb; + } + +} 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 new file mode 100644 index 0000000..46b360f --- /dev/null +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java @@ -0,0 +1,131 @@ +/* + * This file is a part of EpnTAPClient. + * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer. + * See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861 + * Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie. + * + * This program is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at your option) any later + * version. This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. You should have received a copy of + * the GNU General Public License along with this program. If not, see + * . + */ + +package eu.omp.irap.vespa.epntapclient.gui.mainpanel; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSplitPane; + +import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelView; +import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelView; +import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelView; + +/** + * The main view of the application, which manage all the other views. + * + * @author N. Jourdane + */ +public class MainPanelView extends JPanel { + + /** The serial version UID. */ + private static final long serialVersionUID = 1L; + + /** The JPanel where the VOTable results is displayed. */ + private ResultPanelView resultPanel; + + /** The JPanel where the list of services is displayed. */ + private ServicesPanelView servicesPanel; + + /** The JPanel where the user build the query. */ + private RequestPanelView requestPanel; + + + /** + * The main view constructor, which create all the panels. + * + * @param voTableServicesView The view to put in the services panel, built by ServicesController + * @param voTableResultsView The view to put in the results panel, built by ResultsController. + */ + + public MainPanelView(MainPanelCtrl mainPanelCtrl) { + servicesPanel = mainPanelCtrl.getServicePanelCtrl().getView(); + resultPanel = mainPanelCtrl.getResultPanelCtrl().getView(); + requestPanel = mainPanelCtrl.getRequestPanelCtrl().getView(); + buildMainView(); + } + + /** + * Build and fill the GUI. + */ + private void buildMainView() { + setLayout(new BorderLayout()); + + JSplitPane northPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, servicesPanel, + requestPanel); + JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, northPanel, resultPanel); + + add(mainPanel, BorderLayout.CENTER); + + revalidate(); + setSizes(); + } + + private void setSizes() { + servicesPanel.setPreferredSize( + new Dimension(GUIDim.LEFT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT)); + servicesPanel.setMinimumSize( + new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT)); + + requestPanel.setPreferredSize( + new Dimension(GUIDim.RIGHT_PANEL_WIDTH, GUIDim.TOP_PANEL_HEIGHT)); + requestPanel.setMinimumSize( + new Dimension(GUIDim.RIGHT_PANEL_MIN_WIDTH, GUIDim.TOP_PANEL_MIN_HEIGHT)); + + resultPanel.setPreferredSize( + new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH + GUIDim.RIGHT_PANEL_MIN_WIDTH, + GUIDim.BOTTOM_PANEL_HEIGHT)); + resultPanel.setMinimumSize( + new Dimension(GUIDim.LEFT_PANEL_MIN_WIDTH + GUIDim.RIGHT_PANEL_MIN_WIDTH, + GUIDim.BOTTOM_PANEL_MIN_HEIGHT)); + } + + /** + * @return The JPanel where the VOTable result is displayed. + */ + public ResultPanelView getResultsPanel() { + return resultPanel; + } + + /** + * @return The JPanel containing the GUI elements to build the query. + */ + public RequestPanelView getRequestPanel() { + return requestPanel; + } + + /** + * @return The JPanel where the list of services is displayed. + */ + public ServicesPanelView getServicesPanel() { + return servicesPanel; + } + + /** + * Display an error message. Usually used each time an error happens. + * + * @param title The title of the error. + * @param message The message of the error. + */ + public void displayError(String title, String message) { + JOptionPane.showMessageDialog(this, message, title, + JOptionPane.ERROR_MESSAGE); + } + +} 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 12f6ed3..8aad52a 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 @@ -19,7 +19,7 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel; import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.RequestCtrl; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; import eu.omp.irap.vespa.epntapclient.service.Queries; /** @@ -54,11 +54,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene return view; } - /* - * @see - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onSendButtonClicked(java - * .lang.String) - */ @Override public void onSendButtonClicked(String query) { mainPanelCtrl.sendQuery(query); @@ -73,18 +68,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene view.updateQueryArea(query); } - /** - * Update the query area with a working ADQL query, based on the parameters list. - */ - // private void updateQueryArea() { - // mainPanelCtrl.updateQueryArea(); - // } - - /* - * @see - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onParameterRemoved(java. - * lang.String) - */ @Override public void onParameterRemoved(String paramName) { removeParameter(paramName); @@ -92,11 +75,6 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene logger.info("removed " + paramName); } - /* - * @see - * eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelListener#onParameterChanged(java. - * lang.String, java.lang.Object) - */ @Override public void onParameterChanged(String paramName, Object paramValue) { updateParameter(paramName, paramValue); 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 d7e5b0e..4ac7e56 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 @@ -17,7 +17,6 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield; import java.awt.Dimension; -import java.io.File; import java.util.logging.Level; import javax.swing.JComboBox; @@ -54,6 +53,39 @@ public class TargetNameField extends ParamField implements TextFieldListener { */ String lastContent; + /** + * This method is called each time the field is modified. A Runnable is used it is impossible to + * modify the comboBox from a DocumentEvent. + */ + Runnable updateComboBox = new Runnable() { + + @Override + public void run() { + String content = field.getText(); + if (!content.equals(lastContent)) { + if (content.length() >= 2) { + lastContent = content; + comboBox.removeAllItems(); + try { + for (String s : RequestCtrl.getTargetNames(content)) { + comboBox.addItem(s); + } + } catch (CantSendQueryException e) { + ParamField.logger.log(Level.WARNING, + "Can't get table names for the resolver", e); + } + comboBox.getEditor().setItem(content); + comboBox.showPopup(); + } + if (content.isEmpty()) { + requestPanelListener.onParameterRemoved(paramName); + } else { + requestPanelListener.onParameterChanged(paramName, content); + } + } + } + }; + /** * Method constructor @@ -74,26 +106,16 @@ public class TargetNameField extends ParamField implements TextFieldListener { } public TargetNameField(String paraName) { + // @noformat this(new RequestPanelListener() { - - public void onServiceSelected(int selectedService) { - } - @Override - public void onSendButtonClicked(String query) { - } - + public void onSendButtonClicked(String query) {/** no SendButtonClicked event, we just want the field */} @Override - public void onParameterRemoved(String paramName) { - } - + public void onParameterRemoved(String paramName) {/** no ParameterRemoved event, we just want the field */} @Override - public void onParameterChanged(String paramName, Object paramValue) { - } - - public void onDownloadButtonClicked(File outputFile) { - } + public void onParameterChanged(String paramName, Object paramValue) {/** no ParameterChanged event, we just want the field */} }, paraName); + // @format } /** @@ -104,37 +126,4 @@ public class TargetNameField extends ParamField implements TextFieldListener { SwingUtilities.invokeLater(updateComboBox); } - - /** - * This method is called each time the field is modified. A Runnable is used it is impossible to - * modify the comboBox from a DocumentEvent. - */ - Runnable updateComboBox = new Runnable() { - - @Override - public void run() { - String content = field.getText(); - if (!content.equals(lastContent)) { - if (content.length() >= 2) { - lastContent = content; - comboBox.removeAllItems(); - try { - for (String s : RequestCtrl.getTargetNames(content)) { - comboBox.addItem(s); - } - } catch (CantSendQueryException e) { - ParamField.logger.log(Level.WARNING, - "Can't get table names for the resolver", e); - } - comboBox.getEditor().setItem(content); - comboBox.showPopup(); - } - if (content.isEmpty()) { - requestPanelListener.onParameterRemoved(paramName); - } else { - requestPanelListener.onParameterChanged(paramName, content); - } - } - } - }; } \ No newline at end of file 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 40127a5..8000681 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 @@ -23,7 +23,7 @@ import java.nio.file.Paths; import java.util.logging.Level; import java.util.logging.Logger; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; import eu.omp.irap.vespa.votable.controller.VOTableController; /** @@ -44,11 +44,6 @@ public class ResultPanelCtrl extends VOTableController implements ResultPanelLis view = new ResultPanelView(this); } - /* - * @see - * eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelListener#onDownloadButtonClicked( - * java.io.File) - */ @Override public void onDownloadButtonClicked(File file) { try { 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 e264b9d..f50f874 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 @@ -18,7 +18,7 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; import java.util.logging.Logger; -import eu.omp.irap.vespa.epntapclient.gui.mainPanel.MainPanelCtrl; +import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; import eu.omp.irap.vespa.epntapclient.service.Queries; import eu.omp.irap.vespa.epntapclient.service.ServiceCore; import eu.omp.irap.vespa.votable.Consts; diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java index 165e196..d342376 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java @@ -28,8 +28,8 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; * @author N. Jourdane */ public final class Queries { - - public static String RETURN_PARAMETERS = "target_name, target_class"; + + public static final String RETURN_PARAMETERS = "target_name, target_class"; private static final String SELECT = "SELECT DISTINCT short_name, res_title, " + "table_name, schema_name, ivoid, access_url "; @@ -115,7 +115,7 @@ public final class Queries { } } String where = addJoin.isEmpty() ? "" : " WHERE " + addJoin; - + return "SELECT TOP " + nbRow + " " + RETURN_PARAMETERS + " " diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java index 39f0b77..717324a 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java @@ -20,7 +20,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import javax.xml.datatype.XMLGregorianCalendar; @@ -42,13 +41,13 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableDataParser; */ public class ServiceCtrl { - /** The logger for the class ServiceCtrl. */ - private static final Logger logger = Logger.getLogger(ServiceCtrl.class.getName()); - public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; - public final static Service getService(Resource resource) { + private ServiceCtrl() { + } + + public static final Service getService(Resource resource) { Service service = new Service(resource.getIdentifier()); service.setTitle(resource.getTitle()); service.setShortName(resource.getShortName()); @@ -70,8 +69,8 @@ public class ServiceCtrl { service.setContentLevel(contentLevels.toString()); service.setReferenceURL(resource.getContent().getReferenceURL()); - service.setCreated(ServiceCtrl.XMLDateToString(resource.getCreated())); - service.setUpdated(ServiceCtrl.XMLDateToString(resource.getUpdated())); + service.setCreated(ServiceCtrl.xmlDateToString(resource.getCreated())); + service.setUpdated(ServiceCtrl.xmlDateToString(resource.getUpdated())); return service; } @@ -130,7 +129,7 @@ public class ServiceCtrl { return getVoTableData(query).getCell(0, 0); } - private static String XMLDateToString(XMLGregorianCalendar date) { + private static String xmlDateToString(XMLGregorianCalendar date) { SimpleDateFormat sdf = new SimpleDateFormat(ServiceCtrl.DATE_FORMAT); return sdf.format(date.toGregorianCalendar().getTime()); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java index ac83c0c..8498186 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java @@ -67,11 +67,14 @@ public class VOResourceCtrl { private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; + private VOResourceCtrl() { + } + public static List getVOResources(ServiceCore type) throws VOResourceException { List ivoidResources; Map parameters = new HashMap(); - parameters.put("keywords", "datamodel:\"EpnCore\""); + parameters.put("keywords", "datamodel:\"" + type.toString() + "\""); parameters.put("max", String.valueOf(MAX_VORESOURCES)); String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); try { @@ -88,7 +91,8 @@ public class VOResourceCtrl { List ivoidResources; Map parameters = new HashMap(); String subjects = StringJoiner.join(keywords); - parameters.put("keywords", "datamodel:\"EpnCore\" subjects:\"" + subjects + "\""); + parameters.put("keywords", + "datamodel:\"" + type.toString() + "\" subjects:\"" + subjects + "\""); parameters.put("max", String.valueOf(MAX_VORESOURCES)); String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters); @@ -130,7 +134,6 @@ public class VOResourceCtrl { Unmarshaller unmarshaller = jc.createUnmarshaller(); voResource = unmarshaller.unmarshal(source, Resource.class).getValue(); - // erreur sur : o = unmarshaller.unmarshal(f); } catch (JAXBException e) { throw new VOResourceIsNotValidException(voResourcePath, e); } -- libgit2 0.21.2