Commit a8594a1489fa649bba0b7e8628d985d54b3065db
1 parent
5af53be7
Exists in
master
[VOTable] Throw errors instead of display message dialogs.
Showing
5 changed files
with
58 additions
and
55 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
@@ -64,8 +64,7 @@ public class EpnTapController implements MainViewListener { | @@ -64,8 +64,7 @@ public class EpnTapController implements MainViewListener { | ||
64 | Queries.GET_EPN_TAP_SERVICES); | 64 | Queries.GET_EPN_TAP_SERVICES); |
65 | resultsController = new VOTableController(); | 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 | mainView.addMainViewListener(this); | 68 | mainView.addMainViewListener(this); |
70 | updateSelected(0); | 69 | updateSelected(0); |
71 | } | 70 | } |
@@ -158,7 +157,7 @@ public class EpnTapController implements MainViewListener { | @@ -158,7 +157,7 @@ public class EpnTapController implements MainViewListener { | ||
158 | } | 157 | } |
159 | } catch (Exception e) { | 158 | } catch (Exception e) { |
160 | mainView.displayError("Error", "An unexpected error occured: " + e.getMessage() | 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 | logger.log(Level.SEVERE, "Error occured when " + event.toString(), e); | 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,7 +23,6 @@ import javax.swing.JOptionPane; | ||
23 | import javax.swing.JPanel; | 23 | import javax.swing.JPanel; |
24 | import javax.swing.JSplitPane; | 24 | import javax.swing.JSplitPane; |
25 | 25 | ||
26 | -import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; | ||
27 | import eu.omp.irap.vespa.epntapclient.view.panels.BottomBarPanel; | 26 | import eu.omp.irap.vespa.epntapclient.view.panels.BottomBarPanel; |
28 | import eu.omp.irap.vespa.epntapclient.view.panels.RequestPanel; | 27 | import eu.omp.irap.vespa.epntapclient.view.panels.RequestPanel; |
29 | import eu.omp.irap.vespa.epntapclient.view.panels.ResultsPanel; | 28 | import eu.omp.irap.vespa.epntapclient.view.panels.ResultsPanel; |
@@ -40,9 +39,6 @@ public class EpnTapMainView extends JPanel { | @@ -40,9 +39,6 @@ public class EpnTapMainView extends JPanel { | ||
40 | /** The serial version UID (affected with a random number). */ | 39 | /** The serial version UID (affected with a random number). */ |
41 | private static final long serialVersionUID = -1233290271099283814L; | 40 | private static final long serialVersionUID = -1233290271099283814L; |
42 | 41 | ||
43 | - /** The main EPN-TAP main controller */ | ||
44 | - private EpnTapController controller; | ||
45 | - | ||
46 | /** The JPanel where the VOTable results is displayed. */ | 42 | /** The JPanel where the VOTable results is displayed. */ |
47 | private ResultsPanel resultsPanel; | 43 | private ResultsPanel resultsPanel; |
48 | 44 | ||
@@ -67,10 +63,7 @@ public class EpnTapMainView extends JPanel { | @@ -67,10 +63,7 @@ public class EpnTapMainView extends JPanel { | ||
67 | * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events. | 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 | this.servicesPanel = new ServicesPanel(this, voTableServicesView); | 67 | this.servicesPanel = new ServicesPanel(this, voTableServicesView); |
75 | this.resultsPanel = new ResultsPanel(this, voTableResultsView); | 68 | this.resultsPanel = new ResultsPanel(this, voTableResultsView); |
76 | this.requestPanel = new RequestPanel(this); | 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,7 +19,11 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | import java.util.logging.Logger; | 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 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; | 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 | import eu.omp.irap.vespa.epntapclient.votable.model.Table; | 27 | import eu.omp.irap.vespa.epntapclient.votable.model.Table; |
24 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | 28 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
25 | import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | 29 | import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; |
@@ -48,14 +52,11 @@ public class VOTableController { | @@ -48,14 +52,11 @@ public class VOTableController { | ||
48 | * Method constructor | 52 | * Method constructor |
49 | * | 53 | * |
50 | * @param voTablePath The path of the VOTable XML file. | 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 | view = new VOTableView(); | 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,33 +90,35 @@ public class VOTableController { | ||
89 | 90 | ||
90 | /** | 91 | /** |
91 | * @param voTablePath The path of the VOTable file. | 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 | * @throws VOTableException Can not fill the VOTable data in the JTable. | 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 | // TODO: Handle the case when there are more than 1 resource or table. | 107 | // TODO: Handle the case when there are more than 1 resource or table. |
103 | if (voTable.getRESOURCE().size() > 1) { | 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 | // TODO: Iterate over all potential ERROR tags | 112 | // TODO: Iterate over all potential ERROR tags |
109 | if ("ERROR".equals(voTable.getRESOURCE().get(0).getINFO().get(0).getValueAttribute())) { | 113 | if ("ERROR".equals(voTable.getRESOURCE().get(0).getINFO().get(0).getValueAttribute())) { |
110 | String errorInfo = voTable.getRESOURCE().get(0).getINFO().get(0).getValue(); | 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 | if (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().size() > 1) { | 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 | Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0)); | 122 | Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0)); |
120 | 123 | ||
121 | VOTableDataParser dataParser; | 124 | VOTableDataParser dataParser; |
@@ -123,7 +126,7 @@ public class VOTableController { | @@ -123,7 +126,7 @@ public class VOTableController { | ||
123 | dataParser = new VOTableDataParser(table); | 126 | dataParser = new VOTableDataParser(table); |
124 | view.fillTable(dataParser.getColumnsName(), dataParser.getDataArray()); | 127 | view.fillTable(dataParser.getColumnsName(), dataParser.getDataArray()); |
125 | } catch (IOException e) { | 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,6 +16,7 @@ | ||
16 | 16 | ||
17 | package eu.omp.irap.vespa.epntapclient.votable.controller; | 17 | package eu.omp.irap.vespa.epntapclient.votable.controller; |
18 | 18 | ||
19 | +import java.io.IOException; | ||
19 | import java.util.logging.Logger; | 20 | import java.util.logging.Logger; |
20 | 21 | ||
21 | /** | 22 | /** |
@@ -63,6 +64,36 @@ public class VOTableException extends Exception { | @@ -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 | public static class BadRequestException extends VOTableException { | 97 | public static class BadRequestException extends VOTableException { |
67 | private final String info; | 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,7 +20,6 @@ import java.awt.BorderLayout; | ||
20 | import java.util.List; | 20 | import java.util.List; |
21 | import java.util.logging.Logger; | 21 | import java.util.logging.Logger; |
22 | 22 | ||
23 | -import javax.swing.JOptionPane; | ||
24 | import javax.swing.JPanel; | 23 | import javax.swing.JPanel; |
25 | import javax.swing.JScrollPane; | 24 | import javax.swing.JScrollPane; |
26 | import javax.swing.JTable; | 25 | import javax.swing.JTable; |
@@ -104,28 +103,6 @@ public class VOTableView extends JPanel implements TableModelListener { | @@ -104,28 +103,6 @@ public class VOTableView extends JPanel implements TableModelListener { | ||
104 | return tableData.getValueAt(row, column); | 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 | @Override | 106 | @Override |
130 | public void tableChanged(TableModelEvent e) { | 107 | public void tableChanged(TableModelEvent e) { |
131 | if (e.getType() != TableModelEvent.UPDATE) | 108 | if (e.getType() != TableModelEvent.UPDATE) |