diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java index 298be92..5fb0cf8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java @@ -16,8 +16,11 @@ package eu.omp.irap.vespa.epntapclient.controller; +import eu.omp.irap.vespa.epntapclient.utils.Const; +import eu.omp.irap.vespa.epntapclient.utils.Queries; import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; /** * @author N. Jourdane @@ -36,15 +39,16 @@ public class EpnTapController { * Method constructor */ public EpnTapController() { - view = new EpnTapMainView(); + servicesController = new VOTableController(Const.DEFAULT_REGISTRY_URL, "ADQL", + Queries.GET_TAP_SERVICES); - String[] sColumns = { "service name", "service value" }; - String[][] sValues = { { "s1", "s2" }, { "789", "357" } }; + VOTableView serviceView = servicesController.getView(); + + view = new EpnTapMainView(this, serviceView); String[] rColumns = { "result name", "result value" }; String[][] rValues = { { "r1", "r2" }, { "123", "456" } }; - view.fillServices(sColumns, sValues); view.fillResults(rColumns, rValues); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java index 57b2b2b..2606453 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java @@ -22,6 +22,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; +import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; /** @@ -33,20 +34,23 @@ public class EpnTapMainView extends JPanel { private static final long serialVersionUID = -1233290271099283814L; /** The JPanel where the VOTable results is displayed. */ - private VOTableView results; + private VOTableView resultsView; /** The JPanel where the list of services is displayed. */ - private VOTableView services; + private VOTableView servicesView; /** The text area where the user put its requests. */ private JTextArea queryArea; /** * The constructor of the view. + * + * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events. + * @param servicesView The JPanel representing the table of services. */ - public EpnTapMainView() { - services = new VOTableView(); - results = new VOTableView(); + public EpnTapMainView(EpnTapController controller, VOTableView servicesView) { + this.servicesView = servicesView; + resultsView = new VOTableView(controller.getResultsController()); queryArea = new JTextArea(""); buildWindow(); @@ -58,7 +62,7 @@ public class EpnTapMainView extends JPanel { * table. The second one represents each element, in the same order as the `columns`. */ public void fillServices(String[] columns, Object[][] values) { - services.buildArray(columns, values); + servicesView.buildArray(columns, values); } /** @@ -67,21 +71,21 @@ public class EpnTapMainView extends JPanel { * The second one represents each element, in the same order as the `columns`. */ public void fillResults(String[] columns, Object[][] values) { - results.buildArray(columns, values); + resultsView.buildArray(columns, values); } /** * @return The JPanel where the VOTable results is displayed. */ public VOTableView getResults() { - return results; + return resultsView; } /** * @return The JPanel where the list of services is displayed. */ public VOTableView getServices() { - return services; + return servicesView; } /** @@ -89,12 +93,12 @@ public class EpnTapMainView extends JPanel { */ public void buildWindow() { JPanel northPanel = new JPanel(new BorderLayout()); - northPanel.add(services, BorderLayout.WEST); + northPanel.add(servicesView, BorderLayout.WEST); northPanel.add(queryArea, BorderLayout.CENTER); setLayout(new BorderLayout()); add(northPanel, BorderLayout.NORTH); - add(results, BorderLayout.CENTER); + add(resultsView, BorderLayout.CENTER); } /** diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java index e6e0c3b..cd7cb80 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java @@ -16,6 +16,7 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; +import eu.omp.irap.vespa.epntapclient.utils.Log; import eu.omp.irap.vespa.epntapclient.votable.model.Table; import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; @@ -31,13 +32,21 @@ public class VOTableController { /** The VOTable model */ VOTABLE voTable; + /** The table column selected by the user. */ + int selectedColumn; + + /** The table row selected by the user. */ + int selectedRow; + /** * Method constructor * * @param voTablePath The path of the VOTable XML file. */ public VOTableController(String voTablePath) { - view = new VOTableView(); + view = new VOTableView(this); + selectedColumn = -1; + selectedRow = -1; try { voTable = VOTableParser.parseVOTable(voTablePath); @@ -51,17 +60,15 @@ public class VOTableController { * Method constructor * * @param targetURL The url of the registry to communicate (ie. "http://reg.g-vo.org"). - * @param serviceType The type of service (ie. "tap"). * @param queryLanguage The language used for the queries (ie. "ADQL"). * @param query The query to ask to the registry. */ - public VOTableController(String targetURL, String serviceType, String queryLanguage, - String query) { - view = new VOTableView(); + public VOTableController(String targetURL, String queryLanguage, String query) { + view = new VOTableView(this); String voTablePath; try { - voTablePath = VOTableConnection.sendQuery(targetURL, serviceType, queryLanguage, + voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage, query); voTable = VOTableParser.parseVOTable(voTablePath); fillView(); @@ -95,4 +102,12 @@ public class VOTableController { public VOTableView getView() { return view; } + + /** + * @param selectedColumn The table column selected by the user. + * @param selectedRow The table row selected by the user. + */ + public void updateSelection(int selectedColumn, int selectedRow) { + Log.LOGGER.info("Selection updated: [" + selectedColumn + " ; " + selectedRow + "]"); + } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java index 06c3115..6d82db4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java @@ -17,6 +17,12 @@ package eu.omp.irap.vespa.epntapclient.votable.view; import java.awt.BorderLayout; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.List; import javax.swing.JOptionPane; @@ -25,6 +31,8 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ScrollPaneConstants; +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; + /** * The main class of the View of the application. * @@ -35,6 +43,21 @@ public class VOTableView extends JPanel { /** The serial version UID (affected with a random number). */ private static final long serialVersionUID = -1233290271099283814L; + /** The VOTable controller, allowing the view to send events. */ + private VOTableController controller; + + /** The JTable component where the data are displayed. */ + private JTable table; + + /** + * Method constructor + * + * @param controller The VOTable controller, allowing the view to send events. + */ + public VOTableView(VOTableController controller) { + this.controller = controller; + } + /** * Build and fill the GUI. * @@ -55,7 +78,24 @@ public class VOTableView extends JPanel { * The second one represents each element, in the same order as `keys`. */ public void buildArray(String[] keys, Object[][] values) { - JTable table = new JTable(values, keys); + table = new JTable(values, keys); + + // TODO: support multi-selection + KeyListener tableKeyListener = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + updateSelection(); + } + }; + MouseListener tableMouseListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + updateSelection(); + } + }; + + table.addKeyListener(tableKeyListener); + table.addMouseListener(tableMouseListener); JScrollPane scrollPane = new JScrollPane(table); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); @@ -66,6 +106,13 @@ public class VOTableView extends JPanel { } /** + * This method is called on keyPressed and mouseClicked events on the JTable. + */ + void updateSelection() { + controller.updateSelection(table.getSelectedColumn(), table.getSelectedRow()); + } + + /** * Display an error. * * @param title The title of the error. -- libgit2 0.21.2