Commit a8594a1489fa649bba0b7e8628d985d54b3065db

Authored by Nathanael Jourdane
1 parent 5af53be7
Exists in master

[VOTable] Throw errors instead of display message dialogs.

src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
... ... @@ -64,8 +64,7 @@ public class EpnTapController implements MainViewListener {
64 64 Queries.GET_EPN_TAP_SERVICES);
65 65 resultsController = new VOTableController();
66 66  
67   - mainView = new EpnTapMainView(this, servicesController.getView(),
68   - resultsController.getView());
  67 + mainView = new EpnTapMainView(servicesController.getView(), resultsController.getView());
69 68 mainView.addMainViewListener(this);
70 69 updateSelected(0);
71 70 }
... ... @@ -158,7 +157,7 @@ public class EpnTapController implements MainViewListener {
158 157 }
159 158 } catch (Exception e) {
160 159 mainView.displayError("Error", "An unexpected error occured: " + e.getMessage()
161   - + ".\nPlease report it to the developper team.");
  160 + + ".\nPlease report it to the developper team along with the stacktrace.");
162 161 logger.log(Level.SEVERE, "Error occured when " + event.toString(), e);
163 162 }
164 163 }
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java
... ... @@ -23,7 +23,6 @@ import javax.swing.JOptionPane;
23 23 import javax.swing.JPanel;
24 24 import javax.swing.JSplitPane;
25 25  
26   -import eu.omp.irap.vespa.epntapclient.controller.EpnTapController;
27 26 import eu.omp.irap.vespa.epntapclient.view.panels.BottomBarPanel;
28 27 import eu.omp.irap.vespa.epntapclient.view.panels.RequestPanel;
29 28 import eu.omp.irap.vespa.epntapclient.view.panels.ResultsPanel;
... ... @@ -40,9 +39,6 @@ public class EpnTapMainView extends JPanel {
40 39 /** The serial version UID (affected with a random number). */
41 40 private static final long serialVersionUID = -1233290271099283814L;
42 41  
43   - /** The main EPN-TAP main controller */
44   - private EpnTapController controller;
45   -
46 42 /** The JPanel where the VOTable results is displayed. */
47 43 private ResultsPanel resultsPanel;
48 44  
... ... @@ -67,10 +63,7 @@ public class EpnTapMainView extends JPanel {
67 63 * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events.
68 64 */
69 65  
70   - public EpnTapMainView(final EpnTapController controller, VOTableView voTableServicesView,
71   - VOTableView voTableResultsView) {
72   - this.controller = controller;
73   -
  66 + public EpnTapMainView(VOTableView voTableServicesView, VOTableView voTableResultsView) {
74 67 this.servicesPanel = new ServicesPanel(this, voTableServicesView);
75 68 this.resultsPanel = new ResultsPanel(this, voTableResultsView);
76 69 this.requestPanel = new RequestPanel(this);
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
... ... @@ -19,7 +19,11 @@ package eu.omp.irap.vespa.epntapclient.votable.controller;
19 19 import java.io.IOException;
20 20 import java.util.logging.Logger;
21 21  
  22 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableCantFillVoTableException;
  23 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableNotValidQueryException;
22 24 import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException;
  25 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableSeveralResourcesException;
  26 +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableSeveralTablesException;
23 27 import eu.omp.irap.vespa.epntapclient.votable.model.Table;
24 28 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
25 29 import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView;
... ... @@ -48,14 +52,11 @@ public class VOTableController {
48 52 * Method constructor
49 53 *
50 54 * @param voTablePath The path of the VOTable XML file.
  55 + * @throws VOTableException
51 56 */
52   - public VOTableController(String voTablePath) {
  57 + public VOTableController(String voTablePath) throws VOTableException {
53 58 view = new VOTableView();
54   - try {
55   - fillTable(voTablePath);
56   - } catch (VOTableException e) {
57   - view.displayError("Can not fil the VOTable.", e);
58   - }
  59 + fillTable(voTablePath);
59 60 }
60 61  
61 62 /**
... ... @@ -89,33 +90,35 @@ public class VOTableController {
89 90  
90 91 /**
91 92 * @param voTablePath The path of the VOTable file.
  93 + * @throws VOTableParsingException
  94 + * @throws VOTableSeveralResourcesException
  95 + * @throws VOTableNotValidQueryException
  96 + * @throws VOTableSeveralTablesException
  97 + * @throws VOTableCantFillVoTableException
92 98 * @throws VOTableException Can not fill the VOTable data in the JTable.
93 99 */
94   - public void fillTable(String voTablePath) throws VOTableException {
  100 + public void fillTable(String voTablePath)
  101 + throws VOTableParsingException, VOTableSeveralResourcesException,
  102 + VOTableNotValidQueryException, VOTableSeveralTablesException,
  103 + VOTableCantFillVoTableException {
95 104  
96   - try {
97   - voTable = VOTableParser.parseVOTable(voTablePath);
98   - } catch (VOTableParsingException e1) {
99   - view.displayError("Can not parse the VOTable.", e1);
100   - }
  105 + voTable = VOTableParser.parseVOTable(voTablePath);
101 106  
102 107 // TODO: Handle the case when there are more than 1 resource or table.
103 108 if (voTable.getRESOURCE().size() > 1) {
104   - view.displayError("VOTable with more than one resource are not yet supported.\n"
105   - + "See VOTable file for more informations: " + voTablePath);
106   - return;
  109 + throw new VOTableSeveralResourcesException();
107 110 }
  111 +
108 112 // TODO: Iterate over all potential ERROR tags
109 113 if ("ERROR".equals(voTable.getRESOURCE().get(0).getINFO().get(0).getValueAttribute())) {
110 114 String errorInfo = voTable.getRESOURCE().get(0).getINFO().get(0).getValue();
111   - view.displayError("The query is not valid.\n" + errorInfo);
112   - return;
  115 + throw new VOTableNotValidQueryException(errorInfo);
113 116 }
  117 +
114 118 if (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().size() > 1) {
115   - view.displayError("VOTable with more than one table are not yet supported.\n"
116   - + "See VOTable file for more informations: " + voTablePath);
117   - return;
  119 + throw new VOTableSeveralTablesException();
118 120 }
  121 +
119 122 Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0));
120 123  
121 124 VOTableDataParser dataParser;
... ... @@ -123,7 +126,7 @@ public class VOTableController {
123 126 dataParser = new VOTableDataParser(table);
124 127 view.fillTable(dataParser.getColumnsName(), dataParser.getDataArray());
125 128 } catch (IOException e) {
126   - throw new VOTableException("Can not fill the VOTable data in the JTable.", e);
  129 + throw new VOTableCantFillVoTableException(e);
127 130 }
128 131 }
129 132  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java
... ... @@ -16,6 +16,7 @@
16 16  
17 17 package eu.omp.irap.vespa.epntapclient.votable.controller;
18 18  
  19 +import java.io.IOException;
19 20 import java.util.logging.Logger;
20 21  
21 22 /**
... ... @@ -63,6 +64,36 @@ public class VOTableException extends Exception {
63 64 }
64 65 }
65 66  
  67 + // view.displayError("VOTable with more than one resource are not yet supported.\n"
  68 + // "See VOTable file for more informations: " + voTablePath);
  69 + public static class VOTableSeveralResourcesException extends VOTableException {
  70 + public VOTableSeveralResourcesException() {
  71 + super();
  72 + }
  73 + }
  74 +
  75 + // view.displayError("VOTable with more than one table are not yet supported.\n"
  76 + // "See VOTable file for more informations: " + voTablePath);
  77 + public static class VOTableSeveralTablesException extends VOTableException {
  78 + public VOTableSeveralTablesException() {
  79 + super();
  80 + }
  81 + }
  82 +
  83 + // "Can not fill the VOTable data in the JTable."
  84 + public static class VOTableCantFillVoTableException extends VOTableException {
  85 + public VOTableCantFillVoTableException(IOException e) {
  86 + super();
  87 + }
  88 + }
  89 +
  90 + // The query is not valid.
  91 + public static class VOTableNotValidQueryException extends VOTableException {
  92 + public VOTableNotValidQueryException(String errorInfo) {
  93 + super();
  94 + }
  95 + }
  96 +
66 97 public static class BadRequestException extends VOTableException {
67 98 private final String info;
68 99  
... ...
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
... ... @@ -20,7 +20,6 @@ import java.awt.BorderLayout;
20 20 import java.util.List;
21 21 import java.util.logging.Logger;
22 22  
23   -import javax.swing.JOptionPane;
24 23 import javax.swing.JPanel;
25 24 import javax.swing.JScrollPane;
26 25 import javax.swing.JTable;
... ... @@ -104,28 +103,6 @@ public class VOTableView extends JPanel implements TableModelListener {
104 103 return tableData.getValueAt(row, column);
105 104 }
106 105  
107   - /**
108   - * Display an error.
109   - *
110   - * @param message The error message displayed in the window.
111   - */
112   - public void displayError(String message) {
113   - JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
114   - logger.warning(message);
115   - }
116   -
117   - /**
118   - * Display an error.
119   - *
120   - * @param message The error message displayed in the window.
121   - * @param e The exception displayed in the log for debug.
122   - */
123   - public void displayError(String message, Exception e) {
124   - String error_msg = "-- user error --\n%1s\nbecause:\n%2s\n-- end of user error --\n";
125   - JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
126   - logger.warning(String.format(error_msg, message, e.getMessage()));
127   - }
128   -
129 106 @Override
130 107 public void tableChanged(TableModelEvent e) {
131 108 if (e.getType() != TableModelEvent.UPDATE)
... ...