Blame view

src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java 3.89 KB
1353e182   Nathanael Jourdane   Add minimal eleme...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * 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
 * <http://www.gnu.org/licenses/>.
 */

package eu.omp.irap.vespa.epntapclient.controller;

5799764b   Nathanael Jourdane   Use Log4j2 instea...
19
20
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
7706bfa4   Nathanael Jourdane   Use log4j as logg...
21

6b021d84   Nathanael Jourdane   VOTable view can ...
22
import eu.omp.irap.vespa.epntapclient.utils.Const;
6b021d84   Nathanael Jourdane   VOTable view can ...
23
import eu.omp.irap.vespa.epntapclient.utils.Queries;
1353e182   Nathanael Jourdane   Add minimal eleme...
24
25
import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
4dd68979   Nathanael Jourdane   Improve Exception...
26
import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException;
6b021d84   Nathanael Jourdane   VOTable view can ...
27
import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
1353e182   Nathanael Jourdane   Add minimal eleme...
28
29
30
31
32

/**
 * @author N. Jourdane
 */
public class EpnTapController {
7706bfa4   Nathanael Jourdane   Use log4j as logg...
33
	/** The logger for this class. */
5799764b   Nathanael Jourdane   Use Log4j2 instea...
34
	private static final Logger logger = LogManager.getLogger(EpnTapController.class);
7706bfa4   Nathanael Jourdane   Use log4j as logg...
35

1353e182   Nathanael Jourdane   Add minimal eleme...
36
37
38
	/** The view of EPN-TAP application. */
	EpnTapMainView view;

4cc84b63   Nathanael Jourdane   Add the possibili...
39
40
41
	/** The controller of the VOTable displaying the list of services. */
	VOTableController servicesController;

1353e182   Nathanael Jourdane   Add minimal eleme...
42
43
44
	/** The controller of the VOTable displaying the query results. */
	VOTableController resultsController;

6415d908   Nathanael Jourdane   Get all tap servi...
45
46
47
48
49
	/** The name of the table selected by the user on the table list panel. */
	String selectedTableName;

	/** The URL of the service corresponding to the selected table. */
	String selectedTableServiceURL;
1353e182   Nathanael Jourdane   Add minimal eleme...
50
51
52
53
54

	/**
	 * Method constructor
	 */
	public EpnTapController() {
a7aff3e3   Nathanael Jourdane   Fix Sonar issues
55

4cc84b63   Nathanael Jourdane   Add the possibili...
56
		// TODO: Get only *EPN* TAP services
6b021d84   Nathanael Jourdane   VOTable view can ...
57
		servicesController = new VOTableController(Const.DEFAULT_REGISTRY_URL, "ADQL",
8a39b260   Nathanael Jourdane   Get only EPN-core...
58
				Queries.GET_EPN_TAP_SERVICES);
43c14591   Nathanael Jourdane   View: Add methods...
59

4cc84b63   Nathanael Jourdane   Add the possibili...
60
		resultsController = new VOTableController();
43c14591   Nathanael Jourdane   View: Add methods...
61

4cc84b63   Nathanael Jourdane   Add the possibili...
62
63
64
		VOTableView serviceView = servicesController.getView();
		VOTableView resultsView = resultsController.getView();
		view = new EpnTapMainView(this, serviceView, resultsView);
6415d908   Nathanael Jourdane   Get all tap servi...
65
		updateSelected(0);
1353e182   Nathanael Jourdane   Add minimal eleme...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
	}

	/**
	 * @return the EPN-TAP view.
	 */
	public EpnTapMainView getView() {
		return view;
	}

	/**
	 * @return The controller of the VOTable displaying the query results.
	 */
	public VOTableController getResultsController() {
		return resultsController;
	}

	/**
	 * @return The controller of the VOTable displaying the list of services.
	 */
	public VOTableController getServicesController() {
		return servicesController;
	}
4cc84b63   Nathanael Jourdane   Add the possibili...
88
89
90
91

	/**
	 * @param row The row selected by the user on the Jtable.
	 */
6415d908   Nathanael Jourdane   Get all tap servi...
92
93
94
95
96
97
	public void updateSelected(int row) {
		String serviceURL = (String) view.getServicesView().getValueAt(5, row);
		String tableName = (String) view.getServicesView().getValueAt(2, row);
		if (!tableName.equals(selectedTableName)) {
			selectedTableServiceURL = serviceURL;
			selectedTableName = tableName;
0b616d80   Nathanael Jourdane   Updtate the query...
98
			view.getRequestView().updateQueryArea();
6415d908   Nathanael Jourdane   Get all tap servi...
99
100
			logger.info("Selected table: " + selectedTableName + " - service: "
					+ selectedTableServiceURL);
4cc84b63   Nathanael Jourdane   Add the possibili...
101
102
103
		}
	}

6415d908   Nathanael Jourdane   Get all tap servi...
104
105
106
107
	public String getSelectedTable() {
		return selectedTableName;
	}

4cc84b63   Nathanael Jourdane   Add the possibili...
108
109
	/**
	 * @param query The query to send to the selected service.
4dd68979   Nathanael Jourdane   Improve Exception...
110
	 * @throws VOTableException Can not fill the Table
4cc84b63   Nathanael Jourdane   Add the possibili...
111
	 */
4dd68979   Nathanael Jourdane   Improve Exception...
112
	public void sendQuery(String query) throws VOTableException {
6415d908   Nathanael Jourdane   Get all tap servi...
113
114
		logger.info("Sending query: " + query + " on " + selectedTableServiceURL);
		resultsController.fillTable(selectedTableServiceURL, "ADQL", query);
4cc84b63   Nathanael Jourdane   Add the possibili...
115
	}
1353e182   Nathanael Jourdane   Add minimal eleme...
116
}