Commit 6b021d8465a1aefc915b718a7577f83ece249224

Authored by Nathanael Jourdane
1 parent 34ddb630
Exists in master

VOTable view can now send events callbacks.

src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
... ... @@ -16,8 +16,11 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.controller;
18 18  
  19 +import eu.omp.irap.vespa.epntapclient.utils.Const;
  20 +import eu.omp.irap.vespa.epntapclient.utils.Queries;
19 21 import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView;
20 22 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
  23 +import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
21 24  
22 25 /**
23 26 * @author N. Jourdane
... ... @@ -36,15 +39,16 @@ public class EpnTapController {
36 39 * Method constructor
37 40 */
38 41 public EpnTapController() {
39   - view = new EpnTapMainView();
  42 + servicesController = new VOTableController(Const.DEFAULT_REGISTRY_URL, "ADQL",
  43 + Queries.GET_TAP_SERVICES);
40 44  
41   - String[] sColumns = { "service name", "service value" };
42   - String[][] sValues = { { "s1", "s2" }, { "789", "357" } };
  45 + VOTableView serviceView = servicesController.getView();
  46 +
  47 + view = new EpnTapMainView(this, serviceView);
43 48  
44 49 String[] rColumns = { "result name", "result value" };
45 50 String[][] rValues = { { "r1", "r2" }, { "123", "456" } };
46 51  
47   - view.fillServices(sColumns, sValues);
48 52 view.fillResults(rColumns, rValues);
49 53 }
50 54  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java
... ... @@ -22,6 +22,7 @@ import javax.swing.JOptionPane;
22 22 import javax.swing.JPanel;
23 23 import javax.swing.JTextArea;
24 24  
  25 +import eu.omp.irap.vespa.epntapclient.controller.EpnTapController;
25 26 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
26 27  
27 28 /**
... ... @@ -33,20 +34,23 @@ public class EpnTapMainView extends JPanel {
33 34 private static final long serialVersionUID = -1233290271099283814L;
34 35  
35 36 /** The JPanel where the VOTable results is displayed. */
36   - private VOTableView results;
  37 + private VOTableView resultsView;
37 38  
38 39 /** The JPanel where the list of services is displayed. */
39   - private VOTableView services;
  40 + private VOTableView servicesView;
40 41  
41 42 /** The text area where the user put its requests. */
42 43 private JTextArea queryArea;
43 44  
44 45 /**
45 46 * The constructor of the view.
  47 + *
  48 + * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events.
  49 + * @param servicesView The JPanel representing the table of services.
46 50 */
47   - public EpnTapMainView() {
48   - services = new VOTableView();
49   - results = new VOTableView();
  51 + public EpnTapMainView(EpnTapController controller, VOTableView servicesView) {
  52 + this.servicesView = servicesView;
  53 + resultsView = new VOTableView(controller.getResultsController());
50 54 queryArea = new JTextArea("");
51 55  
52 56 buildWindow();
... ... @@ -58,7 +62,7 @@ public class EpnTapMainView extends JPanel {
58 62 * table. The second one represents each element, in the same order as the `columns`.
59 63 */
60 64 public void fillServices(String[] columns, Object[][] values) {
61   - services.buildArray(columns, values);
  65 + servicesView.buildArray(columns, values);
62 66 }
63 67  
64 68 /**
... ... @@ -67,21 +71,21 @@ public class EpnTapMainView extends JPanel {
67 71 * The second one represents each element, in the same order as the `columns`.
68 72 */
69 73 public void fillResults(String[] columns, Object[][] values) {
70   - results.buildArray(columns, values);
  74 + resultsView.buildArray(columns, values);
71 75 }
72 76  
73 77 /**
74 78 * @return The JPanel where the VOTable results is displayed.
75 79 */
76 80 public VOTableView getResults() {
77   - return results;
  81 + return resultsView;
78 82 }
79 83  
80 84 /**
81 85 * @return The JPanel where the list of services is displayed.
82 86 */
83 87 public VOTableView getServices() {
84   - return services;
  88 + return servicesView;
85 89 }
86 90  
87 91 /**
... ... @@ -89,12 +93,12 @@ public class EpnTapMainView extends JPanel {
89 93 */
90 94 public void buildWindow() {
91 95 JPanel northPanel = new JPanel(new BorderLayout());
92   - northPanel.add(services, BorderLayout.WEST);
  96 + northPanel.add(servicesView, BorderLayout.WEST);
93 97 northPanel.add(queryArea, BorderLayout.CENTER);
94 98  
95 99 setLayout(new BorderLayout());
96 100 add(northPanel, BorderLayout.NORTH);
97   - add(results, BorderLayout.CENTER);
  101 + add(resultsView, BorderLayout.CENTER);
98 102 }
99 103  
100 104 /**
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
... ... @@ -16,6 +16,7 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.votable.controller;
18 18  
  19 +import eu.omp.irap.vespa.epntapclient.utils.Log;
19 20 import eu.omp.irap.vespa.epntapclient.votable.model.Table;
20 21 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
21 22 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
... ... @@ -31,13 +32,21 @@ public class VOTableController {
31 32 /** The VOTable model */
32 33 VOTABLE voTable;
33 34  
  35 + /** The table column selected by the user. */
  36 + int selectedColumn;
  37 +
  38 + /** The table row selected by the user. */
  39 + int selectedRow;
  40 +
34 41 /**
35 42 * Method constructor
36 43 *
37 44 * @param voTablePath The path of the VOTable XML file.
38 45 */
39 46 public VOTableController(String voTablePath) {
40   - view = new VOTableView();
  47 + view = new VOTableView(this);
  48 + selectedColumn = -1;
  49 + selectedRow = -1;
41 50  
42 51 try {
43 52 voTable = VOTableParser.parseVOTable(voTablePath);
... ... @@ -51,17 +60,15 @@ public class VOTableController {
51 60 * Method constructor
52 61 *
53 62 * @param targetURL The url of the registry to communicate (ie. "http://reg.g-vo.org").
54   - * @param serviceType The type of service (ie. "tap").
55 63 * @param queryLanguage The language used for the queries (ie. "ADQL").
56 64 * @param query The query to ask to the registry.
57 65 */
58   - public VOTableController(String targetURL, String serviceType, String queryLanguage,
59   - String query) {
60   - view = new VOTableView();
  66 + public VOTableController(String targetURL, String queryLanguage, String query) {
  67 + view = new VOTableView(this);
61 68 String voTablePath;
62 69  
63 70 try {
64   - voTablePath = VOTableConnection.sendQuery(targetURL, serviceType, queryLanguage,
  71 + voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage,
65 72 query);
66 73 voTable = VOTableParser.parseVOTable(voTablePath);
67 74 fillView();
... ... @@ -95,4 +102,12 @@ public class VOTableController {
95 102 public VOTableView getView() {
96 103 return view;
97 104 }
  105 +
  106 + /**
  107 + * @param selectedColumn The table column selected by the user.
  108 + * @param selectedRow The table row selected by the user.
  109 + */
  110 + public void updateSelection(int selectedColumn, int selectedRow) {
  111 + Log.LOGGER.info("Selection updated: [" + selectedColumn + " ; " + selectedRow + "]");
  112 + }
98 113 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
... ... @@ -17,6 +17,12 @@
17 17 package eu.omp.irap.vespa.epntapclient.votable.view;
18 18  
19 19 import java.awt.BorderLayout;
  20 +import java.awt.event.KeyAdapter;
  21 +import java.awt.event.KeyEvent;
  22 +import java.awt.event.KeyListener;
  23 +import java.awt.event.MouseAdapter;
  24 +import java.awt.event.MouseEvent;
  25 +import java.awt.event.MouseListener;
20 26 import java.util.List;
21 27  
22 28 import javax.swing.JOptionPane;
... ... @@ -25,6 +31,8 @@ import javax.swing.JScrollPane;
25 31 import javax.swing.JTable;
26 32 import javax.swing.ScrollPaneConstants;
27 33  
  34 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController;
  35 +
28 36 /**
29 37 * The main class of the View of the application.
30 38 *
... ... @@ -35,6 +43,21 @@ public class VOTableView extends JPanel {
35 43 /** The serial version UID (affected with a random number). */
36 44 private static final long serialVersionUID = -1233290271099283814L;
37 45  
  46 + /** The VOTable controller, allowing the view to send events. */
  47 + private VOTableController controller;
  48 +
  49 + /** The JTable component where the data are displayed. */
  50 + private JTable table;
  51 +
  52 + /**
  53 + * Method constructor
  54 + *
  55 + * @param controller The VOTable controller, allowing the view to send events.
  56 + */
  57 + public VOTableView(VOTableController controller) {
  58 + this.controller = controller;
  59 + }
  60 +
38 61 /**
39 62 * Build and fill the GUI.
40 63 *
... ... @@ -55,7 +78,24 @@ public class VOTableView extends JPanel {
55 78 * The second one represents each element, in the same order as `keys`.
56 79 */
57 80 public void buildArray(String[] keys, Object[][] values) {
58   - JTable table = new JTable(values, keys);
  81 + table = new JTable(values, keys);
  82 +
  83 + // TODO: support multi-selection
  84 + KeyListener tableKeyListener = new KeyAdapter() {
  85 + @Override
  86 + public void keyPressed(KeyEvent e) {
  87 + updateSelection();
  88 + }
  89 + };
  90 + MouseListener tableMouseListener = new MouseAdapter() {
  91 + @Override
  92 + public void mouseClicked(MouseEvent e) {
  93 + updateSelection();
  94 + }
  95 + };
  96 +
  97 + table.addKeyListener(tableKeyListener);
  98 + table.addMouseListener(tableMouseListener);
59 99  
60 100 JScrollPane scrollPane = new JScrollPane(table);
61 101 scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
... ... @@ -66,6 +106,13 @@ public class VOTableView extends JPanel {
66 106 }
67 107  
68 108 /**
  109 + * This method is called on keyPressed and mouseClicked events on the JTable.
  110 + */
  111 + void updateSelection() {
  112 + controller.updateSelection(table.getSelectedColumn(), table.getSelectedRow());
  113 + }
  114 +
  115 + /**
69 116 * Display an error.
70 117 *
71 118 * @param title The title of the error.
... ...