JAL-2326 updated references of JOptionPane to JvOptionPane
[jalview.git] / src / jalview / gui / StructureChooser.java
index af8b2f3..0c3aa2a 100644 (file)
@@ -81,6 +81,10 @@ public class StructureChooser extends GStructureChooser implements
 
   private boolean isValidPBDEntry;
 
+  private boolean cachedPDBExists;
+
+  private static int MAX_QLENGHT = 7820;
+
   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
           AlignmentPanel ap)
   {
@@ -102,7 +106,7 @@ public class StructureChooser extends GStructureChooser implements
     }
 
     // ensure a filter option is in force for search
-    populateFilterComboBox(true);
+    populateFilterComboBox(true, cachedPDBExists);
     Thread discoverPDBStructuresThread = new Thread(new Runnable()
     {
       @Override
@@ -118,7 +122,7 @@ public class StructureChooser extends GStructureChooser implements
                 startTime);
         fetchStructuresMetaData();
         // revise filter options if no results were found
-        populateFilterComboBox(isStructuresDiscovered());
+        populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
         updateProgressIndicator(null, startTime);
         mainFrame.setVisible(true);
         updateCurrentView();
@@ -195,7 +199,7 @@ public class StructureChooser extends GStructureChooser implements
     {
       getResultTable().setModel(
               FTSRestResponse.getTableModel(lastPdbRequest,
-              discoveredStructuresSet));
+                      discoveredStructuresSet));
       noOfStructuresFound = discoveredStructuresSet.size();
       mainFrame.setTitle(MessageManager.formatMessage(
               "label.structure_chooser_no_of_structures",
@@ -212,9 +216,9 @@ public class StructureChooser extends GStructureChooser implements
         {
           errorMsg.append(error).append("\n");
         }
-        JOptionPane.showMessageDialog(this, errorMsg.toString(),
+        JvOptionPane.showMessageDialog(this, errorMsg.toString(),
                 MessageManager.getString("label.pdb_web-service_error"),
-                JOptionPane.ERROR_MESSAGE);
+                JvOptionPane.ERROR_MESSAGE);
       }
     }
   }
@@ -237,7 +241,7 @@ public class StructureChooser extends GStructureChooser implements
         }
       }
     }
-
+    cachedPDBExists = !entries.isEmpty();
     PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
     tbl_local_pdb.setModel(tableModelx);
   }
@@ -257,17 +261,16 @@ public class StructureChooser extends GStructureChooser implements
     StringBuilder queryBuilder = new StringBuilder();
     Set<String> seqRefs = new LinkedHashSet<String>();
 
-    if (seq.getAllPDBEntries() != null)
+    if (seq.getAllPDBEntries() != null
+            && queryBuilder.length() < MAX_QLENGHT)
     {
       for (PDBEntry entry : seq.getAllPDBEntries())
       {
         if (isValidSeqName(entry.getId()))
         {
           queryBuilder.append("pdb_id:")
-                  .append(entry.getId().toLowerCase())
-                  .append(" OR ");
+                  .append(entry.getId().toLowerCase()).append(" OR ");
           isPDBRefsFound = true;
-          // seqRefs.add(entry.getId());
         }
       }
     }
@@ -276,13 +279,13 @@ public class StructureChooser extends GStructureChooser implements
     {
       for (DBRefEntry dbRef : seq.getDBRefs())
       {
-        if (isValidSeqName(getDBRefId(dbRef)))
+        if (isValidSeqName(getDBRefId(dbRef))
+                && queryBuilder.length() < MAX_QLENGHT)
         {
           if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
           {
             queryBuilder.append("uniprot_accession:")
-                    .append(getDBRefId(dbRef))
-                    .append(" OR ");
+                    .append(getDBRefId(dbRef)).append(" OR ");
             queryBuilder.append("uniprot_id:").append(getDBRefId(dbRef))
                     .append(" OR ");
             isUniProtRefsFound = true;
@@ -291,8 +294,7 @@ public class StructureChooser extends GStructureChooser implements
           {
 
             queryBuilder.append("pdb_id:")
-                    .append(getDBRefId(dbRef).toLowerCase())
-                    .append(" OR ");
+                    .append(getDBRefId(dbRef).toLowerCase()).append(" OR ");
             isPDBRefsFound = true;
           }
           else
@@ -347,7 +349,6 @@ public class StructureChooser extends GStructureChooser implements
             .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
   }
 
-
   /**
    * Ensures sequence ref names are not less than 3 characters and does not
    * contain a database name
@@ -458,8 +459,8 @@ public class StructureChooser extends GStructureChooser implements
           reorderedStructuresSet.addAll(filteredResponse);
           reorderedStructuresSet.addAll(discoveredStructuresSet);
           getResultTable().setModel(
-                  FTSRestResponse.getTableModel(
-                  lastPdbRequest, reorderedStructuresSet));
+                  FTSRestResponse.getTableModel(lastPdbRequest,
+                          reorderedStructuresSet));
 
           FTSRestResponse.configureTableColumn(getResultTable(),
                   wantedFields, tempUserPrefs);
@@ -483,11 +484,11 @@ public class StructureChooser extends GStructureChooser implements
             {
               errorMsg.append(error).append("\n");
             }
-            JOptionPane.showMessageDialog(
+            JvOptionPane.showMessageDialog(
                     null,
                     errorMsg.toString(),
                     MessageManager.getString("label.pdb_web-service_error"),
-                    JOptionPane.ERROR_MESSAGE);
+                    JvOptionPane.ERROR_MESSAGE);
           }
         }
 
@@ -528,7 +529,8 @@ public class StructureChooser extends GStructureChooser implements
    * Populates the filter combo-box options dynamically depending on discovered
    * structures
    */
-  protected void populateFilterComboBox(boolean haveData)
+  protected void populateFilterComboBox(boolean haveData,
+          boolean cachedPDBExists)
   {
     /*
      * temporarily suspend the change listener behaviour
@@ -553,8 +555,14 @@ public class StructureChooser extends GStructureChooser implements
             VIEWS_ENTER_ID));
     cmb_filterOption.addItem(new FilterOption("From File", "-",
             VIEWS_FROM_FILE));
-    cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
-            VIEWS_LOCAL_PDB));
+    FilterOption cachedOption = new FilterOption("Cached PDB Entries", "-",
+            VIEWS_LOCAL_PDB);
+    cmb_filterOption.addItem(cachedOption);
+
+    if (/*!haveData &&*/cachedPDBExists)
+    {
+      cmb_filterOption.setSelectedItem(cachedOption);
+    }
 
     cmb_filterOption.addItemListener(this);
   }
@@ -898,9 +906,9 @@ public class StructureChooser extends GStructureChooser implements
         }
         if (seq.getPrimaryDBRefs().size() == 0)
         {
-            seqsWithoutSourceDBRef.add(seq);
-            continue;
-          }
+          seqsWithoutSourceDBRef.add(seq);
+          continue;
+        }
       }
       if (!seqsWithoutSourceDBRef.isEmpty())
       {
@@ -1003,8 +1011,7 @@ public class StructureChooser extends GStructureChooser implements
           pdbRequest.setResponseSize(1);
           pdbRequest.setFieldToSearchBy("(pdb_id:");
           pdbRequest.setWantedFields(wantedFields);
-          pdbRequest
-.setSearchTerm(searchTerm + ")");
+          pdbRequest.setSearchTerm(searchTerm + ")");
           pdbRequest.setAssociatedSequence(selectedSequence);
           pdbRestCleint = PDBFTSRestClient.getInstance();
           wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());