From a8594a1489fa649bba0b7e8628d985d54b3065db Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Mon, 14 Mar 2016 12:11:48 +0100 Subject: [PATCH] [VOTable] Throw errors instead of display message dialogs. --- src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java | 5 ++--- src/main/java/eu/omp/irap/vespa/epntapclient/view/EpnTapMainView.java | 9 +-------- src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java | 45 ++++++++++++++++++++++++--------------------- src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java | 31 +++++++++++++++++++++++++++++++ src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java | 23 ----------------------- 5 files changed, 58 insertions(+), 55 deletions(-) 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 e562345..3b7484e 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 @@ -64,8 +64,7 @@ public class EpnTapController implements MainViewListener { Queries.GET_EPN_TAP_SERVICES); resultsController = new VOTableController(); - mainView = new EpnTapMainView(this, servicesController.getView(), - resultsController.getView()); + mainView = new EpnTapMainView(servicesController.getView(), resultsController.getView()); mainView.addMainViewListener(this); updateSelected(0); } @@ -158,7 +157,7 @@ public class EpnTapController implements MainViewListener { } } catch (Exception e) { mainView.displayError("Error", "An unexpected error occured: " + e.getMessage() - + ".\nPlease report it to the developper team."); + + ".\nPlease report it to the developper team along with the stacktrace."); logger.log(Level.SEVERE, "Error occured when " + event.toString(), e); } } 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 6d04351..8772110 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 @@ -23,7 +23,6 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; -import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; import eu.omp.irap.vespa.epntapclient.view.panels.BottomBarPanel; import eu.omp.irap.vespa.epntapclient.view.panels.RequestPanel; import eu.omp.irap.vespa.epntapclient.view.panels.ResultsPanel; @@ -40,9 +39,6 @@ public class EpnTapMainView extends JPanel { /** The serial version UID (affected with a random number). */ private static final long serialVersionUID = -1233290271099283814L; - /** The main EPN-TAP main controller */ - private EpnTapController controller; - /** The JPanel where the VOTable results is displayed. */ private ResultsPanel resultsPanel; @@ -67,10 +63,7 @@ public class EpnTapMainView extends JPanel { * @param controller The EPN-TAP controller, allowing the EPN-TAP view to send events. */ - public EpnTapMainView(final EpnTapController controller, VOTableView voTableServicesView, - VOTableView voTableResultsView) { - this.controller = controller; - + public EpnTapMainView(VOTableView voTableServicesView, VOTableView voTableResultsView) { this.servicesPanel = new ServicesPanel(this, voTableServicesView); this.resultsPanel = new ResultsPanel(this, voTableResultsView); this.requestPanel = new RequestPanel(this); 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 71a50da..4a63d80 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 @@ -19,7 +19,11 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; import java.io.IOException; import java.util.logging.Logger; +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableCantFillVoTableException; +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableNotValidQueryException; import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableSeveralResourcesException; +import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableSeveralTablesException; 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; @@ -48,14 +52,11 @@ public class VOTableController { * Method constructor * * @param voTablePath The path of the VOTable XML file. + * @throws VOTableException */ - public VOTableController(String voTablePath) { + public VOTableController(String voTablePath) throws VOTableException { view = new VOTableView(); - try { - fillTable(voTablePath); - } catch (VOTableException e) { - view.displayError("Can not fil the VOTable.", e); - } + fillTable(voTablePath); } /** @@ -89,33 +90,35 @@ public class VOTableController { /** * @param voTablePath The path of the VOTable file. + * @throws VOTableParsingException + * @throws VOTableSeveralResourcesException + * @throws VOTableNotValidQueryException + * @throws VOTableSeveralTablesException + * @throws VOTableCantFillVoTableException * @throws VOTableException Can not fill the VOTable data in the JTable. */ - public void fillTable(String voTablePath) throws VOTableException { + public void fillTable(String voTablePath) + throws VOTableParsingException, VOTableSeveralResourcesException, + VOTableNotValidQueryException, VOTableSeveralTablesException, + VOTableCantFillVoTableException { - try { - voTable = VOTableParser.parseVOTable(voTablePath); - } catch (VOTableParsingException e1) { - view.displayError("Can not parse the VOTable.", e1); - } + voTable = VOTableParser.parseVOTable(voTablePath); // TODO: Handle the case when there are more than 1 resource or table. if (voTable.getRESOURCE().size() > 1) { - view.displayError("VOTable with more than one resource are not yet supported.\n" - + "See VOTable file for more informations: " + voTablePath); - return; + throw new VOTableSeveralResourcesException(); } + // TODO: Iterate over all potential ERROR tags if ("ERROR".equals(voTable.getRESOURCE().get(0).getINFO().get(0).getValueAttribute())) { String errorInfo = voTable.getRESOURCE().get(0).getINFO().get(0).getValue(); - view.displayError("The query is not valid.\n" + errorInfo); - return; + throw new VOTableNotValidQueryException(errorInfo); } + if (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().size() > 1) { - view.displayError("VOTable with more than one table are not yet supported.\n" - + "See VOTable file for more informations: " + voTablePath); - return; + throw new VOTableSeveralTablesException(); } + Table table = (Table) (voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0)); VOTableDataParser dataParser; @@ -123,7 +126,7 @@ public class VOTableController { dataParser = new VOTableDataParser(table); view.fillTable(dataParser.getColumnsName(), dataParser.getDataArray()); } catch (IOException e) { - throw new VOTableException("Can not fill the VOTable data in the JTable.", e); + throw new VOTableCantFillVoTableException(e); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java index 99eb441..ab937f8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java @@ -16,6 +16,7 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; +import java.io.IOException; import java.util.logging.Logger; /** @@ -63,6 +64,36 @@ public class VOTableException extends Exception { } } + // view.displayError("VOTable with more than one resource are not yet supported.\n" + // "See VOTable file for more informations: " + voTablePath); + public static class VOTableSeveralResourcesException extends VOTableException { + public VOTableSeveralResourcesException() { + super(); + } + } + + // view.displayError("VOTable with more than one table are not yet supported.\n" + // "See VOTable file for more informations: " + voTablePath); + public static class VOTableSeveralTablesException extends VOTableException { + public VOTableSeveralTablesException() { + super(); + } + } + + // "Can not fill the VOTable data in the JTable." + public static class VOTableCantFillVoTableException extends VOTableException { + public VOTableCantFillVoTableException(IOException e) { + super(); + } + } + + // The query is not valid. + public static class VOTableNotValidQueryException extends VOTableException { + public VOTableNotValidQueryException(String errorInfo) { + super(); + } + } + public static class BadRequestException extends VOTableException { private final String info; 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 579502b..38997ce 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 @@ -20,7 +20,6 @@ import java.awt.BorderLayout; import java.util.List; import java.util.logging.Logger; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -104,28 +103,6 @@ public class VOTableView extends JPanel implements TableModelListener { return tableData.getValueAt(row, column); } - /** - * Display an error. - * - * @param message The error message displayed in the window. - */ - public void displayError(String message) { - JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); - logger.warning(message); - } - - /** - * Display an error. - * - * @param message The error message displayed in the window. - * @param e The exception displayed in the log for debug. - */ - public void displayError(String message, Exception e) { - String error_msg = "-- user error --\n%1s\nbecause:\n%2s\n-- end of user error --\n"; - JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); - logger.warning(String.format(error_msg, message, e.getMessage())); - } - @Override public void tableChanged(TableModelEvent e) { if (e.getType() != TableModelEvent.UPDATE) -- libgit2 0.21.2