Commit 857e48450751319934be944ff58e4cb9632ec148
1 parent
a17b4f33
Exists in
master
Use a swing worker to send the query.
Showing
1 changed file
with
52 additions
and
8 deletions
Show diff stats
src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java
@@ -16,10 +16,12 @@ | @@ -16,10 +16,12 @@ | ||
16 | 16 | ||
17 | package eu.omp.irap.vespa.epntapclient.gui.mainpanel; | 17 | package eu.omp.irap.vespa.epntapclient.gui.mainpanel; |
18 | 18 | ||
19 | +import java.awt.Cursor; | ||
19 | import java.util.logging.Level; | 20 | import java.util.logging.Level; |
20 | import java.util.logging.Logger; | 21 | import java.util.logging.Logger; |
21 | 22 | ||
22 | import javax.swing.JOptionPane; | 23 | import javax.swing.JOptionPane; |
24 | +import javax.swing.SwingWorker; | ||
23 | 25 | ||
24 | import eu.omp.irap.vespa.epntapclient.EpnTapController; | 26 | import eu.omp.irap.vespa.epntapclient.EpnTapController; |
25 | import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; | 27 | import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; |
@@ -35,17 +37,20 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | @@ -35,17 +37,20 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | ||
35 | /** The logger for the class MainPanelCtrl. */ | 37 | /** The logger for the class MainPanelCtrl. */ |
36 | private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); | 38 | private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); |
37 | 39 | ||
40 | + /** The swing worker for doing a send query. */ | ||
41 | + private SwingWorker<Void, Void> sw; | ||
42 | + | ||
38 | /** The controller of the request panel. */ | 43 | /** The controller of the request panel. */ |
39 | - private RequestPanelCtrl requestPanelCtrl; | 44 | + RequestPanelCtrl requestPanelCtrl; |
40 | 45 | ||
41 | /** The controller of the result panel. */ | 46 | /** The controller of the result panel. */ |
42 | - private ResultPanelCtrl resultsPanelCtrl; | 47 | + ResultPanelCtrl resultsPanelCtrl; |
43 | 48 | ||
44 | /** The controller of the services panel. */ | 49 | /** The controller of the services panel. */ |
45 | - private ServicesPanelCtrl servicesPanelCtrl; | 50 | + ServicesPanelCtrl servicesPanelCtrl; |
46 | 51 | ||
47 | /** The main view of the application. */ | 52 | /** The main view of the application. */ |
48 | - private MainPanelView view; | 53 | + MainPanelView view; |
49 | 54 | ||
50 | 55 | ||
51 | /** | 56 | /** |
@@ -64,6 +69,15 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | @@ -64,6 +69,15 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | ||
64 | JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); | 69 | JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); |
65 | } | 70 | } |
66 | 71 | ||
72 | + /* | ||
73 | + * @see | ||
74 | + * eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener#displayInfo(java.lang.String) | ||
75 | + */ | ||
76 | + @Override | ||
77 | + public void displayInfo(String message) { | ||
78 | + view.getResultsPanel().getStatusBar().setText(message); | ||
79 | + } | ||
80 | + | ||
67 | /** | 81 | /** |
68 | * @return The controller of the request panel. | 82 | * @return The controller of the request panel. |
69 | */ | 83 | */ |
@@ -107,15 +121,45 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | @@ -107,15 +121,45 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener | ||
107 | 121 | ||
108 | @Override | 122 | @Override |
109 | public void sendQuery() { | 123 | public void sendQuery() { |
110 | - try { | ||
111 | - sendQueries(servicesPanelCtrl.getServices()); | ||
112 | - } catch (VOTableException e) { | ||
113 | - displayError("Can not update the VOTable.", e); | 124 | + // Avoid multiple queries at the same time: stop the current first, then launch a new one. |
125 | + if (sw != null && !sw.isDone()) { | ||
126 | + sw.cancel(true); | ||
114 | } | 127 | } |
128 | + sw = createNewWorker(); | ||
129 | + view.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); | ||
130 | + sw.execute(); | ||
115 | } | 131 | } |
116 | 132 | ||
117 | @Override | 133 | @Override |
118 | public void updateQuery() { | 134 | public void updateQuery() { |
119 | requestPanelCtrl.updateQuery(); | 135 | requestPanelCtrl.updateQuery(); |
120 | } | 136 | } |
137 | + | ||
138 | + /** | ||
139 | + * Create a new {@link SwingWorker} for doing a send query. | ||
140 | + * | ||
141 | + * @return The created {@link SwingWorker}. | ||
142 | + */ | ||
143 | + private SwingWorker<Void, Void> createNewWorker() { | ||
144 | + return new SwingWorker<Void, Void>() { | ||
145 | + | ||
146 | + @Override | ||
147 | + protected Void doInBackground() throws Exception { | ||
148 | + try { | ||
149 | + sendQueries(servicesPanelCtrl.getServices()); | ||
150 | + } catch (VOTableException e) { | ||
151 | + displayError("Can not update the VOTable.", e); | ||
152 | + } | ||
153 | + return null; | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + protected void done() { | ||
158 | + if (!isCancelled()) { | ||
159 | + resultsPanelCtrl.getView().fillTable(resultsPanelCtrl.getVOTableData()); | ||
160 | + } | ||
161 | + view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); | ||
162 | + } | ||
163 | + }; | ||
164 | + } | ||
121 | } | 165 | } |