JAL-1563 JAL-2091 Added total result count to Uniprot pagination, implemented caching...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 4 May 2016 11:57:56 +0000 (12:57 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 4 May 2016 11:57:56 +0000 (12:57 +0100)
src/jalview/fts/core/GFTSPanel.java
src/jalview/fts/service/pdb/PDBFTSPanel.java
src/jalview/fts/service/uniprot/UniProtFTSRestClient.java
src/jalview/fts/service/uniprot/UniprotFTSPanel.java
src/jalview/jbgui/GStructureChooser.java

index bc68667..3e4a1cd 100644 (file)
@@ -46,6 +46,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
 
 import javax.swing.ImageIcon;
@@ -140,6 +141,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   protected int pageLimit;
 
+  protected HashSet<String> paginatorCart = new HashSet<String>();
+
   private JTable tbl_summary = new JTable()
   {
     private boolean inLayout;
@@ -491,6 +494,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
                 if (!getTypedText().equalsIgnoreCase(lastSearchTerm))
                 {
                   searchAction(true);
+                  paginatorCart.clear();
                   lastSearchTerm = getTypedText();
                 }
               }
@@ -553,6 +557,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
           if (wantedFieldsUpdated())
           {
             searchAction(true);
+            paginatorCart.clear();
           }
           else
           {
@@ -647,7 +652,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   public void validateSelection()
   {
-    if (tbl_summary.getSelectedRows().length > 0)
+    if (tbl_summary.getSelectedRows().length > 0
+            || !paginatorCart.isEmpty())
     {
       btn_ok.setEnabled(true);
     }
@@ -824,6 +830,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
   @Override
   public void prevPageAction()
   {
+    updatePaginatorCart();
     if (offSet >= pageLimit)
     {
       offSet = offSet - pageLimit;
@@ -838,11 +845,73 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
   @Override
   public void nextPageAction()
   {
+    updatePaginatorCart();
     offSet = offSet + pageLimit;
     searchAction(false);
+  }
+
+  public void updatePaginatorCart()
+  {
+    int primaryKeyColIndex = 0;
+    JTable resultTable = getResultTable();
+    int totalRows = resultTable.getRowCount();
+    try
+    {
+      primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
+              wantedFields, false);
+    } catch (Exception e)
+    {
+      e.printStackTrace();
+    }
 
+    for (int row = 0; row < totalRows; row++)
+    {
+      String id = (String) resultTable.getValueAt(row, primaryKeyColIndex);
+      if (paginatorCart.contains(id))
+      {
+        paginatorCart.remove(id);
+      }
+    }
+    int[] selectedRows = resultTable.getSelectedRows();
+    for (int summaryRow : selectedRows)
+    {
+      String idStr = resultTable.getValueAt(summaryRow,
+              primaryKeyColIndex).toString();
+      paginatorCart.add(idStr);
+    }
+    // System.out.println("Paginator shopping cart size : "
+    // + paginatorCart.size());
   }
 
+  public void updateSummaryTableSelections()
+  {
+    JTable resultTable = getResultTable();
+    if (paginatorCart.isEmpty())
+    {
+      return;
+    }
+    int primaryKeyColIndex = 0;
+    try
+    {
+      primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
+              wantedFields, false);
+    } catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+    // System.out.println(">>>>>> got here : 1");
+    int totalRows = resultTable.getRowCount();
+    // resultTable.clearSelection();
+    for (int row = 0; row < totalRows; row++)
+    {
+      String id = (String) resultTable.getValueAt(row, primaryKeyColIndex);
+      if (paginatorCart.contains(id))
+      {
+        resultTable.addRowSelectionInterval(row, row);
+      }
+    }
+    validateSelection();
+  }
   public void refreshPaginatorState()
   {
     // System.out.println("resultSet count : " + resultSetCount);
index 4f308e3..74b7853 100644 (file)
@@ -107,7 +107,8 @@ public class PDBFTSPanel extends GFTSPanel
 
           long endTime = System.currentTimeMillis();
           totalResultSetCount = resultList.getNumberOfItemsFound();
-          resultSetCount = resultList.getSearchSummary().size();
+          resultSetCount = resultList.getSearchSummary() == null ? 0
+                  : resultList.getSearchSummary().size();
           String result = (resultSetCount > 0) ? MessageManager
                   .getString("label.results") : MessageManager
                   .getString("label.result");
@@ -129,6 +130,7 @@ public class PDBFTSPanel extends GFTSPanel
           
           setSearchInProgress(false);
           refreshPaginatorState();
+          updateSummaryTableSelections();
         }
       }
     }.start();
@@ -188,12 +190,17 @@ public class PDBFTSPanel extends GFTSPanel
       e.printStackTrace();
     }
     int[] selectedRows = getResultTable().getSelectedRows();
+    String searchTerm = txt_search.getText();
     for (int summaryRow : selectedRows)
     {
       String idStr = getResultTable().getValueAt(summaryRow,
               primaryKeyColIndex)
               .toString();
-      String searchTerm = txt_search.getText();
+      selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
+    }
+
+    for (String idStr : paginatorCart)
+    {
       selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
     }
 
index 8a21ffb..0447715 100644 (file)
@@ -99,10 +99,12 @@ public class UniProtFTSRestClient extends FTSRestClient
         throw new Exception(errorMessage);
 
       }
+      int xTotalResults = Integer.valueOf(clientResponse.getHeaders()
+              .get("X-Total-Results").get(0));
       clientResponse = null;
       client = null;
       return parseUniprotResponse(uniProtTabDelimittedResponseString,
-              uniportRestRequest);
+              uniportRestRequest, xTotalResults);
     } catch (Exception e)
     {
       String exceptionMsg = e.getMessage();
@@ -129,7 +131,7 @@ public class UniProtFTSRestClient extends FTSRestClient
 
   public FTSRestResponse parseUniprotResponse(
           String uniProtTabDelimittedResponseString,
-          FTSRestRequest uniprotRestRequest)
+          FTSRestRequest uniprotRestRequest, int xTotalResults)
   {
     FTSRestResponse searchResult = new FTSRestResponse();
     List<FTSData> result = null;
@@ -156,7 +158,7 @@ public class UniProtFTSRestClient extends FTSRestClient
         // System.out.println(dataRow);
         result.add(getFTSData(dataRow, uniprotRestRequest));
       }
-      searchResult.setNumberOfItemsFound(result.size());
+      searchResult.setNumberOfItemsFound(xTotalResults);
       searchResult.setSearchSummary(result);
     }
     return searchResult;
index acf2fb0..6c28ee5 100644 (file)
@@ -109,7 +109,9 @@ public class UniprotFTSPanel extends GFTSPanel
           }
 
           long endTime = System.currentTimeMillis();
-          resultSetCount = resultList.getNumberOfItemsFound();
+          totalResultSetCount = resultList.getNumberOfItemsFound();
+          resultSetCount = resultList.getSearchSummary() == null ? 0
+                  : resultList.getSearchSummary().size();
           String result = (resultSetCount > 0) ? MessageManager
                   .getString("label.results") : MessageManager
                   .getString("label.result");
@@ -117,7 +119,8 @@ public class UniprotFTSPanel extends GFTSPanel
           {
             updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
                     + " " + (offSet + 1) + " to "
-                    + (offSet + resultSetCount)
+                    + (offSet + resultSetCount) + " of "
+                    + totalResultSetCount
                     + " " + " (" + (endTime - startTime) + " milli secs)");
           }
           else
@@ -128,6 +131,7 @@ public class UniprotFTSPanel extends GFTSPanel
           }
           setSearchInProgress(false);
           refreshPaginatorState();
+          updateSummaryTableSelections();
         }
       }
     }.start();
@@ -190,7 +194,7 @@ public class UniprotFTSPanel extends GFTSPanel
               primaryKeyColIndex).toString();
       selectedIdsSet.add(idStr);
     }
-
+    selectedIdsSet.addAll(paginatorCart);
     for (String selectedId : selectedIdsSet)
     {
       selectedIds.append(selectedId).append(";");
index a5b03d8..a1aa0d3 100644 (file)
@@ -61,6 +61,7 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
+import javax.swing.table.TableColumn;
 
 @SuppressWarnings("serial")
 /**
@@ -158,8 +159,65 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
 
+  protected JTable tbl_local_pdb = new JTable();
+
+  protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
+
+  private JTabbedPane pnl_filter = new JTabbedPane();
+
+  private FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
+          PreferenceSource.STRUCTURE_CHOOSER,
+          PDBFTSRestClient.getInstance());
+
+  protected FTSDataColumnI[] previousWantedFields;
+
   protected JTable tbl_summary = new JTable()
   {
+    private boolean inLayout;
+
+    @Override
+    public boolean getScrollableTracksViewportWidth()
+    {
+      return hasExcessWidth();
+
+    }
+
+    @Override
+    public void doLayout()
+    {
+      if (hasExcessWidth())
+      {
+        autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
+      }
+      inLayout = true;
+      super.doLayout();
+      inLayout = false;
+      autoResizeMode = AUTO_RESIZE_OFF;
+    }
+
+    protected boolean hasExcessWidth()
+    {
+      return getPreferredSize().width < getParent().getWidth();
+    }
+
+    @Override
+    public void columnMarginChanged(ChangeEvent e)
+    {
+      if (isEditing())
+      {
+        removeEditor();
+      }
+      TableColumn resizingColumn = getTableHeader().getResizingColumn();
+      // Need to do this here, before the parent's
+      // layout manager calls getPreferredSize().
+      if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF
+              && !inLayout)
+      {
+        resizingColumn.setPreferredWidth(resizingColumn.getWidth());
+      }
+      resizeAndRepaint();
+    }
+
     @Override
     public String getToolTipText(MouseEvent evt)
     {
@@ -190,17 +248,6 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
 
-  protected JTable tbl_local_pdb = new JTable();
-
-  protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
-
-  private JTabbedPane pnl_filter = new JTabbedPane();
-
-  private FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
-          PreferenceSource.STRUCTURE_CHOOSER, PDBFTSRestClient.getInstance());
-
-  protected FTSDataColumnI[] previousWantedFields;
-
   public GStructureChooser()
   {
     try