From: gmungoc Date: Thu, 29 Sep 2016 11:56:51 +0000 (+0100) Subject: JAL-2237 apply default filter as sort in initial search X-Git-Tag: Release_2_10_0~29 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=32e495296239f89190828a16d8893c1e143e0a12;p=jalview.git JAL-2237 apply default filter as sort in initial search --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 7d8f1bf..af8b2f3 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -65,8 +65,6 @@ import javax.swing.table.AbstractTableModel; public class StructureChooser extends GStructureChooser implements IProgressIndicator { - private boolean structuresDiscovered = false; - private SequenceI selectedSequence; private SequenceI[] selectedSequences; @@ -103,6 +101,8 @@ public class StructureChooser extends GStructureChooser implements progressBar = new ProgressBar(this.statusPanel, this.statusBar); } + // ensure a filter option is in force for search + populateFilterComboBox(true); Thread discoverPDBStructuresThread = new Thread(new Runnable() { @Override @@ -117,7 +117,8 @@ public class StructureChooser extends GStructureChooser implements .getString("status.searching_for_pdb_structures"), startTime); fetchStructuresMetaData(); - populateFilterComboBox(); + // revise filter options if no results were found + populateFilterComboBox(isStructuresDiscovered()); updateProgressIndicator(null, startTime); mainFrame.setVisible(true); updateCurrentView(); @@ -161,6 +162,10 @@ public class StructureChooser extends GStructureChooser implements pdbRequest.setAllowEmptySeq(false); pdbRequest.setResponseSize(500); pdbRequest.setFieldToSearchBy("("); + FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption + .getSelectedItem()); + pdbRequest.setFieldToSortBy(selectedFilterOpt.getValue(), + !chk_invertFilter.isSelected()); pdbRequest.setWantedFields(wantedFields); pdbRequest.setSearchTerm(buildQuery(seq) + ")"); pdbRequest.setAssociatedSequence(seq); @@ -191,7 +196,6 @@ public class StructureChooser extends GStructureChooser implements getResultTable().setModel( FTSRestResponse.getTableModel(lastPdbRequest, discoveredStructuresSet)); - structuresDiscovered = true; noOfStructuresFound = discoveredStructuresSet.size(); mainFrame.setTitle(MessageManager.formatMessage( "label.structure_chooser_no_of_structures", @@ -524,10 +528,15 @@ public class StructureChooser extends GStructureChooser implements * Populates the filter combo-box options dynamically depending on discovered * structures */ - @Override - protected void populateFilterComboBox() + protected void populateFilterComboBox(boolean haveData) { - if (isStructuresDiscovered()) + /* + * temporarily suspend the change listener behaviour + */ + cmb_filterOption.removeItemListener(this); + + cmb_filterOption.removeAllItems(); + if (haveData) { cmb_filterOption.addItem(new FilterOption("Best Quality", "overall_quality", VIEWS_FILTER)); @@ -546,12 +555,13 @@ public class StructureChooser extends GStructureChooser implements VIEWS_FROM_FILE)); cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-", VIEWS_LOCAL_PDB)); + + cmb_filterOption.addItemListener(this); } /** * Updates the displayed view based on the selected filter option */ - @Override protected void updateCurrentView() { FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption @@ -963,12 +973,8 @@ public class StructureChooser extends GStructureChooser implements public boolean isStructuresDiscovered() { - return structuresDiscovered; - } - - public void setStructuresDiscovered(boolean structuresDiscovered) - { - this.structuresDiscovered = structuresDiscovered; + return discoveredStructuresSet != null + && !discoveredStructuresSet.isEmpty(); } public Collection getDiscoveredStructuresSet() diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index ec12b26..4d66a18 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -802,10 +802,6 @@ public abstract class GStructureChooser extends JPanel implements protected abstract void stateChanged(ItemEvent e); - protected abstract void updateCurrentView(); - - protected abstract void populateFilterComboBox(); - protected abstract void ok_ActionPerformed(); protected abstract void pdbFromFile_actionPerformed(); diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index bad536b..4c7df46 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -105,24 +105,16 @@ public class StructureChooserTest } @Test(groups = { "Functional" }) - public void populateFilterComboBoxTest() + public void populateFilterComboBoxTest() throws InterruptedException { SequenceI[] selectedSeqs = new SequenceI[] { seq }; StructureChooser sc = new StructureChooser(selectedSeqs, seq, null); - sc.populateFilterComboBox(); + sc.populateFilterComboBox(false); int optionsSize = sc.getCmbFilterOption().getItemCount(); assertEquals(3, optionsSize); // if structures are not discovered then don't // populate filter options - sc.setStructuresDiscovered(true); - sc.populateFilterComboBox(); - try - { - Thread.sleep(2000); - } catch (InterruptedException e) - { - e.printStackTrace(); - } + sc.populateFilterComboBox(true); optionsSize = sc.getCmbFilterOption().getItemCount(); assertTrue(optionsSize > 3); // if structures are found, filter options // should be populated