From 84b3dbfc8f6fd5fb6645fc9148cded8de3c3cfd6 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Wed, 15 Jun 2016 21:09:36 +0200 Subject: [PATCH] Use SwingWorkers to avoid EDT violations. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java | 4 ++-- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java | 22 ++++++++++++++++++++-- src/main/java/eu/omp/irap/vespa/epntapclient/epntap/EpnTapController.java | 40 +++++++++++++++------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/epntap/service/ServiceCtrl.java | 8 ++++---- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelCtrl.java | 99 +++++++++++++++++++++++---------------------------------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java | 30 ++++++++++++++++++------------ src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java | 18 +++++++++++++++--- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java | 9 ++++++++- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java | 17 ++++++++++++++--- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java | 33 +++++++++++++++++++++++++++++---- src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java | 6 ++++++ src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java | 39 ++++++++++++++++----------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java | 9 --------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java | 104 +++++++++----------------------------------------------------------------------------------------------- src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java | 37 +++++++++++++++++++++++++++++++------ 15 files changed, 210 insertions(+), 265 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java index cbd02f9..0b35fd8 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java @@ -125,7 +125,7 @@ public class EpnTapConnection implements EpnTapInterface { @Override public List sendADQLQuery(String tapURL, String adqlQuery) throws VOTableException { VOTableCtrl voTableCtrl = new VOTableCtrl(); - voTableCtrl.newVOTable(tapURL, adqlQuery); + voTableCtrl.acquireVOTable(tapURL, adqlQuery, false); VOTableData data = voTableCtrl.getVOTableData(); List granules; @@ -139,7 +139,7 @@ public class EpnTapConnection implements EpnTapInterface { throws VOTableException { String query = String.format(enumeratedQuery.toString(), schemaName); VOTableCtrl voTableCtrl = new VOTableCtrl(); - voTableCtrl.newVOTable(tapURL, query); + voTableCtrl.acquireVOTable(tapURL, query, false); VOTableData data = voTableCtrl.getVOTableData(); Debug.writeObject("data", data); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java index df8be4c..6494475 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java @@ -18,6 +18,9 @@ package eu.omp.irap.vespa.epntapclient; import java.util.logging.Logger; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + import com.google.gson.Gson; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelCtrl; @@ -46,12 +49,27 @@ public class EpnTapMainApp { * @param args The program arguments (not used). */ public static void main(final String[] args) { + // RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager()); LOGGER.info("Lauching EPNTAP app with arguments: " + new Gson().toJson(args)); if (args.length != 0) { System.console().writer().println(WRONG_COMMAND); return; } - MainPanelCtrl guiCtrl = new MainPanelCtrl(); - guiCtrl.readServices(); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + MainPanelCtrl guiCtrl = new MainPanelCtrl(); + guiCtrl.acquireServices(); + JFrame frame = new JFrame("EpnTAP client"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setContentPane(guiCtrl.getView()); + frame.setVisible(true); + frame.setSize(800, 600); + frame.setLocationRelativeTo(null); + + } + }); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/EpnTapController.java b/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/EpnTapController.java index 794037d..154d1b4 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/EpnTapController.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/EpnTapController.java @@ -55,6 +55,17 @@ public abstract class EpnTapController { /** + * Get the services from the XML path or the targetURL / query. + * + * @throws VOTableException Can not read the services. + */ + public void acquireServices() throws VOTableException { + String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, + ServiceCore.EPNCORE); + getServicesCtrl().acquireVOTable(Consts.DEFAULT_REGISTRY_URL, query, true); + } + + /** * @return The request controller. */ public RequestCtrl getRequestCtrl() { @@ -83,37 +94,16 @@ public abstract class EpnTapController { } /** - * Get the services from the XML path or the targetURL / query. - * - * @throws VOTableException Can not read the services. - */ - public void readServices() throws VOTableException { - // Here getServicesCtrl() is used instead of class field servicesCtrl to get the - // subclass field, since subclasses overrides getServicesCtrl(). - String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, - ServiceCore.EPNCORE); - getServicesCtrl().newVOTable(Consts.DEFAULT_REGISTRY_URL, query); - } - - /** - * ... + * Send all the queries. * * @param services The services to send the queries. - * @throws VOTableException Can not update the VOTable. */ - public void sendQueries(ServicesList services) throws VOTableException { - // Here getRequestCtrl() and getResultsCtrl() are used instead of class fields requestCtrl - // and resultCtrl to get the subclass field, since subclasses overrides getRequestCtrl() and - // getResultsCtrl(). + public void sendQueries(ServicesList services) { List servicesUrls = services.getTargetUrls(); - LOGGER.info("Sending query(ies) on " + StringJoiner.join(servicesUrls)); + LOGGER.info("Sending query(ies) at " + StringJoiner.join(servicesUrls)); for (int i = 0; i < servicesUrls.size(); i++) { String query = getRequestCtrl().getQuery(services.getTableNames().get(i)); - if (i == 0) { - getResultsCtrl().newVOTable(servicesUrls.get(i), query); - } else { - getResultsCtrl().appendVOTable(servicesUrls.get(i), query); - } + getResultsCtrl().acquireVOTable(servicesUrls.get(i), query, i != 0); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/service/ServiceCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/service/ServiceCtrl.java index b3e276d..9e3cfd6 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/service/ServiceCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/epntap/service/ServiceCtrl.java @@ -152,7 +152,7 @@ public class ServiceCtrl { */ public static VOTABLE getVoTable(String query) throws VOTableException { VOTableCtrl voTableCtrl = new VOTableCtrl(); - voTableCtrl.newVOTable(Consts.DEFAULT_REGISTRY_URL, query); + voTableCtrl.acquireVOTable(Consts.DEFAULT_REGISTRY_URL, query, false); return voTableCtrl.getVOTable(); } @@ -173,10 +173,10 @@ public class ServiceCtrl { * @throws VOTableException Can not get the VOTable. */ public static VOTableData getVoTableData(VOTABLE voTable) throws VOTableException { - VOTableCtrl.checkVOTable(voTable); - + VOTableCtrl ctrl = new VOTableCtrl(); + ctrl.acquireVOTable(voTable, false); Table table = (Table) voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0); - VOTableDataParser dataParser = new VOTableDataParser(table); + VOTableDataParser dataParser = new VOTableDataParser("Services list", table); dataParser.parseData(); return dataParser.getData(); } 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 ff9e49a..d3b98a9 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,21 +16,19 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; -import java.awt.Cursor; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JFrame; import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; import eu.omp.irap.vespa.epntapclient.epntap.EpnTapController; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelCtrl; import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelCtrl; -import eu.omp.irap.vespa.votable.votable.VOTableException; /** * @author N. Jourdane @@ -40,9 +38,6 @@ 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. */ RequestPanelCtrl requestPanelCtrl; @@ -64,40 +59,27 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener resultsPanelCtrl = new ResultPanelCtrl(this); requestPanelCtrl = new RequestPanelCtrl(this); view = new MainPanelView(this); - SwingUtilities.invokeLater(run("EPN-TAP client", view)); } - /** - * Creates runnable used to run the application GUI. - * - * @param title The title of the application window. - * @param view The view of the VOTable, created by the VOTableController. - * @return The runnable. - */ - private static Runnable run(final String title, final MainPanelView view) { - return new Runnable() { - - @Override - public void run() { - JFrame frame = new JFrame(title); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setContentPane(view); - frame.setVisible(true); - frame.pack(); - frame.setLocationRelativeTo(null); - } - }; + @Override + public void acquireServices() { + servicesPanelCtrl.acquire(); } @Override - public void displayError(String message, Exception e) { - LOGGER.log(Level.SEVERE, message, e); - JOptionPane.showMessageDialog(view, e.getMessage(), message, JOptionPane.ERROR_MESSAGE); + public void displayError(String message, Exception error) { + LOGGER.log(Level.SEVERE, message, error); + JOptionPane.showMessageDialog(view, error.getMessage(), message, JOptionPane.ERROR_MESSAGE); } @Override - public void displayInfo(String message) { - view.getResultsPanel().setStatusBarText(message); + public void displayInfo(String shortMessage, String detailledMessage) { + if (detailledMessage == null) { + LOGGER.info(shortMessage); + } else { + LOGGER.info(shortMessage + ": " + detailledMessage); + } + view.getStatusBarPanelView().setStatusBarText(shortMessage); } /** @@ -132,57 +114,22 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener } @Override - public void readServices() { + public void saveCurrentVOTable(File file) { try { - super.readServices(); - } catch (VOTableException e) { - displayError("Can not read services.", e); + Files.copy(Paths.get(resultsPanelCtrl.getVOTablePath()), + Paths.get(file.getAbsolutePath())); + } catch (IOException e) { + displayError("Can not save the VOTable file.", e); } - view.getServicesPanel().fillTable(servicesPanelCtrl.getVOTableData()); } @Override - public void sendQuery() { - // 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(); + public void sendQueries() { + sendQueries(servicesPanelCtrl.getServices()); } @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()) { - String fName = new File(resultsPanelCtrl.getVOTablePath()).getName(); - resultsPanelCtrl.getView().addTable(fName, resultsPanelCtrl.getVOTableData()); - } - view.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - }; - } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java index dd75be6..8d5385d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelListener.java @@ -16,33 +16,39 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; +import java.io.File; + /** * @author N. Jourdane */ public interface MainPanelListener { /** - * Ask the main panel to open a pop-up and display the specified error. + * Display an error message to the user. * - * @param message A short message describing the error, which will be the pop-up title. - * @param e The error itself. + * @param message A short version of the message. + * @param error The exception related to the error. */ - void displayError(String message, Exception e); + void displayError(String message, Exception error); /** - * Display an informative message in the status bar. + * Display an informative message to the user. * - * @param message The message to display. + * @param shortMessage A short version of the message. + * @param detailledMessage The full message to display (optional, can be null). */ - void displayInfo(String message); + void displayInfo(String shortMessage, String detailledMessage); /** - * Ask the main panel to send the query. + * Ask the main panel to save the VOTable displayed in the focused tab on the result panel. + * + * @param file The file specified by the user on the FileChooser popup. */ - void sendQuery(); + void saveCurrentVOTable(File file); - /** - * Ask the main panel to update the query. - */ + /** Ask the main panel to send the query. */ + void sendQueries(); + + /** Ask the main panel to update the query. */ void updateQuery(); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java index a29b260..96907ee 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/mainpanel/MainPanelView.java @@ -26,6 +26,7 @@ import javax.swing.JSplitPane; import eu.omp.irap.vespa.epntapclient.gui.requestpanel.RequestPanelView; import eu.omp.irap.vespa.epntapclient.gui.resultpanel.ResultPanelView; import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelView; +import eu.omp.irap.vespa.epntapclient.gui.statusbarpanel.StatusBarPanelView; /** * The main view of the application, which manage all the other views. @@ -34,7 +35,7 @@ import eu.omp.irap.vespa.epntapclient.gui.servicespanel.ServicesPanelView; */ public class MainPanelView extends JPanel { - /** The serial version UID. */ + /** The default serial version UID. */ private static final long serialVersionUID = 1L; /** The JPanel where the user build the query. */ @@ -46,6 +47,9 @@ public class MainPanelView extends JPanel { /** The JPanel where the list of services is displayed. */ private ServicesPanelView servicesPanel; + /** The JPanel where the list of services is displayed. */ + private StatusBarPanelView statusBarPanel; + /** * The main view constructor, which create all the panels. @@ -57,6 +61,7 @@ public class MainPanelView extends JPanel { servicesPanel = mainPanelCtrl.getServicesCtrl().getView(); resultPanel = mainPanelCtrl.getResultsCtrl().getView(); requestPanel = mainPanelCtrl.getRequestCtrl().getView(); + statusBarPanel = new StatusBarPanelView(); buildMainView(); } @@ -67,8 +72,7 @@ public class MainPanelView extends JPanel { * @param message The message of the error. */ public void displayError(String title, String message) { - JOptionPane.showMessageDialog(this, message, title, - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this, message, title, JOptionPane.ERROR_MESSAGE); } /** @@ -93,6 +97,13 @@ public class MainPanelView extends JPanel { } /** + * @return The view of the status bar panel. + */ + public StatusBarPanelView getStatusBarPanelView() { + return statusBarPanel; + } + + /** * Build the panel and add GUI elements on it. */ private void buildMainView() { @@ -102,6 +113,7 @@ public class MainPanelView extends JPanel { requestPanel); JSplitPane mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, northPanel, resultPanel); add(mainPanel, BorderLayout.CENTER); + add(statusBarPanel, BorderLayout.SOUTH); setSizes(); revalidate(); diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java index fc48c44..ca6f80d 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelCtrl.java @@ -16,6 +16,8 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel; +import java.io.File; + import eu.omp.irap.vespa.epntapclient.epntap.request.RequestCtrl; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; @@ -62,9 +64,14 @@ public class RequestPanelCtrl extends RequestCtrl implements RequestPanelListene } @Override + public void onSaveButtonClicked(File file) { + listener.saveCurrentVOTable(file); + } + + @Override public void onSendButtonClicked() { setQuery(view.getQueryArea().getText()); - listener.sendQuery(); + listener.sendQueries(); } /** diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java index ba22ffb..658b4ed 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelListener.java @@ -16,20 +16,23 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel; +import java.io.File; + /** * @author N. Jourdane */ public interface RequestPanelListener { /** - * Method called when the user remove a parameter with a parameter field. + * This method is called when the user remove a parameter with a parameter field. * * @param paramName The name of the removed parameter */ void onParameterRemoved(String paramName); /** - * Method called when the user change a parameter (add or update) with a parameter field. + * This method is called when the user change a parameter (add or update) with a parameter + * field. * * @param paramName The name of the changed parameter. * @param paramValue The new value of the parameter. @@ -37,7 +40,15 @@ public interface RequestPanelListener { void onParameterUpdated(String paramName, Object paramValue); /** - * Method called when the used click on the 'Send query' button. + * This method is called when the user clicks on the download button. + * + * @param file The file selected by the user in the FileChooser pop-up, corresponding to the + * place where save the VOTable. + */ + void onSaveButtonClicked(File file); + + /** + * This method is called when the used click on the 'Send query' button. */ void onSendButtonClicked(); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java index 2d265ec..d974f91 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/RequestPanelView.java @@ -26,6 +26,7 @@ import java.util.List; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JTextArea; @@ -45,9 +46,12 @@ public class RequestPanelView extends JPanel { /** The height of the buttons panel. */ private static final int BUTTON_PANEL_HEIGHT = 20; - /** The serial version UID. */ + /** The default serial version UID. */ private static final long serialVersionUID = 1L; + /** The GUI element of the button to move the file in the specified location. */ + private JButton buttonSave; + /** The GUI element of the button to send the query. */ private JButton buttonSend; @@ -86,7 +90,7 @@ public class RequestPanelView extends JPanel { /** * Get the GUI element of the send button. If it doesn't exist, create it. * - * @return The button. + * @return The button to download and parse the VOTable. */ public JButton getButtonSend() { if (buttonSend == null) { @@ -160,9 +164,9 @@ public class RequestPanelView extends JPanel { } /** - * Get the GUI element of the target name field. If it doesn't exist, create it. + * Get the field where the user enter the target name. If it doesn't exist, create it. * - * @return The target name field. + * @return The TargetNameField object of the field. */ public TargetNameField getTargetNameField() { if (targetNameField == null) { @@ -186,6 +190,27 @@ public class RequestPanelView extends JPanel { } /** + * Get the button to save the VOTable in the specified location. If it doesn't exist, create it. + * + * @return The JButton object. + */ + public JButton saveFileButton() { + if (buttonSave == null) { + buttonSave = new JButton("Save File"); + buttonSave.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent evt) { + final JFileChooser fc = new JFileChooser(); + fc.showOpenDialog(RequestPanelView.this); + listener.onSaveButtonClicked(fc.getSelectedFile()); + } + }); + } + return buttonSave; + } + + /** * Update the query in the JTextArea. * * @param query The string literal to put in the text-area, which will override the old content. diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java index 5f48fa6..8335dad 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/requestpanel/paramfield/TargetNameField.java @@ -17,6 +17,7 @@ package eu.omp.irap.vespa.epntapclient.gui.requestpanel.paramfield; import java.awt.Dimension; +import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; @@ -93,6 +94,11 @@ public class TargetNameField extends ParamField implements TextFieldListener { } @Override + public void onSaveButtonClicked(File file) { + /** No SaveButtonClicked event, we just want the field itself. */ + } + + @Override public void onSendButtonClicked() { /** No SendButtonClicked event, we just want the field itself. */ } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java index 888d50c..61d91bb 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java @@ -16,16 +16,12 @@ package eu.omp.irap.vespa.epntapclient.gui.resultpanel; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.awt.Cursor; import java.util.logging.Logger; import eu.omp.irap.vespa.epntapclient.gui.mainpanel.MainPanelListener; import eu.omp.irap.vespa.votable.utils.StringJoiner; import eu.omp.irap.vespa.votable.votable.VOTableCtrl; -import eu.omp.irap.vespa.votable.votable.VOTableException; /** * @author N. Jourdane @@ -52,41 +48,38 @@ public class ResultPanelCtrl extends VOTableCtrl implements ResultPanelListener view = new ResultPanelView(this); } - /** Download and parse a VOTable, then add the result to the current tab in the result panel. */ @Override - public void appendVOTable(String newTargetURL, String newQuery) { - try { - super.appendVOTable(newTargetURL, newQuery); - } catch (VOTableException e) { - listener.displayError("Can not update the VOTable.", e); - } - view.updateTable(voTableData); + public void displayError(String message, Exception error) { + listener.displayError(message, error); } @Override public void displayInfo(String shortMessage, String detailledMessage) { - super.displayInfo(shortMessage, detailledMessage); - listener.displayInfo(shortMessage); + listener.displayInfo(shortMessage, detailledMessage); + } + + @Override + public void fillTable() { + view.addTable(voTableData); } /** - * @return The view of the result panel. Used in MainPanelCtrl to add panels in the main window. + * @return The result panel view. */ public ResultPanelView getView() { return view; } @Override - public void onDownloadButtonClicked(File file) { - try { - Files.copy(Paths.get(voTablePath), Paths.get(file.getAbsolutePath())); - } catch (IOException e) { - listener.displayError("Can not save the VOTable file.", e); + public void onRowsSelected() { + if (view.getSelectedIndex() != -1) { + LOGGER.info("Selected row(s): " + StringJoiner.join(view.getSelectedRows())); } } @Override - public void onRowsSelected() { - LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows())); + public void setWaitCursor(boolean enableWaitcursor) { + int cursor = enableWaitcursor ? Cursor.WAIT_CURSOR : Cursor.DEFAULT_CURSOR; + view.setCursor(Cursor.getPredefinedCursor(cursor)); } } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java index 00cebe0..d1ff61b 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelListener.java @@ -16,8 +16,6 @@ package eu.omp.irap.vespa.epntapclient.gui.resultpanel; -import java.io.File; - import eu.omp.irap.vespa.votable.gui.VOTablePanelListener; /** @@ -25,11 +23,4 @@ import eu.omp.irap.vespa.votable.gui.VOTablePanelListener; */ public interface ResultPanelListener extends VOTablePanelListener { - /** - * This method is called when the user clicks on the download button. - * - * @param file The file selected by the user in the FileChooser pop-up, corresponding to the - * place where save the VOTable. - */ - public void onDownloadButtonClicked(File file); } diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java index ab96be9..2de2b93 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelView.java @@ -16,43 +16,21 @@ package eu.omp.irap.vespa.epntapclient.gui.resultpanel; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; import java.util.List; -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.JTabbedPane; -import eu.omp.irap.vespa.votable.gui.VOTablePanelListener; import eu.omp.irap.vespa.votable.gui.VOTablePanelView; import eu.omp.irap.vespa.votable.votabledata.VOTableData; /** * @author N. Jourdane */ -public class ResultPanelView extends JPanel implements VOTablePanelListener { +public class ResultPanelView extends JTabbedPane { - /** The serial version UID. */ + /** The default serial version UID. */ private static final long serialVersionUID = 1L; - /** The JPanel containing the buttons. */ - private JPanel buttonsPanel; - - /** The GUI element of the button to save the result of the query. */ - private JButton fileButton; - - /** A status bar, to display several informative messages. */ - private JLabel statusBar; - - private JTabbedPane tabbedPane; - - private List tablePanels; - /** The listener of the result panel. */ ResultPanelListener listener; @@ -65,7 +43,6 @@ public class ResultPanelView extends JPanel implements VOTablePanelListener { */ public ResultPanelView(ResultPanelListener listener) { this.listener = listener; - tablePanels = new ArrayList<>(); buildResultPanel(); } @@ -74,63 +51,24 @@ public class ResultPanelView extends JPanel implements VOTablePanelListener { * * @param voTableData The VOTable data to add in a new tab. */ - public void addTable(String title, VOTableData voTableData) { - VOTablePanelView voTablePanel = new VOTablePanelView(this); + public void addTable(VOTableData voTableData) { + VOTablePanelView voTablePanel = new VOTablePanelView(listener); voTablePanel.fillTable(voTableData); - tablePanels.add(voTablePanel); - tabbedPane.add(title, voTablePanel); + addTab(voTableData.getTitle(), voTablePanel); } /** * Build the panel and add graphical elements to it. */ public void buildResultPanel() { - tabbedPane = new JTabbedPane(); - JPanel bottomBar = new JPanel(); - bottomBar.setLayout(new BorderLayout()); - bottomBar.add(getStatusBar(), BorderLayout.CENTER); - bottomBar.add(getButtonsPanel(), BorderLayout.EAST); - - add(tabbedPane, BorderLayout.CENTER); - add(bottomBar, BorderLayout.SOUTH); + // setLayout(new BorderLayout()); } /** - * Create if necessary the buttons panel, then return it. - * - * @return the buttons panel. + * @return The panel inside the current active tab. */ - public JPanel getButtonsPanel() { - if (buttonsPanel == null) { - buttonsPanel = new JPanel(); - buttonsPanel.add(getFileButton()); - } - return buttonsPanel; - } - public VOTablePanelView getCurrentTablePanel() { - return tablePanels.get(getSelectedTab()); - } - - /** - * Returns the button to save the VOTable, create it if doesn't exist. - * - * @return The button to save the VOTable. - */ - public JButton getFileButton() { - if (fileButton == null) { - fileButton = new JButton("Get File"); - fileButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent evt) { - final JFileChooser fc = new JFileChooser(); - fc.showOpenDialog(ResultPanelView.this); - listener.onDownloadButtonClicked(fc.getSelectedFile()); - } - }); - } - return fileButton; + return (VOTablePanelView) getComponentAt(getSelectedTab()); } /** @@ -144,31 +82,7 @@ public class ResultPanelView extends JPanel implements VOTablePanelListener { * @return The index of the selected tab. */ public int getSelectedTab() { - return tabbedPane.getSelectedIndex(); - } - - /** - * Returns the status bar, create it if doesn't exist. - * - * @return The status bar. - */ - public JLabel getStatusBar() { - if (statusBar == null) { - statusBar = new JLabel(""); - } - return statusBar; - } - - @Override - public void onRowsSelected() { - // Do nothing yet when a row is selected. - } - - /** - * @param infoText The text to display in the status-bar, which will override the old one. - */ - public void setStatusBarText(String infoText) { - getStatusBar().setText(infoText); + return getSelectedIndex(); } /** diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java index 316d188..a9d4be5 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/servicespanel/ServicesPanelCtrl.java @@ -16,6 +16,7 @@ package eu.omp.irap.vespa.epntapclient.gui.servicespanel; +import java.awt.Cursor; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -53,15 +54,31 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe public ServicesPanelCtrl(MainPanelListener listener) { this.listener = listener; services = new ServicesList(); - targetUrl = Consts.DEFAULT_REGISTRY_URL; - query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); view = new ServicesPanelView(this); } + /** + * Download and parse the list of services. + */ + public void acquire() { + String getServicesQuery = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, + ServiceCore.EPNCORE); + acquireVOTable(Consts.DEFAULT_REGISTRY_URL, getServicesQuery, false); + } + + @Override + public void displayError(String message, Exception error) { + listener.displayError(message, error); + } + @Override public void displayInfo(String shortMessage, String detailledMessage) { - super.displayInfo(shortMessage, detailledMessage); - listener.displayInfo(shortMessage); + listener.displayInfo(shortMessage, detailledMessage); + } + + @Override + public void fillTable() { + view.fillTable(voTableData); } /** @@ -99,8 +116,10 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe public void onServiceListUpdated() { String newTableName = view.getTableNameTextField().getText(); String newTargetUrl = view.getServiceUrlTextField().getText(); - List customTableNames = Arrays.asList(newTableName.split(CUSTOM_SERVICES_SEPARATOR)); - List customServicesUrls = Arrays.asList(newTargetUrl.split(CUSTOM_SERVICES_SEPARATOR)); + List customTableNames = Arrays + .asList(newTableName.split(CUSTOM_SERVICES_SEPARATOR)); + List customServicesUrls = Arrays + .asList(newTargetUrl.split(CUSTOM_SERVICES_SEPARATOR)); if (!newTableName.isEmpty() && !newTargetUrl.isEmpty() && customTableNames.size() == customServicesUrls.size()) { @@ -108,4 +127,10 @@ public class ServicesPanelCtrl extends VOTableCtrl implements ServicesPanelListe } listener.updateQuery(); } + + @Override + public void setWaitCursor(boolean enableWaitcursor) { + int cursor = enableWaitcursor ? Cursor.WAIT_CURSOR : Cursor.DEFAULT_CURSOR; + view.setCursor(Cursor.getPredefinedCursor(cursor)); + } } -- libgit2 0.21.2