From ee0f6c877392ffc2018ae1a832042fbd364730ab Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Tue, 11 Oct 2016 13:01:39 +0100 Subject: [PATCH] JAL-2039 improvement to offer cached structure view immediately when cached structures exists --- src/jalview/gui/StructureChooser.java | 21 +++++++++++++++------ test/jalview/gui/StructureChooserTest.java | 11 +++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 57debe3..3350f6c 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -81,6 +81,8 @@ public class StructureChooser extends GStructureChooser implements private boolean isValidPBDEntry; + private boolean cachedPDBExists; + public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq, AlignmentPanel ap) { @@ -102,7 +104,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 +120,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(); @@ -237,7 +239,7 @@ public class StructureChooser extends GStructureChooser implements } } } - + cachedPDBExists = !entries.isEmpty(); PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries); tbl_local_pdb.setModel(tableModelx); } @@ -524,7 +526,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 @@ -549,8 +552,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); } diff --git a/test/jalview/gui/StructureChooserTest.java b/test/jalview/gui/StructureChooserTest.java index 1e41a16..446d32d 100644 --- a/test/jalview/gui/StructureChooserTest.java +++ b/test/jalview/gui/StructureChooserTest.java @@ -28,6 +28,7 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; +import jalview.jbgui.GStructureChooser.FilterOption; import java.util.Vector; @@ -109,15 +110,21 @@ public class StructureChooserTest { SequenceI[] selectedSeqs = new SequenceI[] { seq }; StructureChooser sc = new StructureChooser(selectedSeqs, seq, null); - sc.populateFilterComboBox(false); + sc.populateFilterComboBox(false, false); int optionsSize = sc.getCmbFilterOption().getItemCount(); assertEquals(3, optionsSize); // if structures are not discovered then don't // populate filter options - sc.populateFilterComboBox(true); + sc.populateFilterComboBox(true, false); optionsSize = sc.getCmbFilterOption().getItemCount(); assertTrue(optionsSize > 3); // if structures are found, filter options // should be populated + + sc.populateFilterComboBox(true, true); + assertTrue(sc.getCmbFilterOption().getSelectedItem() != null); + FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption() + .getSelectedItem(); + assertEquals("Cached PDB Entries", filterOpt.getName()); } @Test(groups = { "Functional" }) -- 1.7.10.2