Commit ccd40d6d9d372dd90bf22f9ce4d77a524ac1320b
1 parent
18446806
Exists in
master
Add download button
Showing
4 changed files
with
45 additions
and
5 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
... | ... | @@ -16,6 +16,10 @@ |
16 | 16 | |
17 | 17 | package eu.omp.irap.vespa.epntapclient.controller; |
18 | 18 | |
19 | +import java.io.File; | |
20 | +import java.io.IOException; | |
21 | +import java.nio.file.Files; | |
22 | +import java.nio.file.Paths; | |
19 | 23 | import java.util.HashMap; |
20 | 24 | import java.util.Map; |
21 | 25 | import java.util.logging.Level; |
... | ... | @@ -54,6 +58,8 @@ public class EpnTapController implements MainViewListener { |
54 | 58 | /** The URL of the service corresponding to the selected table. */ |
55 | 59 | private String selectedTableServiceURL; |
56 | 60 | |
61 | + String voTablePath; | |
62 | + | |
57 | 63 | /** |
58 | 64 | * The parameters fields for the request. |
59 | 65 | */ |
... | ... | @@ -70,7 +76,7 @@ public class EpnTapController implements MainViewListener { |
70 | 76 | |
71 | 77 | mainView = new EpnTapMainView(servicesController.getView(), resultsController.getView()); |
72 | 78 | mainView.addMainViewListener(this); |
73 | -// updateSelected(0); | |
79 | + // updateSelected(0); | |
74 | 80 | } |
75 | 81 | |
76 | 82 | /** |
... | ... | @@ -158,7 +164,17 @@ public class EpnTapController implements MainViewListener { |
158 | 164 | */ |
159 | 165 | public void sendQuery(String query) throws VOTableException { |
160 | 166 | logger.info("Sending query: " + query + " on " + selectedTableServiceURL); |
161 | - resultsController.fillTable(selectedTableServiceURL, "ADQL", query); | |
167 | + voTablePath = resultsController.fillTable(selectedTableServiceURL, "ADQL", query); | |
168 | + } | |
169 | + | |
170 | + public void downloadVOTable(File selectedFile) { | |
171 | + try { | |
172 | + // TODO: get real VOTAble path | |
173 | + Files.copy(Paths.get(voTablePath), Paths.get(selectedFile.getAbsolutePath())); | |
174 | + } catch (IOException e) { | |
175 | + // TODO Auto-generated catch block | |
176 | + e.printStackTrace(); | |
177 | + } | |
162 | 178 | } |
163 | 179 | |
164 | 180 | /** |
... | ... | @@ -180,6 +196,9 @@ public class EpnTapController implements MainViewListener { |
180 | 196 | case SEND_BUTTON_CLICKED: |
181 | 197 | sendQuery((String) object); |
182 | 198 | break; |
199 | + case DOWNLOAD_BUTTON_CLICKED: | |
200 | + downloadVOTable((File) args[0]); | |
201 | + break; | |
183 | 202 | case PARAMETER_CHANGED: |
184 | 203 | updateParameter((String) object, args[1]); |
185 | 204 | break; | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/Event.java
... | ... | @@ -24,6 +24,8 @@ public enum Event { |
24 | 24 | SERVICE_SELECTED, |
25 | 25 | /** When the `Send query` button is clicked. */ |
26 | 26 | SEND_BUTTON_CLICKED, |
27 | + /** When the `Download VOTable` button is clicked. */ | |
28 | + DOWNLOAD_BUTTON_CLICKED, | |
27 | 29 | /** When a parameter is removed on the parameter panel. */ |
28 | 30 | PARAMETER_REMOVED, |
29 | 31 | /** When a parameter is updated to a valid value on the parameter panel. */ | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/view/panels/BottomBarPanel.java
... | ... | @@ -17,12 +17,16 @@ |
17 | 17 | package eu.omp.irap.vespa.epntapclient.view.panels; |
18 | 18 | |
19 | 19 | import java.awt.BorderLayout; |
20 | +import java.awt.event.ActionEvent; | |
21 | +import java.awt.event.ActionListener; | |
20 | 22 | |
21 | 23 | import javax.swing.JButton; |
24 | +import javax.swing.JFileChooser; | |
22 | 25 | import javax.swing.JLabel; |
23 | 26 | import javax.swing.JPanel; |
24 | 27 | |
25 | 28 | import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; |
29 | +import eu.omp.irap.vespa.epntapclient.view.Event; | |
26 | 30 | |
27 | 31 | /** |
28 | 32 | * @author N. Jourdane |
... | ... | @@ -35,17 +39,30 @@ public class BottomBarPanel extends JPanel { |
35 | 39 | /** A label to display several informations (aka. status bar). */ |
36 | 40 | private JLabel infoLabel; |
37 | 41 | |
42 | + EpnTapMainView mainView; | |
43 | + | |
38 | 44 | |
39 | 45 | /** |
40 | 46 | * Method constructor for the bottom bar panel. |
41 | 47 | * |
42 | 48 | * @param mainView The main view of the application. |
43 | 49 | */ |
44 | - public BottomBarPanel(EpnTapMainView mainView) { | |
50 | + public BottomBarPanel(final EpnTapMainView mainView) { | |
51 | + this.mainView = mainView; | |
45 | 52 | setLayout(new BorderLayout()); |
46 | 53 | infoLabel = new JLabel(); |
47 | 54 | this.add(infoLabel); |
48 | - this.add(new JButton("Get File"), BorderLayout.EAST); | |
55 | + JButton button = new JButton("Get File"); | |
56 | + button.addActionListener(new ActionListener() { | |
57 | + | |
58 | + @Override | |
59 | + public void actionPerformed(ActionEvent e) { | |
60 | + final JFileChooser fc = new JFileChooser(); | |
61 | + fc.showOpenDialog(mainView); | |
62 | + mainView.event(Event.DOWNLOAD_BUTTON_CLICKED, fc.getSelectedFile()); | |
63 | + } | |
64 | + }); | |
65 | + this.add(button, BorderLayout.EAST); | |
49 | 66 | } |
50 | 67 | |
51 | 68 | /** |
... | ... | @@ -54,4 +71,5 @@ public class BottomBarPanel extends JPanel { |
54 | 71 | public void setInfoText(String infoText) { |
55 | 72 | infoLabel.setText(infoText); |
56 | 73 | } |
74 | + | |
57 | 75 | } | ... | ... |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
... | ... | @@ -86,10 +86,11 @@ public class VOTableController { |
86 | 86 | * @throws CantSendQueryException If the query can not be sent. |
87 | 87 | * @throws CantDisplayVOTableException If the table can not be filled. |
88 | 88 | */ |
89 | - public void fillTable(String targetURL, String queryLanguage, String query) | |
89 | + public String fillTable(String targetURL, String queryLanguage, String query) | |
90 | 90 | throws CantDisplayVOTableException, CantSendQueryException { |
91 | 91 | String voTablePath = VOTableConnection.sendQuery(targetURL, queryLanguage, query); |
92 | 92 | fillTable(voTablePath); |
93 | + return voTablePath; | |
93 | 94 | } |
94 | 95 | |
95 | 96 | /** | ... | ... |