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 1d8ac78..ff9e49a 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 @@ -17,6 +17,7 @@ package eu.omp.irap.vespa.epntapclient.gui.mainpanel; import java.awt.Cursor; +import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; @@ -177,7 +178,8 @@ public class MainPanelCtrl extends EpnTapController implements MainPanelListener @Override protected void done() { if (!isCancelled()) { - resultsPanelCtrl.getView().fillTable(resultsPanelCtrl.getVOTableData()); + 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/resultpanel/ResultPanelCtrl.java b/src/main/java/eu/omp/irap/vespa/epntapclient/gui/resultpanel/ResultPanelCtrl.java index 21d8236..888d50c 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 @@ -52,6 +52,17 @@ 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); + } + @Override public void displayInfo(String shortMessage, String detailledMessage) { super.displayInfo(shortMessage, detailledMessage); @@ -78,14 +89,4 @@ public class ResultPanelCtrl extends VOTableCtrl implements ResultPanelListener public void onRowsSelected() { LOGGER.info("Selected row: " + StringJoiner.join(view.getSelectedRows())); } - - @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.fillTable(voTableData); - } } 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 0b25fb3..ab96be9 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 @@ -19,34 +19,43 @@ 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 VOTablePanelView { +public class ResultPanelView extends JPanel implements VOTablePanelListener { /** The 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; - /** The JPanel containing the buttons. */ - private JPanel buttonsPanel; - /** * Method constructor which customize the result panel, but don't build it from scratch since @@ -55,24 +64,55 @@ public class ResultPanelView extends VOTablePanelView { * @param listener The listener of the result view. */ public ResultPanelView(ResultPanelListener listener) { - super(listener); this.listener = listener; + tablePanels = new ArrayList<>(); buildResultPanel(); } /** + * Create a new tab and add a new VOTable into it. + * + * @param voTableData The VOTable data to add in a new tab. + */ + public void addTable(String title, VOTableData voTableData) { + VOTablePanelView voTablePanel = new VOTablePanelView(this); + voTablePanel.fillTable(voTableData); + tablePanels.add(voTablePanel); + tabbedPane.add(title, 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); } /** + * Create if necessary the buttons panel, then return it. + * + * @return the buttons panel. + */ + 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. @@ -94,6 +134,20 @@ public class ResultPanelView extends VOTablePanelView { } /** + * @return The index of the selected tab. + */ + public List getSelectedRows() { + return getCurrentTablePanel().getSelectedRows(); + } + + /** + * @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. @@ -105,6 +159,11 @@ public class ResultPanelView extends VOTablePanelView { 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. */ @@ -113,15 +172,11 @@ public class ResultPanelView extends VOTablePanelView { } /** - * Create if necessary the buttons panel, then return it. + * Append data to the current tab. * - * @return the buttons panel. + * @param voTableData The VOTable data to add in the current tab. */ - public JPanel getButtonsPanel() { - if (buttonsPanel == null) { - buttonsPanel = new JPanel(); - buttonsPanel.add(getFileButton()); - } - return buttonsPanel; + public void updateTable(VOTableData voTableData) { + getCurrentTablePanel().fillTable(voTableData); } } -- libgit2 0.21.2