Commit 26c7a6bfa287c3ebaa8eb08421f195ee0bc8edc4

Authored by Nathanael Jourdane
1 parent 8db758c4
Exists in master

VOTable: Code restructuration in order that the controller do not need the view.

src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java
@@ -26,6 +26,7 @@ import com.google.gson.Gson; @@ -26,6 +26,7 @@ import com.google.gson.Gson;
26 26
27 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; 27 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
28 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; 28 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException;
  29 +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
29 30
30 /** 31 /**
31 * Simple class to have a main function to display a voTable from a XML file. 32 * Simple class to have a main function to display a voTable from a XML file.
@@ -37,6 +38,9 @@ public class VOTableApp { @@ -37,6 +38,9 @@ public class VOTableApp {
37 /** The logger for the class VOTableApp. */ 38 /** The logger for the class VOTableApp. */
38 protected static final Logger logger = Logger.getLogger(VOTableApp.class.getName()); 39 protected static final Logger logger = Logger.getLogger(VOTableApp.class.getName());
39 40
  41 + private static final String WRONG_COMMAND = "Usage: VOtableApp path/to/VOTable.xml\n"
  42 + + "OR: VOtableApp http://url.to.service/or/registry type language \"YOUR QUERY\"";
  43 +
40 44
41 /** Private constructor to hide the implicit public one. */ 45 /** Private constructor to hide the implicit public one. */
42 private VOTableApp() { 46 private VOTableApp() {
@@ -49,34 +53,42 @@ public class VOTableApp { @@ -49,34 +53,42 @@ public class VOTableApp {
49 */ 53 */
50 public static void main(final String[] args) { 54 public static void main(final String[] args) {
51 VOTableApp.logger.info("Lauching VOTable app with arguments: " + new Gson().toJson(args)); 55 VOTableApp.logger.info("Lauching VOTable app with arguments: " + new Gson().toJson(args));
52 - SwingUtilities.invokeLater(new Runnable() { 56 + VOTableController ctrl;
  57 +
  58 + if (args.length == 1) {
  59 + ctrl = new VOTableController(args[0]);
  60 + } else if (args.length == 3) {
  61 + ctrl = new VOTableController(args[0], args[1], args[2]);
  62 + } else {
  63 + System.console().writer().println(VOTableApp.WRONG_COMMAND);
  64 + return;
  65 + }
  66 +
  67 + try {
  68 + ctrl.readTable();
  69 + } catch (VOTableException e) {
  70 + System.console().writer().println("Error: " + e.getMessage());
  71 + VOTableApp.logger.log(Level.WARNING, e.getMessage(), e);
  72 + return;
  73 + }
  74 +
  75 + VOTableView view = new VOTableView();
  76 + view.fillTable(ctrl.getColumns(), ctrl.getData());
  77 + SwingUtilities.invokeLater(VOTableApp.run(view, args[0]));
  78 + }
  79 +
  80 + private static Runnable run(final VOTableView voTableView, final String title) {
  81 + return new Runnable() {
53 82
54 @Override 83 @Override
55 public void run() { 84 public void run() {
56 - VOTableController voTableControl;  
57 - if (args.length == 1) {  
58 - try {  
59 - voTableControl = new VOTableController(args[0]);  
60 - } catch (VOTableException e) {  
61 - System.console().writer().println("Error: " + e.getMessage());  
62 - VOTableApp.logger.log(Level.WARNING, e.getMessage(), e);  
63 - return;  
64 - }  
65 - } else if (args.length == 3) {  
66 - voTableControl = new VOTableController(args[0], args[1], args[2]);  
67 - } else {  
68 - System.console().writer().println("Usage: VOtableApp path/to/VOTable.xml\n"  
69 - + "OR: VOtableApp http://url.to.service/or/registry type language \"YOUR QUERY\"");  
70 - return;  
71 - }  
72 -  
73 - JFrame frame = new JFrame(args[0]); 85 + JFrame frame = new JFrame(title);
74 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 86 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
75 - frame.setContentPane(voTableControl.getView()); 87 + frame.setContentPane(voTableView);
76 frame.setVisible(true); 88 frame.setVisible(true);
77 frame.setSize(800, 600); 89 frame.setSize(800, 600);
78 frame.setLocationRelativeTo(null); 90 frame.setLocationRelativeTo(null);
79 } 91 }
80 - }); 92 + };
81 } 93 }
82 } 94 }
83 \ No newline at end of file 95 \ No newline at end of file
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 package eu.omp.irap.vespa.epntapclient.votable.controller; 17 package eu.omp.irap.vespa.epntapclient.votable.controller;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
  20 +import java.util.List;
20 import java.util.logging.Logger; 21 import java.util.logging.Logger;
21 22
22 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantDisplayVOTableException; 23 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantDisplayVOTableException;
@@ -27,39 +28,43 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantDi @@ -27,39 +28,43 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantDi
27 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantSendQueryException; 28 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.CantSendQueryException;
28 import eu.omp.irap.vespa.epntapclient.votable.model.Table; 29 import eu.omp.irap.vespa.epntapclient.votable.model.Table;
29 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; 30 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
30 -import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; 31 +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableViewListener;
31 32
32 /** 33 /**
33 * @author N. Jourdane 34 * @author N. Jourdane
34 */ 35 */
35 -public class VOTableController { 36 +public class VOTableController implements VOTableViewListener {
36 37
37 /** The logger for the class VOTableController. */ 38 /** The logger for the class VOTableController. */
38 private static final Logger logger = Logger.getLogger(VOTableController.class.getName()); 39 private static final Logger logger = Logger.getLogger(VOTableController.class.getName());
39 40
40 - /** The view of the VOTable */  
41 - private VOTableView view;  
42 -  
43 /** The VOTable model */ 41 /** The VOTable model */
44 private VOTABLE voTable; 42 private VOTABLE voTable;
45 43
  44 + private String voTablePath;
46 45
47 - /**  
48 - * Method constructor  
49 - */  
50 - public VOTableController() {  
51 - view = new VOTableView(); 46 + private String targetURL;
  47 +
  48 + private String queryLanguage;
  49 +
  50 + private String query;
  51 +
  52 + private String[] voTableColumns;
  53 +
  54 + private List<Object[]> voTableData;
  55 +
  56 +
  57 + /** Private constructor to hide the implicit public one. */
  58 + private VOTableController() {
52 } 59 }
53 60
54 /** 61 /**
55 * Method constructor 62 * Method constructor
56 * 63 *
57 * @param voTablePath The path of the VOTable XML file. 64 * @param voTablePath The path of the VOTable XML file.
58 - * @throws VOTableException If something went wrong on the VOTable view or when filling table.  
59 */ 65 */
60 - public VOTableController(String voTablePath) throws VOTableException {  
61 - view = new VOTableView();  
62 - fillTable(voTablePath); 66 + public VOTableController(String voTablePath) {
  67 + this.voTablePath = voTablePath;
63 } 68 }
64 69
65 /** 70 /**
@@ -70,36 +75,23 @@ public class VOTableController { @@ -70,36 +75,23 @@ public class VOTableController {
70 * @param query The query to ask to the registry. 75 * @param query The query to ask to the registry.
71 */ 76 */
72 public VOTableController(String targetURL, String queryLanguage, String query) { 77 public VOTableController(String targetURL, String queryLanguage, String query) {
73 - view = new VOTableView();  
74 -  
75 - try {  
76 - fillTable(VOTableConnection.sendQuery(targetURL, queryLanguage, query));  
77 - } catch (VOTableException e) {  
78 - VOTableController.logger.info("VOTableController error: " + e);  
79 - }  
80 - }  
81 -  
82 - /**  
83 - * @param targetURL The URL of the registry to communicate (ie. "http://reg.g-vo.org").  
84 - * @param queryLanguage The language used for the queries (ie. "ADQL").  
85 - * @param query The query to ask to the registry.  
86 - * @throws CantSendQueryException If the query can not be sent.  
87 - * @throws CantDisplayVOTableException If the table can not be filled.  
88 - */  
89 - public String fillTable(String targetURL, String queryLanguage, String query)  
90 - throws CantDisplayVOTableException, CantSendQueryException {  
91 - String voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage, query);  
92 - fillTable(voTablePath);  
93 - return voTablePath; 78 + voTablePath = null;
  79 + this.targetURL = targetURL;
  80 + this.queryLanguage = queryLanguage;
  81 + this.query = query;
94 } 82 }
95 83
96 /** 84 /**
97 * @param voTablePath The path of the VOTable file. 85 * @param voTablePath The path of the VOTable file.
98 * @throws CantDisplayVOTableException If the VOTable can not be filled. 86 * @throws CantDisplayVOTableException If the VOTable can not be filled.
  87 + * @throws CantSendQueryException
99 */ 88 */
100 - public void fillTable(String voTablePath)  
101 - throws CantDisplayVOTableException { 89 + // TODO: can't fill table exception
  90 + public void readTable() throws CantDisplayVOTableException, CantSendQueryException {
102 91
  92 + if (voTablePath == null) {
  93 + voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage, query);
  94 + }
103 voTable = VOTableParser.parseVOTable(voTablePath); 95 voTable = VOTableParser.parseVOTable(voTablePath);
104 96
105 if (voTable.getRESOURCE().size() > 1) { 97 if (voTable.getRESOURCE().size() > 1) {
@@ -120,16 +112,22 @@ public class VOTableController { @@ -120,16 +112,22 @@ public class VOTableController {
120 VOTableDataParser dataParser; 112 VOTableDataParser dataParser;
121 try { 113 try {
122 dataParser = new VOTableDataParser(table); 114 dataParser = new VOTableDataParser(table);
123 - view.fillTable(dataParser.getColumnsName(), dataParser.getDataArray()); 115 + voTableColumns = dataParser.getColumnsName();
  116 + voTableData = dataParser.getDataArray();
124 } catch (IOException e) { 117 } catch (IOException e) {
125 throw new CantModifyVOTableException(voTablePath, e); 118 throw new CantModifyVOTableException(voTablePath, e);
126 } 119 }
127 } 120 }
128 121
129 - /**  
130 - * @return The view of the VOTable.  
131 - */  
132 - public VOTableView getView() {  
133 - return view; 122 + public String[] getColumns() {
  123 + return voTableColumns;
  124 + }
  125 +
  126 + public List<Object[]> getData() {
  127 + return voTableData;
  128 + }
  129 +
  130 + public String getVOTablePath() {
  131 + return voTablePath;
134 } 132 }
135 } 133 }
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
@@ -49,6 +49,7 @@ public class VOTableView extends JPanel implements TableModelListener { @@ -49,6 +49,7 @@ public class VOTableView extends JPanel implements TableModelListener {
49 /** 49 /**
50 * Method constructor 50 * Method constructor
51 */ 51 */
  52 + // TODO public VOTableView(VOTableViewListener listener) -> listen for select events
52 public VOTableView() { 53 public VOTableView() {
53 tableData = new DefaultTableModel() { 54 tableData = new DefaultTableModel() {
54 55
@@ -63,7 +64,10 @@ public class VOTableView extends JPanel implements TableModelListener { @@ -63,7 +64,10 @@ public class VOTableView extends JPanel implements TableModelListener {
63 }; 64 };
64 65
65 table = new JTable(tableData); 66 table = new JTable(tableData);
  67 + buildVOTableView();
  68 + }
66 69
  70 + private void buildVOTableView() {
67 JScrollPane scrollPane = new JScrollPane(table); 71 JScrollPane scrollPane = new JScrollPane(table);
68 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); 72 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
69 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); 73 scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableViewListener.java 0 → 100644
@@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
  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.votable.view;
  18 +
  19 +
  20 +/**
  21 + *
  22 + * @author N. Jourdane
  23 + */
  24 +public interface VOTableViewListener {
  25 +
  26 +}