From ccd40d6d9d372dd90bf22f9ce4d77a524ac1320b Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Tue, 12 Apr 2016 17:53:19 +0200 Subject: [PATCH] Add download button --- src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java | 23 +++++++++++++++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java | 2 ++ src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java | 22 ++++++++++++++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java | 3 ++- 4 files changed, 45 insertions(+), 5 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 6681814..6edccab 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,6 +16,10 @@ package eu.omp.irap.vespa.epntapclient.controller; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; @@ -54,6 +58,8 @@ public class EpnTapController implements MainViewListener { /** The URL of the service corresponding to the selected table. */ private String selectedTableServiceURL; + String voTablePath; + /** * The parameters fields for the request. */ @@ -70,7 +76,7 @@ public class EpnTapController implements MainViewListener { mainView = new EpnTapMainView(servicesController.getView(), resultsController.getView()); mainView.addMainViewListener(this); -// updateSelected(0); + // updateSelected(0); } /** @@ -158,7 +164,17 @@ public class EpnTapController implements MainViewListener { */ public void sendQuery(String query) throws VOTableException { logger.info("Sending query: " + query + " on " + selectedTableServiceURL); - resultsController.fillTable(selectedTableServiceURL, "ADQL", query); + voTablePath = resultsController.fillTable(selectedTableServiceURL, "ADQL", query); + } + + public void downloadVOTable(File selectedFile) { + try { + // TODO: get real VOTAble path + Files.copy(Paths.get(voTablePath), Paths.get(selectedFile.getAbsolutePath())); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } /** @@ -180,6 +196,9 @@ public class EpnTapController implements MainViewListener { case SEND_BUTTON_CLICKED: sendQuery((String) object); break; + case DOWNLOAD_BUTTON_CLICKED: + downloadVOTable((File) args[0]); + break; case PARAMETER_CHANGED: updateParameter((String) object, args[1]); break; diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java index e5b6054..40dbd09 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java @@ -24,6 +24,8 @@ public enum Event { SERVICE_SELECTED, /** When the `Send query` button is clicked. */ SEND_BUTTON_CLICKED, + /** When the `Download VOTable` button is clicked. */ + DOWNLOAD_BUTTON_CLICKED, /** When a parameter is removed on the parameter panel. */ PARAMETER_REMOVED, /** When a parameter is updated to a valid value on the parameter panel. */ diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java index 2d7372b..84deb1a 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java @@ -17,12 +17,16 @@ package eu.omp.irap.vespa.epntapclient.view.panels; import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; +import eu.omp.irap.vespa.epntapclient.view.Event; /** * @author N. Jourdane @@ -35,17 +39,30 @@ public class BottomBarPanel extends JPanel { /** A label to display several informations (aka. status bar). */ private JLabel infoLabel; + EpnTapMainView mainView; + /** * Method constructor for the bottom bar panel. * * @param mainView The main view of the application. */ - public BottomBarPanel(EpnTapMainView mainView) { + public BottomBarPanel(final EpnTapMainView mainView) { + this.mainView = mainView; setLayout(new BorderLayout()); infoLabel = new JLabel(); this.add(infoLabel); - this.add(new JButton("Get File"), BorderLayout.EAST); + JButton button = new JButton("Get File"); + button.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + final JFileChooser fc = new JFileChooser(); + fc.showOpenDialog(mainView); + mainView.event(Event.DOWNLOAD_BUTTON_CLICKED, fc.getSelectedFile()); + } + }); + this.add(button, BorderLayout.EAST); } /** @@ -54,4 +71,5 @@ public class BottomBarPanel extends JPanel { public void setInfoText(String infoText) { infoLabel.setText(infoText); } + } 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 039a2b6..68741ff 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 @@ -86,10 +86,11 @@ public class VOTableController { * @throws CantSendQueryException If the query can not be sent. * @throws CantDisplayVOTableException If the table can not be filled. */ - public void fillTable(String targetURL, String queryLanguage, String query) + public String fillTable(String targetURL, String queryLanguage, String query) throws CantDisplayVOTableException, CantSendQueryException { String voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage, query); fillTable(voTablePath); + return voTablePath; } /** -- libgit2 0.21.2