From bf5bc203579d7a291844f3b34d5e8431984ee8e2 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 3 Sep 2021 15:33:49 +0100 Subject: [PATCH] JAL-3829 refactored FilterOption provider to the StructureChooserQuerySource implementation - implementation now is completely independent of GUI code. --- src/jalview/gui/StructureChooser.java | 22 ++--- .../PDBStructureChooserQuerySource.java | 25 +++++- .../StructureChooserQuerySource.java | 16 ++-- .../ThreeDBStructureChooserQuerySource.java | 32 ++++++-- src/jalview/jbgui/FilterOption.java | 86 ++++++++++++++++++++ src/jalview/jbgui/GStructureChooser.java | 85 ------------------- test/jalview/gui/StructureChooserTest.java | 2 +- 7 files changed, 151 insertions(+), 117 deletions(-) create mode 100644 src/jalview/jbgui/FilterOption.java diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index ea2d50d..7a9da92 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -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 filters = data.getAvailableFilterOptions(VIEWS_FILTER); + for (FilterOption filter:filters) + { + cmb_filterOption.addItem(filter); + } } cmb_filterOption.addItem( new FilterOption(MessageManager.getString("label.enter_pdb_id"), diff --git a/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java index 3d2efb2..4dede2e 100644 --- a/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/PDBStructureChooserQuerySource.java @@ -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 getAvailableFilterOptions(String VIEWS_FILTER) + { + List filters = new ArrayList(); + 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 diff --git a/src/jalview/gui/structurechooser/StructureChooserQuerySource.java b/src/jalview/gui/structurechooser/StructureChooserQuerySource.java index 9861b1a..733e6fc 100644 --- a/src/jalview/gui/structurechooser/StructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/StructureChooserQuerySource.java @@ -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 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 getAvailableFilterOptions(String VIEWS_FILTER); } \ No newline at end of file diff --git a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java index 6c2123b..e188b23 100644 --- a/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java +++ b/src/jalview/gui/structurechooser/ThreeDBStructureChooserQuerySource.java @@ -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 getAvailableFilterOptions(String VIEWS_FILTER) + { + List filters = new ArrayList(); + 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 index 0000000..042df23 --- /dev/null +++ b/src/jalview/jbgui/FilterOption.java @@ -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 diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index d43495e..50c9a2e 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -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 * diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index 31f5f8b..c187c60 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -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; -- 1.7.10.2