/*
 * 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.gui.resultpanel;

import java.util.List;

import eu.omp.irap.vespa.epntapclient.epntap.service.ServicesList;
import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener;
import eu.omp.irap.vespa.votable.gui.VOTablePanelView;

/**
 * @author N. Jourdane
 */
public class ResultsPanelCtrl {

	/** The listener of the main panel. */
	private MainPanelListener listener;

	/** The result panel view. */
	private ResultsPanelView view;


	/**
	 * Constructor of ResultsPanelCtrl.
	 *
	 * @param listener The listener of the main panel.
	 */
	public ResultsPanelCtrl(MainPanelListener listener) {
		this.listener = listener;
		view = new ResultsPanelView();
	}

	/** @return The path of the VOTable related to the focused table. */
	public String getFocusedVOTablePath() {
		return ((VOTablePanelView) view.getSelectedComponent()).getVOTablePath();
	}

	/** @return The view of the results panel. */
	public ResultsPanelView getView() {
		return view;
	}

	/**
	 * Send a list of queries to the corresponding services.
	 * 
	 * @param services The services targeted to send the queries
	 * @param queries The queries to send, in the same order that the list of services.
	 */
	public void sendQueries(ServicesList services, List<String> queries) {
		for (int i = 0; i < queries.size(); i++) {
			String title = services.getTableNames().get(i).split("\\.")[0];
			ResultTabCtrl resultCtrl = new ResultTabCtrl(listener, view, title);
			resultCtrl.acquireVOTable(services.getTargetUrls().get(i), queries.get(i));
		}
	}
}
