JAL-3829 pulled out more of the FTS dependent parts of structurechooser
authorJim Procter <j.procter@dundee.ac.uk>
Thu, 26 Aug 2021 10:14:16 +0000 (11:14 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Mon, 30 Aug 2021 11:17:32 +0000 (12:17 +0100)
src/jalview/gui/StructureChooser.java
src/jalview/gui/StructureChooserQuerySource.java
src/jalview/jbgui/GStructureChooser.java

index 99f71dd..ebba2e5 100644 (file)
@@ -31,6 +31,7 @@ import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
+import jalview.fts.core.FTSDataColumnPreferences;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.service.pdb.PDBFTSRestClient;
@@ -80,7 +81,13 @@ public class StructureChooser extends GStructureChooser
 
   private Collection<FTSData> discoveredStructuresSet;
 
-  private StructureChooserQuerySource data = StructureChooserQuerySource.getPDBfts();
+  private StructureChooserQuerySource data;
+
+  @Override
+  protected FTSDataColumnPreferences getFTSDocFieldPrefs()
+  {
+    return data.getDocFieldPrefs();
+  }
 
   private String selectedPdbFileName;
 
@@ -93,11 +100,17 @@ public class StructureChooser extends GStructureChooser
   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
           AlignmentPanel ap)
   {
+    // which FTS engine to use
+    data = StructureChooserQuerySource
+            .getPDBfts();
+    initDialog();
+    
     this.ap = ap;
     this.selectedSequence = selectedSeq;
     this.selectedSequences = selectedSeqs;
     this.progressIndicator = (ap == null) ? null : ap.alignFrame;
     init();
+    
   }
 
   /**
@@ -162,8 +175,7 @@ public class StructureChooser extends GStructureChooser
 
         if (view.isLinkedWith(ap))
         {
-          targetView.insertItemAt(viewHandler,
-                  linkedViewsAt++);
+          targetView.insertItemAt(viewHandler, linkedViewsAt++);
         }
         else
         {
@@ -214,7 +226,7 @@ public class StructureChooser extends GStructureChooser
   void fetchStructuresMetaData()
   {
     long startTime = System.currentTimeMillis();
-    Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
+    Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
             .getStructureSummaryFields();
 
     discoveredStructuresSet = new LinkedHashSet<>();
@@ -222,14 +234,15 @@ public class StructureChooser extends GStructureChooser
 
     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
             .getSelectedItem());
-    
+
     for (SequenceI seq : selectedSequences)
     {
 
       FTSRestResponse resultList;
       try
       {
-        resultList = data.fetchStructuresMetaData(seq, wantedFields, selectedFilterOpt, !chk_invertFilter.isSelected());
+        resultList = data.fetchStructuresMetaData(seq, wantedFields,
+                selectedFilterOpt, !chk_invertFilter.isSelected());
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -249,7 +262,8 @@ public class StructureChooser extends GStructureChooser
     if (discoveredStructuresSet != null
             && !discoveredStructuresSet.isEmpty())
     {
-      getResultTable().setModel(data.getTableModel(discoveredStructuresSet));
+      getResultTable()
+              .setModel(data.getTableModel(discoveredStructuresSet));
       noOfStructuresFound = discoveredStructuresSet.size();
       mainFrame.setTitle(MessageManager.formatMessage(
               "label.structure_chooser_no_of_structures",
@@ -311,19 +325,19 @@ public class StructureChooser extends GStructureChooser
       {
         long startTime = System.currentTimeMillis();
         lbl_loading.setVisible(true);
-        Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
+        Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
                 .getStructureSummaryFields();
         Collection<FTSData> filteredResponse = new HashSet<>();
         HashSet<String> errors = new HashSet<>();
 
         for (SequenceI seq : selectedSequences)
         {
-          
+
           FTSRestResponse resultList;
           try
           {
-            resultList = data.selectFirstRankedQuery(seq, wantedFields, fieldToFilterBy,
-                    !chk_invertFilter.isSelected());
+            resultList = data.selectFirstRankedQuery(seq, wantedFields,
+                    fieldToFilterBy, !chk_invertFilter.isSelected());
 
           } catch (Exception e)
           {
@@ -346,7 +360,8 @@ public class StructureChooser extends GStructureChooser
           Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
           reorderedStructuresSet.addAll(filteredResponse);
           reorderedStructuresSet.addAll(discoveredStructuresSet);
-          getResultTable().setModel(data.getTableModel(reorderedStructuresSet));
+          getResultTable()
+                  .setModel(data.getTableModel(reorderedStructuresSet));
 
           FTSRestResponse.configureTableColumn(getResultTable(),
                   wantedFields, tempUserPrefs);
@@ -390,7 +405,8 @@ public class StructureChooser extends GStructureChooser
   @Override
   protected void pdbFromFile_actionPerformed()
   {
-    // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and StructureChooser
+    // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
+    // StructureChooser
     // works
     jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
             jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
@@ -452,8 +468,8 @@ public class StructureChooser extends GStructureChooser
     if (cachedPDBExist)
     {
       FilterOption cachedOption = new FilterOption(
-              MessageManager.getString("label.cached_structures"),
-              "-", VIEWS_LOCAL_PDB, false);
+              MessageManager.getString("label.cached_structures"), "-",
+              VIEWS_LOCAL_PDB, false);
       cmb_filterOption.addItem(cachedOption);
       cmb_filterOption.setSelectedItem(cachedOption);
     }
@@ -674,7 +690,7 @@ public class StructureChooser extends GStructureChooser
     }
     return found;
   }
-  
+
   /**
    * Handles the 'New View' action
    */
@@ -719,8 +735,7 @@ public class StructureChooser extends GStructureChooser
 
         if (currentView == VIEWS_FILTER)
         {
-          int pdbIdColIndex = restable.getColumn("PDB Id")
-                  .getModelIndex();
+          int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
           int refSeqColIndex = restable.getColumn("Ref Sequence")
                   .getModelIndex();
           int[] selectedRows = restable.getSelectedRows();
@@ -729,10 +744,10 @@ public class StructureChooser extends GStructureChooser
           List<SequenceI> selectedSeqsToView = new ArrayList<>();
           for (int row : selectedRows)
           {
-            String pdbIdStr = restable
-                    .getValueAt(row, pdbIdColIndex).toString();
-            SequenceI selectedSeq = (SequenceI) restable
-                    .getValueAt(row, refSeqColIndex);
+            String pdbIdStr = restable.getValueAt(row, pdbIdColIndex)
+                    .toString();
+            SequenceI selectedSeq = (SequenceI) restable.getValueAt(row,
+                    refSeqColIndex);
             selectedSeqsToView.add(selectedSeq);
             PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
             if (pdbEntry == null)
@@ -823,10 +838,8 @@ public class StructureChooser extends GStructureChooser
                           DataSourceType.FILE, selectedSequence, true,
                           Desktop.instance);
 
-          sViewer = launchStructureViewer(
-                  ssm, new PDBEntry[]
-                  { fileEntry }, ap,
-                  new SequenceI[]
+          sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
+                  ap, new SequenceI[]
                   { selectedSequence });
         }
         SwingUtilities.invokeLater(new Runnable()
@@ -881,8 +894,7 @@ public class StructureChooser extends GStructureChooser
    * @param ssm
    * @return
    */
-  StructureViewer getTargetedStructureViewer(
-          StructureSelectionManager ssm)
+  StructureViewer getTargetedStructureViewer(StructureSelectionManager ssm)
   {
     Object sv = targetView.getSelectedItem();
 
@@ -899,8 +911,7 @@ public class StructureChooser extends GStructureChooser
    * @return
    */
   private StructureViewer launchStructureViewer(
-          StructureSelectionManager ssm,
-          final PDBEntry[] pdbEntriesToView,
+          StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView,
           final AlignmentPanel alignPanel, SequenceI[] sequences)
   {
     long progressId = sequences.hashCode();
@@ -963,8 +974,9 @@ public class StructureChooser extends GStructureChooser
     }
     if (pdbEntriesToView.length > 1)
     {
-      setProgressBar(MessageManager.getString(
-              "status.fetching_3d_structures_for_selected_entries"),
+      setProgressBar(
+              MessageManager.getString(
+                      "status.fetching_3d_structures_for_selected_entries"),
               progressId);
       theViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
     }
@@ -972,7 +984,7 @@ public class StructureChooser extends GStructureChooser
     {
       setProgressBar(MessageManager.formatMessage(
               "status.fetching_3d_structures_for",
-              pdbEntriesToView[0].getId()),progressId);
+              pdbEntriesToView[0].getId()), progressId);
       theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
     }
     setProgressBar(null, progressId);
@@ -1017,7 +1029,8 @@ public class StructureChooser extends GStructureChooser
             && !discoveredStructuresSet.isEmpty();
   }
 
-  protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes this. 
+  protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes
+                               // this.
   // Doing a search for "1" or "1c" is valuable?
   // Those work but are enormously slow.
 
@@ -1025,53 +1038,54 @@ public class StructureChooser extends GStructureChooser
   protected void txt_search_ActionPerformed()
   {
     String text = txt_search.getText().trim();
-       if (text.length() >= PDB_ID_MIN) 
-    new Thread()
-    {
-
-       @Override
-      public void run()
+    if (text.length() >= PDB_ID_MIN)
+      new Thread()
       {
-        errorWarning.setLength(0);
-        isValidPBDEntry = false;
-        if (text.length() > 0)
+
+        @Override
+        public void run()
         {
-          // TODO move this pdb id search into the PDB specific FTSSearchEngine 
-          // for moment, it will work fine as is because it is self-contained
-          String searchTerm = text.toLowerCase();
-          searchTerm = searchTerm.split(":")[0];
-          // System.out.println(">>>>> search term : " + searchTerm);
-          List<FTSDataColumnI> wantedFields = new ArrayList<>();
-          FTSRestRequest pdbRequest = new FTSRestRequest();
-          pdbRequest.setAllowEmptySeq(false);
-          pdbRequest.setResponseSize(1);
-          pdbRequest.setFieldToSearchBy("(pdb_id:");
-          pdbRequest.setWantedFields(wantedFields);
-          pdbRequest.setSearchTerm(searchTerm + ")");
-          pdbRequest.setAssociatedSequence(selectedSequence);
-          FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
-          wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
-          FTSRestResponse resultList;
-          try
-          {
-            resultList = pdbRestClient.executeRequest(pdbRequest);
-          } catch (Exception e)
-          {
-            errorWarning.append(e.getMessage());
-            return;
-          } finally
-          {
-            validateSelections();
-          }
-          if (resultList.getSearchSummary() != null
-                  && resultList.getSearchSummary().size() > 0)
+          errorWarning.setLength(0);
+          isValidPBDEntry = false;
+          if (text.length() > 0)
           {
-            isValidPBDEntry = true;
+            // TODO move this pdb id search into the PDB specific
+            // FTSSearchEngine
+            // for moment, it will work fine as is because it is self-contained
+            String searchTerm = text.toLowerCase();
+            searchTerm = searchTerm.split(":")[0];
+            // System.out.println(">>>>> search term : " + searchTerm);
+            List<FTSDataColumnI> wantedFields = new ArrayList<>();
+            FTSRestRequest pdbRequest = new FTSRestRequest();
+            pdbRequest.setAllowEmptySeq(false);
+            pdbRequest.setResponseSize(1);
+            pdbRequest.setFieldToSearchBy("(pdb_id:");
+            pdbRequest.setWantedFields(wantedFields);
+            pdbRequest.setSearchTerm(searchTerm + ")");
+            pdbRequest.setAssociatedSequence(selectedSequence);
+            FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
+            wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
+            FTSRestResponse resultList;
+            try
+            {
+              resultList = pdbRestClient.executeRequest(pdbRequest);
+            } catch (Exception e)
+            {
+              errorWarning.append(e.getMessage());
+              return;
+            } finally
+            {
+              validateSelections();
+            }
+            if (resultList.getSearchSummary() != null
+                    && resultList.getSearchSummary().size() > 0)
+            {
+              isValidPBDEntry = true;
+            }
           }
+          validateSelections();
         }
-        validateSelections();
-      }
-    }.start();
+      }.start();
   }
 
   @Override
@@ -1218,4 +1232,11 @@ public class StructureChooser extends GStructureChooser
   {
     return sViewer == null ? null : sViewer.sview;
   }
+
+  @Override
+  protected void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs)
+  {
+    data.setDocFieldPrefs(newPrefs);
+    
+  }
 }
index c127a78..637f168 100644 (file)
@@ -16,6 +16,8 @@ import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
+import jalview.fts.core.FTSDataColumnPreferences;
+import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.service.pdb.PDBFTSRestClient;
@@ -34,6 +36,8 @@ public class StructureChooserQuerySource
 
   private FTSRestClientI pdbRestClient;
 
+  private FTSDataColumnPreferences docFieldPrefs;
+
   private static int MAX_QLENGTH = 7820;
 
   public StructureChooserQuerySource()
@@ -44,9 +48,22 @@ public class StructureChooserQuerySource
   {
     StructureChooserQuerySource pdbfts = new StructureChooserQuerySource();
     pdbfts.pdbRestClient = PDBFTSRestClient.getInstance();
+    pdbfts.docFieldPrefs = new FTSDataColumnPreferences(
+            PreferenceSource.STRUCTURE_CHOOSER,
+            PDBFTSRestClient.getInstance());
     return pdbfts;
   }
 
+  public FTSDataColumnPreferences getDocFieldPrefs()
+  {
+    return docFieldPrefs;
+  }
+
+  public void setDocFieldPrefs(FTSDataColumnPreferences docFieldPrefs)
+  {
+    this.docFieldPrefs = docFieldPrefs;
+  }
+
   /**
    * Builds a query string for a given sequences using its DBRef entries
    * 
@@ -289,4 +306,10 @@ public class StructureChooserQuerySource
             discoveredStructuresSet);
   }
 
+  public FTSDataColumnPreferences getInitialFieldPreferences()
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
 }
\ No newline at end of file
index b9c9267..d43495e 100644 (file)
@@ -161,9 +161,9 @@ public abstract class GStructureChooser extends JPanel
 
   protected JTabbedPane pnl_filter = new JTabbedPane();
 
-  protected FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
-          PreferenceSource.STRUCTURE_CHOOSER,
-          PDBFTSRestClient.getInstance());
+  protected abstract FTSDataColumnPreferences getFTSDocFieldPrefs();
+  protected abstract void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs);
+
 
   protected FTSDataColumnI[] previousWantedFields;
 
@@ -249,6 +249,10 @@ public abstract class GStructureChooser extends JPanel
 
   public GStructureChooser()
   {
+  }
+  protected void initDialog()
+  {
+
     try
     {
       jbInit();
@@ -261,7 +265,7 @@ public abstract class GStructureChooser extends JPanel
       e.printStackTrace();
     }
   }
-
+  
   // BH SwingJS optimization
   // (a) 100-ms interruptable timer for text entry -- BH 1/10/2019
   // (b) two-character minimum, at least for JavaScript.
@@ -596,7 +600,7 @@ public abstract class GStructureChooser extends JPanel
           btn_add.setVisible(false);
           btn_newView.setEnabled(false);
           btn_cancel.setVisible(false);
-          previousWantedFields = pdbDocFieldPrefs
+          previousWantedFields = getFTSDocFieldPrefs()
                   .getStructureSummaryFields()
                   .toArray(new FTSDataColumnI[0]);
         }
@@ -618,7 +622,7 @@ public abstract class GStructureChooser extends JPanel
     pnl_filter.addChangeListener(changeListener);
     pnl_filter.setPreferredSize(new Dimension(width, height));
     pnl_filter.add(foundStructureSummary, scrl_foundStructures);
-    pnl_filter.add(configureCols, pdbDocFieldPrefs);
+    pnl_filter.add(configureCols, getFTSDocFieldPrefs());
 
     JPanel pnl_locPDB = new JPanel(new BorderLayout());
     pnl_locPDB.add(scrl_localPDB);
@@ -683,7 +687,7 @@ protected void closeAction(int preferredHeight)
       return true;
     }
 
-    FTSDataColumnI[] currentWantedFields = pdbDocFieldPrefs
+    FTSDataColumnI[] currentWantedFields = getFTSDocFieldPrefs()
             .getStructureSummaryFields().toArray(new FTSDataColumnI[0]);
     return Arrays.equals(currentWantedFields, previousWantedFields) ? false
             : true;