JAL-3829 refactored FilterOption provider to the StructureChooserQuerySource implemen...
authorJim Procter <j.procter@dundee.ac.uk>
Fri, 3 Sep 2021 14:33:49 +0000 (15:33 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Fri, 3 Sep 2021 14:33:49 +0000 (15:33 +0100)
src/jalview/gui/StructureChooser.java
src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java
src/jalview/gui/structurechooser/StructureChooserQuerySource.java
src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java
src/jalview/jbgui/FilterOption.java [new file with mode: 0644]
src/jalview/jbgui/GStructureChooser.java
test/jalview/gui/StructureChooserTest.java

index ea2d50d..7a9da92 100644 (file)
@@ -38,8 +38,8 @@ import jalview.fts.service.pdb.PDBFTSRestClient;
 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
 import jalview.gui.structurechooser.StructureChooserQuerySource;
 import jalview.io.DataSourceType;
+import jalview.jbgui.FilterOption;
 import jalview.jbgui.GStructureChooser;
-import jalview.jbgui.GStructureChooser.FilterOption;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
@@ -450,21 +450,11 @@ public class StructureChooser extends GStructureChooser
     cmb_filterOption.removeAllItems();
     if (haveData)
     {
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.best_quality"),
-              "overall_quality", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.best_resolution"),
-              "resolution", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_protein_chain"),
-              "number_of_protein_chains", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_bound_molecules"),
-              "number_of_bound_molecules", VIEWS_FILTER, false));
-      cmb_filterOption.addItem(new FilterOption(
-              MessageManager.getString("label.most_polymer_residues"),
-              "number_of_polymer_residues", VIEWS_FILTER, true));
+      List<FilterOption> filters = data.getAvailableFilterOptions(VIEWS_FILTER);
+      for (FilterOption filter:filters)
+      {
+        cmb_filterOption.addItem(filter);
+      }
     }
     cmb_filterOption.addItem(
             new FilterOption(MessageManager.getString("label.enter_pdb_id"),
index 3d2efb2..4dede2e 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.gui.structurechooser;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -22,7 +23,8 @@ import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
 import jalview.fts.core.FTSRestRequest;
 import jalview.fts.core.FTSRestResponse;
 import jalview.fts.service.pdb.PDBFTSRestClient;
-import jalview.jbgui.GStructureChooser.FilterOption;
+import jalview.jbgui.FilterOption;
+import jalview.util.MessageManager;
 
 /**
  * logic for querying the PDBe API for structures of sequences
@@ -229,6 +231,27 @@ public class PDBStructureChooserQuerySource
     lastPdbRequest = pdbRequest;
     return resultList;
   }
+  public List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER)
+  {
+    List<FilterOption> filters = new ArrayList<FilterOption>();
+    filters.add(new FilterOption(
+            MessageManager.getString("label.best_quality"),
+            "overall_quality", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.best_resolution"),
+            "resolution", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_protein_chain"),
+            "number_of_protein_chains", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_bound_molecules"),
+            "number_of_bound_molecules", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_polymer_residues"),
+            "number_of_polymer_residues", VIEWS_FILTER, true));
+  
+    return filters;
+  }
 
   /**
    * FTSRestClient specific query builder to pick top ranked entry from a
index 9861b1a..733e6fc 100644 (file)
@@ -1,29 +1,23 @@
 package jalview.gui.structurechooser;
 
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JTable;
 import javax.swing.table.TableModel;
 
 import jalview.datamodel.DBRefEntry;
-import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 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;
-import jalview.jbgui.GStructureChooser.FilterOption;
+import jalview.jbgui.FilterOption;
 
 /**
  * logic for querying sources of structural data for structures of sequences
@@ -204,4 +198,12 @@ public abstract class StructureChooserQuerySource
   public abstract PDBEntry[] collectSelectedRows(JTable restable,
           int[] selectedRows, List<SequenceI> selectedSeqsToView);
 
+  /**
+   * @param VIEWS_FILTER
+   *          - a String key that can be used by the caller to tag the returned filter
+   *          options to distinguish them in a collection
+   * @return list of FilterOption - convention is that the last one in the list
+   *         will be constructed with 'addSeparator==true'
+   */
+  public abstract List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER);
 }
\ No newline at end of file
index 6c2123b..e188b23 100644 (file)
@@ -1,29 +1,26 @@
 package jalview.gui.structurechooser;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Objects;
 import java.util.Set;
 
 import javax.swing.JTable;
-import javax.swing.table.TableModel;
 
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
 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;
 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
-import jalview.jbgui.GStructureChooser.FilterOption;
+import jalview.jbgui.FilterOption;
+import jalview.util.MessageManager;
 
 /**
  * logic for querying the PDBe API for structures of sequences
@@ -169,7 +166,28 @@ public class ThreeDBStructureChooserQuerySource
     return pdbRequest;
   }
 
-
+@Override
+  public List<FilterOption> getAvailableFilterOptions(String VIEWS_FILTER)
+  {
+    List<FilterOption> filters = new ArrayList<FilterOption>();
+    filters.add(new FilterOption(
+            MessageManager.getString("label.best_quality"),
+            "overall_quality", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.best_resolution"),
+            "resolution", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_protein_chain"),
+            "number_of_protein_chains", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_bound_molecules"),
+            "number_of_bound_molecules", VIEWS_FILTER, false));
+    filters.add(new FilterOption(
+            MessageManager.getString("label.most_polymer_residues"),
+            "number_of_polymer_residues", VIEWS_FILTER, true));
+  
+    return filters;
+  }
   /**
    * FTSRestClient specific query builder to pick top ranked entry from a
    * fetchStructuresMetaData query
diff --git a/src/jalview/jbgui/FilterOption.java b/src/jalview/jbgui/FilterOption.java
new file mode 100644 (file)
index 0000000..042df23
--- /dev/null
@@ -0,0 +1,86 @@
+package jalview.jbgui;
+
+/**
+ * This inner class provides the data model for the structure filter combo-box
+ * 
+ * @author tcnofoegbu
+ *
+ */
+public class FilterOption
+{
+  private String name;
+
+  private String value;
+
+  private String view;
+
+  private boolean addSeparatorAfter;
+
+  /**
+   * Model for structure filter option
+   * 
+   * @param name
+   *          - the name of the Option
+   * @param value
+   *          - the value of the option
+   * @param view
+   *          - the category of the filter option
+   * @param addSeparatorAfter
+   *          - if true, a horizontal separator is rendered immediately after
+   *          this filter option, otherwise
+   */
+  public FilterOption(String name, String value, String view,
+          boolean addSeparatorAfter)
+  {
+    this.name = name;
+    this.value = value;
+    this.view = view;
+    this.addSeparatorAfter = addSeparatorAfter;
+  }
+
+  public String getName()
+  {
+    return name;
+  }
+
+  public void setName(String name)
+  {
+    this.name = name;
+  }
+
+  public String getValue()
+  {
+    return value;
+  }
+
+  public void setValue(String value)
+  {
+    this.value = value;
+  }
+
+  public String getView()
+  {
+    return view;
+  }
+
+  public void setView(String view)
+  {
+    this.view = view;
+  }
+
+  @Override
+  public String toString()
+  {
+    return this.name;
+  }
+
+  public boolean isAddSeparatorAfter()
+  {
+    return addSeparatorAfter;
+  }
+
+  public void setAddSeparatorAfter(boolean addSeparatorAfter)
+  {
+    this.addSeparatorAfter = addSeparatorAfter;
+  }
+}
\ No newline at end of file
index d43495e..50c9a2e 100644 (file)
@@ -704,91 +704,6 @@ protected void closeAction(int preferredHeight)
   }
 
   /**
-   * This inner class provides the data model for the structure filter combo-box
-   * 
-   * @author tcnofoegbu
-   *
-   */
-  public class FilterOption
-  {
-    private String name;
-
-    private String value;
-
-    private String view;
-
-    private boolean addSeparatorAfter;
-
-    /**
-     * Model for structure filter option
-     * 
-     * @param name
-     *          - the name of the Option
-     * @param value
-     *          - the value of the option
-     * @param view
-     *          - the category of the filter option
-     * @param addSeparatorAfter
-     *          - if true, a horizontal separator is rendered immediately after
-     *          this filter option, otherwise
-     */
-    public FilterOption(String name, String value, String view,
-            boolean addSeparatorAfter)
-    {
-      this.name = name;
-      this.value = value;
-      this.view = view;
-      this.addSeparatorAfter = addSeparatorAfter;
-    }
-
-    public String getName()
-    {
-      return name;
-    }
-
-    public void setName(String name)
-    {
-      this.name = name;
-    }
-
-    public String getValue()
-    {
-      return value;
-    }
-
-    public void setValue(String value)
-    {
-      this.value = value;
-    }
-
-    public String getView()
-    {
-      return view;
-    }
-
-    public void setView(String view)
-    {
-      this.view = view;
-    }
-
-    @Override
-    public String toString()
-    {
-      return this.name;
-    }
-
-    public boolean isAddSeparatorAfter()
-    {
-      return addSeparatorAfter;
-    }
-
-    public void setAddSeparatorAfter(boolean addSeparatorAfter)
-    {
-      this.addSeparatorAfter = addSeparatorAfter;
-    }
-  }
-
-  /**
    * This inner class provides the provides the data model for associate
    * sequence combo-box - cmb_assSeq
    * 
index 31f5f8b..c187c60 100644 (file)
@@ -32,7 +32,7 @@ import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
 import jalview.gui.structurechooser.StructureChooserQuerySource;
-import jalview.jbgui.GStructureChooser.FilterOption;
+import jalview.jbgui.FilterOption;
 import jalview.ws.params.InvalidArgumentException;
 
 import java.util.Collection;