JAL-1745, JAL-1717 improvement to ensure cached PDB entries are unique within a seque...
[jalview.git] / src / jalview / gui / StructureChooser.java
index ff7cdcb..2944cd8 100644 (file)
@@ -165,7 +165,7 @@ public class StructureChooser extends GStructureChooser
               && !resultList.getSearchSummary().isEmpty())
       {
         discoveredStructuresSet.addAll(resultList.getSearchSummary());
-        updateSequenceDbRef(seq, resultList.getSearchSummary());
+        updateSequencePDBEntries(seq, resultList.getSearchSummary());
       }
     }
 
@@ -216,6 +216,7 @@ public class StructureChooser extends GStructureChooser
       {
         for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId())
         {
+
           String chain = pdbEntry.getChainCode() == null ? "_" : pdbEntry
                   .getChainCode();
           String[] pdbEntryRowData = new String[]
@@ -223,7 +224,10 @@ public class StructureChooser extends GStructureChooser
  chain,
               pdbEntry.getType(),
               pdbEntry.getFile() };
-          tableModel.addRow(pdbEntryRowData);
+          if (pdbEntry.getFile() != null)
+          {
+            tableModel.addRow(pdbEntryRowData);
+          }
           cachedEntryMap.put(pdbEntry.getId().toLowerCase(),
                   pdbEntry);
         }
@@ -233,7 +237,7 @@ public class StructureChooser extends GStructureChooser
   }
 
   /**
-   * Update the DBRef entry for a given sequence with values retrieved from
+   * Update the PDBEntry for a given sequence with values retrieved from
    * PDBResponseSummary
    * 
    * @param seq
@@ -241,15 +245,20 @@ public class StructureChooser extends GStructureChooser
    * @param responseSummaries
    *          a collection of PDBResponseSummary
    */
-  public void updateSequenceDbRef(SequenceI seq,
+  public void updateSequencePDBEntries(SequenceI seq,
           Collection<PDBResponseSummary> responseSummaries)
   {
     for (PDBResponseSummary response : responseSummaries)
     {
-      PDBEntry newEntry = new PDBEntry();
-      newEntry.setId(response.getPdbId());
-      newEntry.setType(PDBEntry.Type.PDB);
-      seq.getDatasetSequence().addPDBId(newEntry);
+      String pdbIdStr = response.getPdbId();
+      PDBEntry pdbEntry = cachedEntryMap.get(pdbIdStr.toLowerCase());
+      if (pdbEntry == null)
+      {
+        pdbEntry = new PDBEntry();
+        pdbEntry.setId(pdbIdStr);
+        pdbEntry.setType(PDBEntry.Type.PDB);
+      }
+      seq.getDatasetSequence().addPDBId(pdbEntry);
     }
   }