From e1976b4025f648431974e7ddcb2be93115688abd Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 29 Apr 2016 16:01:50 +0100 Subject: [PATCH] JAL-1563 Further increased swing timer for search textfield to 2500ms, removed 1200ms delay which was initially added to enable the search summary table initialise without interference, and implemented pagination for Uniprot FTS --- resources/fts/uniprot_data_columns.txt | 2 +- resources/lang/Messages.properties | 6 +- src/jalview/fts/api/GFTSPanelI.java | 6 ++ src/jalview/fts/core/FTSRestClient.java | 4 + src/jalview/fts/core/FTSRestRequest.java | 12 +++ src/jalview/fts/core/FTSRestResponse.java | 8 -- src/jalview/fts/core/GFTSPanel.java | 65 +++++++++++++++- src/jalview/fts/service/pdb/PDBFTSPanel.java | 20 +++++ .../fts/service/uniprot/UniProtFTSRestClient.java | 4 + .../fts/service/uniprot/UniprotFTSPanel.java | 79 ++++++++++++++++++-- 10 files changed, 189 insertions(+), 17 deletions(-) diff --git a/resources/fts/uniprot_data_columns.txt b/resources/fts/uniprot_data_columns.txt index 883f2f3..6c78c16 100644 --- a/resources/fts/uniprot_data_columns.txt +++ b/resources/fts/uniprot_data_columns.txt @@ -54,6 +54,7 @@ Mass spectrometry;comment(MASS SPECTROMETRY);String;g7;50;1000;95;false;false Polymorphism;comment(POLYMORPHISM);String;g7;50;1000;95;false;false RNA editing;comment(RNA EDITING);String;g7;50;1000;95;false;false Sequence caution;comment(SEQUENCE CAUTION);String;g7;50;1000;95;false;false +Status;reviewed;String;g6;50;100;95;true;true Length;length;int;g7;50;100;65;true;true Mass;mass;String;g7;50;100;80;false;true Sequence;sequence;String;g7;50;1000;95;false;true @@ -88,7 +89,6 @@ Caution;comment(CAUTION);String;g6;50;1000;95;false;false Miscellaneous [CC];comment(GENERAL);String;g6;50;1000;95;false;false Keywords;keywords;String;g6;50;1000;95;false;true Protein existence;existence;String;g6;50;1000;95;false;true -Status;reviewed;String;g6;50;100;95;true;true ALL;Search All;String;g7;50;1000;95;false;true; Subunit structure [CC];comment(SUBUNIT);String;g9;50;1000;95;false;false Interacts with;interactor;String;g9;50;1000;95;false;true diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 3c79b58..b68a358 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -790,7 +790,7 @@ label.select_backgroud_colour = Select Background Colour label.invalid_font = Invalid Font label.separate_multiple_accession_ids = Enter one or more accession IDs separated by a semi-colon ";" label.separate_multiple_query_values = Enter one or more {0}s separated by a semi-colon ";" -label.search_all = Enter one or more search values separated by a semi-colon ";" (Note: This Searches the entire PDB database) +label.search_all = Enter one or more search values separated by a semi-colon ";" (Note: This Searches the entire database) label.replace_commas_semicolons = Replace commas with semi-colons label.parsing_failed_syntax_errors_shown_below_param = Parsing failed. Syntax errors shown below {0} label.parsing_failed_unrecoverable_exception_thrown_param = \nParsing failed. An unrecoverable exception was thrown\:\n {0} @@ -1295,4 +1295,6 @@ info.error_creating_file = Error creating {0} file. label.run_groovy = Run Groovy console script label.run_groovy_tip = Run the script in the Groovy console over this alignment label.couldnt_run_groovy_script = Failed to run Groovy script -label.uniprot_sequence_fetcher = UniProt Sequence Fetcher \ No newline at end of file +label.uniprot_sequence_fetcher = UniProt Sequence Fetcher +action.next_page= >> +action.prev_page= << \ No newline at end of file diff --git a/src/jalview/fts/api/GFTSPanelI.java b/src/jalview/fts/api/GFTSPanelI.java index 46121fc..07ae5a1 100644 --- a/src/jalview/fts/api/GFTSPanelI.java +++ b/src/jalview/fts/api/GFTSPanelI.java @@ -92,4 +92,10 @@ public interface GFTSPanelI * @param isSearchInProgress */ public void setSearchInProgress(Boolean isSearchInProgress); + + public void prevPageAction(); + + public void nextPageAction(); + + public boolean isPaginationEnabled(); } diff --git a/src/jalview/fts/core/FTSRestClient.java b/src/jalview/fts/core/FTSRestClient.java index 7a4f72e..8bf1dc2 100644 --- a/src/jalview/fts/core/FTSRestClient.java +++ b/src/jalview/fts/core/FTSRestClient.java @@ -400,6 +400,10 @@ public abstract class FTSRestClient implements FTSRestClientI @Override public int getDefaultResponsePageSize() { + if (dataColumns == null || dataColumns.isEmpty()) + { + parseDataColumnsConfigFile(); + } return defaultResponsePageSize; } diff --git a/src/jalview/fts/core/FTSRestRequest.java b/src/jalview/fts/core/FTSRestRequest.java index 68068d7..164b102 100644 --- a/src/jalview/fts/core/FTSRestRequest.java +++ b/src/jalview/fts/core/FTSRestRequest.java @@ -56,6 +56,8 @@ public class FTSRestRequest private int responseSize; + private int offSet; + private boolean isSortAscending; private Collection wantedFields; @@ -176,4 +178,14 @@ public class FTSRestRequest { this.facetPivotMinCount = facetPivotMinCount; } + + public int getOffSet() + { + return offSet; + } + + public void setOffSet(int offSet) + { + this.offSet = offSet; + } } diff --git a/src/jalview/fts/core/FTSRestResponse.java b/src/jalview/fts/core/FTSRestResponse.java index c56b8c8..6cce2c4 100644 --- a/src/jalview/fts/core/FTSRestResponse.java +++ b/src/jalview/fts/core/FTSRestResponse.java @@ -135,14 +135,6 @@ public class FTSRestResponse public static void configureTableColumn(JTable tbl_summary, Collection wantedFields) { - try - { - // wait for table model initialisation to complete - Thread.sleep(1200); - } catch (InterruptedException e1) - { - e1.printStackTrace(); - } for (FTSDataColumnI wantedField : wantedFields) { try diff --git a/src/jalview/fts/core/GFTSPanel.java b/src/jalview/fts/core/GFTSPanel.java index 139dcb4..c9ee297 100644 --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@ -99,6 +99,10 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI private String lastSearchTerm = ""; + protected JButton btn_next_page = new JButton(); + + protected JButton btn_prev_page = new JButton(); + private JTable tbl_summary = new JTable() { private boolean inLayout; @@ -322,6 +326,63 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI } }); + btn_next_page.setEnabled(false); + btn_next_page.setFont(new java.awt.Font("Verdana", 0, 12)); + btn_next_page.setText(MessageManager.getString("action.next_page")); + btn_next_page.addActionListener(new java.awt.event.ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + nextPageAction(); + } + }); + btn_next_page.addKeyListener(new KeyAdapter() + { + @Override + public void keyPressed(KeyEvent evt) + { + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + nextPageAction(); + } + } + }); + + btn_prev_page.setEnabled(false); + btn_prev_page.setFont(new java.awt.Font("Verdana", 0, 12)); + btn_prev_page.setText(MessageManager.getString("action.prev_page")); + btn_prev_page.addActionListener(new java.awt.event.ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + prevPageAction(); + } + }); + btn_prev_page.addKeyListener(new KeyAdapter() + { + @Override + public void keyPressed(KeyEvent evt) + { + if (evt.getKeyCode() == KeyEvent.VK_ENTER) + { + prevPageAction(); + } + } + }); + + if (isPaginationEnabled()) + { + btn_prev_page.setVisible(true); + btn_next_page.setVisible(true); + } + else + { + btn_prev_page.setVisible(false); + btn_next_page.setVisible(false); + } + btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12)); btn_cancel.setText(MessageManager.getString("action.cancel")); btn_cancel.addActionListener(new java.awt.event.ActionListener() @@ -404,7 +465,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI }); final DeferredTextInputListener listener = new DeferredTextInputListener( - 1500, + 2500, new ActionListener() { @Override @@ -491,6 +552,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI pnl_inputs.add(txt_search); pnl_inputs.add(lbl_loading); pnl_inputs.add(lbl_warning); + pnl_inputs.add(btn_prev_page); + pnl_inputs.add(btn_next_page); this.setLayout(mainLayout); this.add(pnl_inputs, java.awt.BorderLayout.NORTH); diff --git a/src/jalview/fts/service/pdb/PDBFTSPanel.java b/src/jalview/fts/service/pdb/PDBFTSPanel.java index 826a505..ca1a902 100644 --- a/src/jalview/fts/service/pdb/PDBFTSPanel.java +++ b/src/jalview/fts/service/pdb/PDBFTSPanel.java @@ -232,4 +232,24 @@ public class PDBFTSPanel extends GFTSPanel } + @Override + public void prevPageAction() + { + // TODO pagination not yet implemented for PDB FTS + + } + + @Override + public void nextPageAction() + { + // TODO pagination not yet implemented for PDB FTS + + } + + @Override + public boolean isPaginationEnabled() + { + return false; + } + } diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index 2af1d56..57689f9 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -58,6 +58,9 @@ public class UniProtFTSRestClient extends FTSRestClient int responseSize = (uniportRestRequest.getResponseSize() == 0) ? getDefaultResponsePageSize() : uniportRestRequest.getResponseSize(); + int offSet = (uniportRestRequest.getOffSet() == 0) ? getDefaultResponsePageSize() + : uniportRestRequest.getOffSet(); + String query = uniportRestRequest.getFieldToSearchBy() .equalsIgnoreCase("Search All") ? uniportRestRequest .getSearchTerm() @@ -73,6 +76,7 @@ public class UniProtFTSRestClient extends FTSRestClient .queryParam("format", "tab") .queryParam("columns", wantedFields) .queryParam("limit", String.valueOf(responseSize)) + .queryParam("offset", String.valueOf(offSet)) .queryParam("sort", "score") .queryParam("query", query); // Execute the REST request diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index 21343d3..c40e1e8 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -40,6 +40,13 @@ public class UniprotFTSPanel extends GFTSPanel private String ftsFrameTitle = defaultFTSFrameTitle; + private int resultSetCount; + + private int offSet; + + private static int pageLimit = UniProtFTSRestClient.getInstance() + .getDefaultResponsePageSize(); + public UniprotFTSPanel(SequenceFetcher seqFetcher) { this.seqFetcher = seqFetcher; @@ -50,6 +57,12 @@ public class UniprotFTSPanel extends GFTSPanel @Override public void searchAction() { + offSet = 0; + executeSearch(); + } + + public void executeSearch() + { new Thread() { @Override @@ -72,6 +85,7 @@ public class UniprotFTSPanel extends GFTSPanel FTSRestRequest request = new FTSRestRequest(); request.setFieldToSearchBy(searchTarget); request.setSearchTerm(searchTerm); + request.setOffSet(offSet); request.setWantedFields(wantedFields); FTSRestClientI uniProtRestCleint = UniProtFTSRestClient .getInstance(); @@ -92,27 +106,82 @@ public class UniprotFTSPanel extends GFTSPanel { getResultTable().setModel( FTSRestResponse.getTableModel(request, - resultList.getSearchSummary())); + resultList.getSearchSummary())); FTSRestResponse.configureTableColumn(getResultTable(), wantedFields); getResultTable().setVisible(true); } long endTime = System.currentTimeMillis(); - int resultSetCount = resultList.getNumberOfItemsFound(); + resultSetCount = resultList.getNumberOfItemsFound(); String result = (resultSetCount > 1) ? MessageManager .getString("label.results") : MessageManager .getString("label.result"); - updateSearchFrameTitle(defaultFTSFrameTitle + " - " - + resultSetCount + " " + result + " (" - + (endTime - startTime) + " milli secs)"); + if (isPaginationEnabled() && resultSetCount > 1) + { + updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result + + " " + offSet + " to " + (offSet + resultSetCount) + + " " + " (" + (endTime - startTime) + " milli secs)"); + } + else + { + updateSearchFrameTitle(defaultFTSFrameTitle + " - " + + resultSetCount + " " + result + " (" + + (endTime - startTime) + " milli secs)"); + } setSearchInProgress(false); + refreshPaginatorState(); } } }.start(); } + + + public void refreshPaginatorState() + { + // System.out.println("resultSet count : " + resultSetCount); + // System.out.println("offSet : " + offSet); + // System.out.println("page limit : " + pageLimit); + btn_prev_page.setEnabled(false); + btn_next_page.setEnabled(false); + if (resultSetCount >= pageLimit) + { + btn_next_page.setEnabled(true); + } + if (offSet >= pageLimit) + { + btn_prev_page.setEnabled(true); + } + } + + @Override + public void prevPageAction() + { + if (offSet >= pageLimit) + { + offSet = offSet - pageLimit; + executeSearch(); + }else{ + refreshPaginatorState(); + } + } + + @Override + public void nextPageAction() + { + offSet = offSet + pageLimit; + executeSearch(); + + } + + @Override + public boolean isPaginationEnabled() + { + return true; + } + @Override public void okAction() { -- 1.7.10.2