diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java index 00c0bc6..6fda4d3 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java @@ -16,10 +16,12 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; +import java.awt.Cursor; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; +import javax.swing.SwingWorker; import eu.omp.irap.vespa.epntapclient.EpnTapController; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; @@ -35,17 +37,20 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener /** The logger for the class MainPanelCtrl. */ private static final Logger LOGGER = Logger.getLogger(MainPanelCtrl.class.getName()); + /** The swing worker for doing a send query. */ + private SwingWorker sw; + /** The controller of the request panel. */ - private RequestPanelCtrl requestPanelCtrl; + RequestPanelCtrl requestPanelCtrl; /** The controller of the result panel. */ - private ResultPanelCtrl resultsPanelCtrl; + ResultPanelCtrl resultsPanelCtrl; /** The controller of the services panel. */ - private ServicesPanelCtrl servicesPanelCtrl; + ServicesPanelCtrl servicesPanelCtrl; /** The main view of the application. */ - private MainPanelView view; + MainPanelView view; /** @@ -64,6 +69,15 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); } + /* + * @see + * eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener#displayInfo(java.lang.String) + */ + @Override + public void displayInfo(String message) { + view.getResultsPanel().getStatusBar().setText(message); + } + /** * @return The controller of the request panel. */ @@ -107,15 +121,45 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener @Override public void sendQuery() { - try { - sendQueries(servicesPanelCtrl.getServices()); - } catch (VOTableException e) { - displayError("Can not update the VOTable.", e); + // Avoid multiple queries at the same time: stop the current first, then launch a new one. + if (sw != null && !sw.isDone()) { + sw.cancel(true); } + sw = createNewWorker(); + view.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + sw.execute(); } @Override public void updateQuery() { requestPanelCtrl.updateQuery(); } + + /** + * Create a new {@link SwingWorker} for doing a send query. + * + * @return The created {@link SwingWorker}. + */ + private SwingWorker createNewWorker() { + return new SwingWorker() { + + @Override + protected Void doInBackground() throws Exception { + try { + sendQueries(servicesPanelCtrl.getServices()); + } catch (VOTableException e) { + displayError("Can not update the VOTable.", e); + } + return null; + } + + @Override + protected void done() { + if (!isCancelled()) { + resultsPanelCtrl.getView().fillTable(resultsPanelCtrl.getVOTableData()); + } + view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }; + } } -- libgit2 0.21.2