JAL-1668 added filtering and sorting capabilites
[jalview.git] / src / jalview / gui / PDBFetchPanel.java
index c7e5362..85231f7 100644 (file)
@@ -2,12 +2,14 @@ package jalview.gui;
 
 import jalview.jbgui.GPDBFetchPanel;
 import jalview.ws.dbsources.PDBRestClient;
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
 import jalview.ws.uimodel.PDBSearchRequest;
 import jalview.ws.uimodel.PDBSearchResponse;
-import jalview.ws.uimodel.PDBSummaryListModel;
-import jalview.ws.uimodel.PDBSummaryListModel.PDBDocField;
+import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import javax.swing.DefaultListModel;
@@ -18,11 +20,6 @@ public class PDBFetchPanel extends GPDBFetchPanel
 {
   private SequenceFetcher seqFetcher;
 
-  public enum FieldType
-  {
-    INT, STRING, BOOLEAN;
-  }
-
   public PDBFetchPanel()
   {
   }
@@ -48,19 +45,19 @@ public class PDBFetchPanel extends GPDBFetchPanel
   public void searchStringAction()
   {
     boolean allowEmptySequence = false;
-    jListSearchResult.setModel(new DefaultListModel<PDBSummaryListModel>());
+    jListSearchResult.setModel(new DefaultListModel<PDBResponseSummary>());
     mainFrame.setTitle("PDB Sequence Fetcher");
     if (search.getText().trim().length() > 0)
     {
       long startTime = System.currentTimeMillis();
       PDBRestClient pdbRestCleint = new PDBRestClient();
-      String searchTarget = ((PDBSearchOptionList) searchTargetOptions
+      String searchTarget = ((PDBDocField) searchTargetOptions
               .getSelectedItem()).getCode();
 
       PDBSearchRequest request = new PDBSearchRequest();
       request.setAllowEmptySeq(allowEmptySequence);
       request.setResponseSize(100);
-      request.setSearchTarget(searchTarget + ":");
+      request.setFieldToSearchBy(searchTarget + ":");
       request.setSearchTerm(search.getText());
       List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
       wantedFields.add(PDBDocField.MOLECULE_TYPE);
@@ -88,7 +85,7 @@ public class PDBFetchPanel extends GPDBFetchPanel
   @Override
   public void okActionPerformed()
   {
-    processPDBResponseData();
+    importSelectedPDBSequencesToAlignment();
   }
 
 
@@ -104,11 +101,11 @@ public class PDBFetchPanel extends GPDBFetchPanel
     mainFrame.dispose();
   }
 
-  private void processPDBResponseData()
+  private void importSelectedPDBSequencesToAlignment()
   {
     mainFrame.dispose();
     StringBuilder selectedIds = new StringBuilder();
-    for (PDBSummaryListModel dataSelected : jListSearchResult
+    for (PDBResponseSummary dataSelected : jListSearchResult
             .getSelectedValuesList())
     {
       selectedIds.append(";").append(dataSelected.getPdbId());
@@ -119,125 +116,31 @@ public class PDBFetchPanel extends GPDBFetchPanel
     worker.start();
   }
 
-  @SuppressWarnings("unchecked")
-  public void populateSearchOptionCombo()
-
+  public void populateSearchOptionComboBox()
   {
-    List<PDBSearchOptionList> searchOptions = new ArrayList<PDBSearchOptionList>();
-    searchOptions.add(new PDBSearchOptionList("PDB ID", "pdb_id",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("PFAM Name", "pfam_name",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("ALL", "text",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Molecule Type",
-            "molecule_type", FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Title", "title",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Molecule Name",
-            "molecule_name", FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Tax ID", "tax_id",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("UniProt Accession",
-            "uniprot_accession", FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Gene Name", "gene_name",
-            FieldType.STRING));
-    searchOptions.add(new PDBSearchOptionList("Genus", "genus",
-            FieldType.STRING));
-
-    java.util.Collections.sort(searchOptions);
-
-    for (PDBSearchOptionList pdbSO : searchOptions)
-    {
-      searchTargetOptions.addItem(pdbSO);
-    }
-  }
-
-  @SuppressWarnings("rawtypes")
-  public class PDBSearchOptionList implements Comparable
-  {
-    private String name;
-
-    private String code;
-
-    private boolean showInSummary;
-
-    private boolean searchFilter;
-
-    private FieldType type;
-
-    public PDBSearchOptionList(String name, String code, FieldType type)
-    {
-      this.name = name;
-      this.code = code;
-      this.type = type;
-    }
-
-    public String getName()
-    {
-      return name;
-    }
-
-    public void setName(String name)
-    {
-      this.name = name;
-    }
-
-    public String getCode()
-    {
-      return code;
-    }
-
-    public void setCode(String code)
-    {
-      this.code = code;
-    }
-
-    public boolean isShowInSummary()
-    {
-      return showInSummary;
-    }
-
-    public void setShowInSummary(boolean showInSummary)
-    {
-      this.showInSummary = showInSummary;
-    }
-
-    public boolean isSearchFilter()
-    {
-      return searchFilter;
-    }
-
-    public void setSearchFilter(boolean searchFilter)
-    {
-      this.searchFilter = searchFilter;
-    }
-
-    public FieldType getFieldType()
-    {
-      return type;
-    }
-
-    public void setFieldType(FieldType type)
-    {
-      this.type = type;
-    }
-
-    public String toString()
-    {
-      return name;
-    }
-
-    public PDBSearchOptionList()
-    {
-
-    }
+    List<PDBDocField> searchableTargets = new ArrayList<PDBDocField>();
+    searchableTargets.add(PDBDocField.PDB_ID);
+    searchableTargets.add(PDBDocField.PFAM_ACCESSION);
+    searchableTargets.add(PDBDocField.MOLECULE_TYPE);
+    searchableTargets.add(PDBDocField.MOLECULE_NAME);
+    searchableTargets.add(PDBDocField.UNIPROT_ACCESSION);
+    searchableTargets.add(PDBDocField.GENE_NAME);
+    searchableTargets.add(PDBDocField.GENUS);
+    searchableTargets.add(PDBDocField.ALL);
+
+    Collections.sort(searchableTargets, new Comparator<PDBDocField>()
+    {
+      @Override
+      public int compare(PDBDocField o1, PDBDocField o2)
+      {
+        return o1.getName().compareTo(o2.getName());
+      }
+    });
 
-    @Override
-    public int compareTo(Object o)
+    for (PDBDocField searchTarget : searchableTargets)
     {
-      return this.name.compareTo(((PDBSearchOptionList) o).getName());
+      searchTargetOptions.addItem(searchTarget);
     }
-
   }
+
 }