From 0ce95d9c8581b19c1d636f67f67dd670e41f1ca9 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 1 Dec 2016 14:31:39 +0000 Subject: [PATCH] JAL-1648 Implemented in-memory caching for FTS (Uniprot & PDB) and Finder --- src/jalview/fts/api/GFTSPanelI.java | 1 + src/jalview/fts/core/GFTSPanel.java | 129 +++++++++++++------- src/jalview/fts/service/pdb/PDBFTSPanel.java | 18 ++- .../fts/service/uniprot/UniprotFTSPanel.java | 18 ++- src/jalview/gui/Finder.java | 8 +- src/jalview/io/cache/AppCache.java | 89 ++++++++++++++ src/jalview/io/cache/AppCacheI.java | 11 ++ src/jalview/io/cache/Cacheable.java | 37 ++++++ src/jalview/jbgui/GFinder.java | 68 ++++++++--- test/jalview/fts/service/pdb/PDBFTSPanelTest.java | 8 +- 10 files changed, 307 insertions(+), 80 deletions(-) create mode 100644 src/jalview/io/cache/AppCache.java create mode 100644 src/jalview/io/cache/AppCacheI.java create mode 100644 src/jalview/io/cache/Cacheable.java diff --git a/src/jalview/fts/api/GFTSPanelI.java b/src/jalview/fts/api/GFTSPanelI.java index f86c3bc..d15f2e8 100644 --- a/src/jalview/fts/api/GFTSPanelI.java +++ b/src/jalview/fts/api/GFTSPanelI.java @@ -137,4 +137,5 @@ public interface GFTSPanelI * @return */ public Map getTempUserPrefs(); + } diff --git a/src/jalview/fts/core/GFTSPanel.java b/src/jalview/fts/core/GFTSPanel.java index a69d9f8..a581717 100644 --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@ -28,6 +28,8 @@ import jalview.gui.Desktop; import jalview.gui.IProgressIndicator; import jalview.gui.JvSwingUtils; import jalview.gui.SequenceFetcher; +import jalview.io.cache.AppCache; +import jalview.io.cache.Cacheable; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -38,6 +40,8 @@ import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -54,6 +58,7 @@ import java.util.List; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; @@ -61,7 +66,6 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTable; -import javax.swing.JTextField; import javax.swing.Timer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -70,6 +74,7 @@ import javax.swing.event.DocumentListener; import javax.swing.event.InternalFrameEvent; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; +import javax.swing.text.JTextComponent; /** * This class provides the swing GUI layout for FTS Panel and implements most of @@ -80,7 +85,7 @@ import javax.swing.table.TableColumn; */ @SuppressWarnings("serial") -public abstract class GFTSPanel extends JPanel implements GFTSPanelI +public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable { protected JInternalFrame mainFrame = new JInternalFrame( getFTSFrameTitle()); @@ -95,7 +100,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI protected JButton btn_cancel = new JButton(); - protected JTextField txt_search = new JTextField(30); + protected JComboBox txt_search; protected SequenceFetcher seqFetcher; @@ -257,6 +262,12 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI */ private void jbInit() throws Exception { + + txt_search = new JComboBox(); + txt_search.setEditable(true); + txt_search + .setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + populateCmbSearchTargetOptions(); Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800 : getTempUserPrefs().get("FTSPanel.width"); Integer height = getTempUserPrefs().get("FTSPanel.height") == null ? 400 @@ -448,49 +459,52 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI scrl_searchResult.setPreferredSize(new Dimension(width, height)); cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12)); - cmb_searchTarget.addActionListener(new ActionListener() + cmb_searchTarget.addItemListener(new ItemListener() { @Override - public void actionPerformed(ActionEvent e) + public void itemStateChanged(ItemEvent e) { - String tooltipText; - if ("all".equalsIgnoreCase(getCmbSearchTarget().getSelectedItem() - .toString())) - { - tooltipText = MessageManager.getString("label.search_all"); - } - else if ("pdb id".equalsIgnoreCase(getCmbSearchTarget() - .getSelectedItem().toString())) + if (e.getStateChange() == ItemEvent.SELECTED) { - tooltipText = MessageManager - .getString("label.separate_multiple_accession_ids"); - } - else - { - tooltipText = MessageManager.formatMessage( - "label.separate_multiple_query_values", - new Object[] { getCmbSearchTarget().getSelectedItem() - .toString() }); + String tooltipText; + if ("all".equalsIgnoreCase(getCmbSearchTarget().getSelectedItem() + .toString())) + { + tooltipText = MessageManager.getString("label.search_all"); + } + else if ("pdb id".equalsIgnoreCase(getCmbSearchTarget() + .getSelectedItem().toString())) + { + tooltipText = MessageManager + .getString("label.separate_multiple_accession_ids"); + } + else + { + tooltipText = MessageManager.formatMessage( + "label.separate_multiple_query_values", + new Object[] { getCmbSearchTarget().getSelectedItem() + .toString() }); + } + txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true, + tooltipText)); + searchAction(true); } - txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true, - tooltipText)); - searchAction(true); } }); + - populateCmbSearchTargetOptions(); txt_search.setFont(new java.awt.Font("Verdana", 0, 12)); - txt_search.addKeyListener(new KeyAdapter() + txt_search.getEditor().getEditorComponent() + .addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { - if (txt_search.getText() == null - || txt_search.getText().isEmpty()) + if (getTypedText() == null || getTypedText().isEmpty()) { return; } @@ -499,7 +513,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI if (primaryKeyName.equalsIgnoreCase(getCmbSearchTarget() .getSelectedItem().toString())) { - transferToSequenceFetcher(txt_search.getText()); + transferToSequenceFetcher(getTypedText()); } } } @@ -519,7 +533,9 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI } } }, false); - txt_search.getDocument().addDocumentListener(listener); + ((JTextComponent) txt_search.getEditor().getEditorComponent()) + .getDocument().addDocumentListener(listener); + txt_search.addFocusListener(new FocusListener() { @Override @@ -635,11 +651,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI protected void closeAction() { - // System.out.println(">>>>>>>>>> closing internal frame!!!"); - // System.out.println("width : " + this.getWidth()); - // System.out.println("heigh : " + this.getHeight()); - // System.out.println("x : " + mainFrame.getX()); - // System.out.println("y : " + mainFrame.getY()); getTempUserPrefs().put("FTSPanel.width", this.getWidth()); getTempUserPrefs().put("FTSPanel.height", pnl_results.getHeight()); getTempUserPrefs().put("FTSPanel.x", mainFrame.getX()); @@ -692,7 +703,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI { if (previousWantedFields == null) { - return true; + return false; } return Arrays.equals(getFTSRestClient() @@ -719,7 +730,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI return cmb_searchTarget; } - public JTextField getTxtSearch() + public JComboBox getTxtSearch() { return txt_search; } @@ -815,7 +826,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI public void transferToSequenceFetcher(String ids) { - // mainFrame.dispose(); seqFetcher.getTextArea().setText(ids); Thread worker = new Thread(seqFetcher); worker.start(); @@ -824,7 +834,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI @Override public String getTypedText() { - return txt_search.getText().trim(); + return txt_search.getEditor().getItem() == null ? "" : txt_search + .getEditor().getItem().toString().trim(); } @Override @@ -929,8 +940,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI .toString(); paginatorCart.add(idStr); } - // System.out.println("Paginator shopping cart size : " - // + paginatorCart.size()); } public void updateSummaryTableSelections() @@ -949,9 +958,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI { e.printStackTrace(); } - // System.out.println(">>>>>> got here : 1"); int totalRows = resultTable.getRowCount(); - // resultTable.clearSelection(); for (int row = 0; row < totalRows; row++) { String id = (String) resultTable.getValueAt(row, primaryKeyColIndex); @@ -965,9 +972,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI public void refreshPaginatorState() { - // System.out.println("resultSet count : " + resultSetCount); - // System.out.println("offSet : " + offSet); - // System.out.println("page limit : " + pageLimit); setPrevPageButtonEnabled(false); setNextPageButtonEnabled(false); if (resultSetCount == 0 && pageLimit == 0) @@ -989,4 +993,35 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI mainFrame.setTitle(getFTSFrameTitle()); } + + protected void fireCache() + { + AppCache.getInstance().updateCache(this); + } + + @Override + public void init() + { + // reset(); + } + + @Override + public JComponent getNextFocusableElement() + { + return mainFrame; + } + + @Override + public String getCacheKey() + { + return getCacheKey(); + } + + @Override + public JComboBox getCacheComboBox() + { + return txt_search; + } + + } diff --git a/src/jalview/fts/service/pdb/PDBFTSPanel.java b/src/jalview/fts/service/pdb/PDBFTSPanel.java index 1dfabce..66b8261 100644 --- a/src/jalview/fts/service/pdb/PDBFTSPanel.java +++ b/src/jalview/fts/service/pdb/PDBFTSPanel.java @@ -39,10 +39,11 @@ public class PDBFTSPanel extends GFTSPanel private static String defaultFTSFrameTitle = MessageManager .getString("label.pdb_sequence_fetcher"); - private String ftsFrameTitle = defaultFTSFrameTitle; private static Map tempUserPrefs = new HashMap(); + private static final String PDB_FTS_CACHE_KEY = "PDB_FTS_CACHE_KEY"; + public PDBFTSPanel(SequenceFetcher seqFetcher) { super(); @@ -50,6 +51,7 @@ public class PDBFTSPanel extends GFTSPanel this.seqFetcher = seqFetcher; this.progressIndicator = (seqFetcher == null) ? null : seqFetcher .getProgressIndicator(); + fireCache(); } @Override @@ -64,7 +66,6 @@ public class PDBFTSPanel extends GFTSPanel @Override public void run() { - ftsFrameTitle = defaultFTSFrameTitle; reset(); boolean allowEmptySequence = false; if (getTypedText().length() > 0) @@ -76,7 +77,7 @@ public class PDBFTSPanel extends GFTSPanel .getSelectedItem()).getCode(); wantedFields = PDBFTSRestClient.getInstance() .getAllDefaultDisplayedFTSDataColumns(); - String searchTerm = decodeSearchTerm(txt_search.getText(), + String searchTerm = decodeSearchTerm(getTypedText(), searchTarget); FTSRestRequest request = new FTSRestRequest(); @@ -143,6 +144,7 @@ public class PDBFTSPanel extends GFTSPanel refreshPaginatorState(); updateSummaryTableSelections(); } + fireCache(); } }.start(); } @@ -200,7 +202,7 @@ public class PDBFTSPanel extends GFTSPanel e.printStackTrace(); } int[] selectedRows = getResultTable().getSelectedRows(); - String searchTerm = txt_search.getText(); + String searchTerm = getTypedText(); for (int summaryRow : selectedRows) { String idStr = getResultTable().getValueAt(summaryRow, @@ -261,7 +263,7 @@ public class PDBFTSPanel extends GFTSPanel @Override public String getFTSFrameTitle() { - return ftsFrameTitle; + return defaultFTSFrameTitle; } @Override @@ -276,4 +278,10 @@ public class PDBFTSPanel extends GFTSPanel return tempUserPrefs; } + @Override + public String getCacheKey() + { + return PDB_FTS_CACHE_KEY; + } + } diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index f04e4fa..eba0f88 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -40,10 +40,11 @@ public class UniprotFTSPanel extends GFTSPanel private static String defaultFTSFrameTitle = MessageManager .getString("label.uniprot_sequence_fetcher"); - private String ftsFrameTitle = defaultFTSFrameTitle; private static Map tempUserPrefs = new HashMap(); + private static final String UNIPROT_FTS_CACHE_KEY = "UNIPROT_FTS_CACHE_KEY"; + public UniprotFTSPanel(SequenceFetcher seqFetcher) { super(); @@ -52,6 +53,7 @@ public class UniprotFTSPanel extends GFTSPanel this.seqFetcher = seqFetcher; this.progressIndicator = (seqFetcher == null) ? null : seqFetcher .getProgressIndicator(); + fireCache(); } @Override @@ -66,9 +68,9 @@ public class UniprotFTSPanel extends GFTSPanel @Override public void run() { - ftsFrameTitle = defaultFTSFrameTitle; reset(); - if (getTypedText().length() > 0) + String searchInput = getTypedText(); + if (searchInput.length() > 0) { setSearchInProgress(true); long startTime = System.currentTimeMillis(); @@ -78,7 +80,7 @@ public class UniprotFTSPanel extends GFTSPanel wantedFields = UniProtFTSRestClient.getInstance() .getAllDefaultDisplayedFTSDataColumns(); - String searchTerm = decodeSearchTerm(txt_search.getText(), + String searchTerm = decodeSearchTerm(getTypedText(), searchTarget); FTSRestRequest request = new FTSRestRequest(); @@ -143,6 +145,7 @@ public class UniprotFTSPanel extends GFTSPanel refreshPaginatorState(); updateSummaryTableSelections(); } + fireCache(); } }.start(); @@ -226,7 +229,7 @@ public class UniprotFTSPanel extends GFTSPanel @Override public String getFTSFrameTitle() { - return ftsFrameTitle; + return defaultFTSFrameTitle; } @Override @@ -235,4 +238,9 @@ public class UniprotFTSPanel extends GFTSPanel return tempUserPrefs; } + @Override + public String getCacheKey() + { + return UNIPROT_FTS_CACHE_KEY; + } } diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index af23ceb..63278ac 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -38,7 +38,6 @@ import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; -import javax.swing.JOptionPane; import javax.swing.KeyStroke; /** @@ -98,7 +97,7 @@ public class Finder extends GFinder Desktop.addInternalFrame(frame, MessageManager.getString("label.find"), WIDTH, HEIGHT); - textfield.requestFocus(); + searchBox.requestFocus(); } /** @@ -214,7 +213,8 @@ public class Finder extends GFinder { seqs[i] = match.getSequence().getDatasetSequence(); - features[i] = new SequenceFeature(textfield.getText().trim(), + features[i] = new SequenceFeature(searchBox.getEditor().getItem() + .toString().trim(), "Search Results", null, match.getStart(), match.getEnd(), "Search Results"); i++; @@ -239,7 +239,7 @@ public class Finder extends GFinder { createNewGroup.setEnabled(false); - String searchString = textfield.getText().trim(); + String searchString = searchBox.getEditor().getItem().toString().trim(); if (isInvalidSearchString(searchString)) { diff --git a/src/jalview/io/cache/AppCache.java b/src/jalview/io/cache/AppCache.java new file mode 100644 index 0000000..9201341 --- /dev/null +++ b/src/jalview/io/cache/AppCache.java @@ -0,0 +1,89 @@ +package jalview.io.cache; + + +import java.util.Hashtable; +import java.util.LinkedHashSet; +import java.util.Set; + +import javax.swing.JComboBox; +import javax.swing.JComponent; + +public class AppCache implements AppCacheI +{ + private static AppCache instance = null; + + private Hashtable> cacheItems; + + private AppCache() + { + cacheItems = new Hashtable>(); + } + + @Override + public LinkedHashSet getAllCachedItemsFor(String cacheKey) + { + LinkedHashSet foundCache = cacheItems.get(cacheKey); + if (foundCache == null) + { + foundCache = new LinkedHashSet(); + cacheItems.put(cacheKey, foundCache); + } + return foundCache; + } + + + public static AppCache getInstance() + { + if (instance == null) + { + instance = new AppCache(); + } + return instance; + } + + @Override + public void updateCache(Cacheable cacheable) + { + JComboBox cacheComboBox = cacheable.getCacheComboBox(); + String cacheKey = cacheable.getCacheKey(); + JComponent nextFocusableComponent = cacheable.getNextFocusableElement(); + String userInput = cacheComboBox.getEditor().getItem() == null ? "" + : cacheComboBox.getEditor().getItem().toString().trim(); + + if (userInput != null && !userInput.isEmpty()) + { + LinkedHashSet foundCache = getAllCachedItemsFor(cacheKey); + foundCache.add(userInput); + cacheItems.put(cacheKey, foundCache); + } + + String lastSearch = userInput; + nextFocusableComponent.requestFocusInWindow(); + if (cacheComboBox.getItemCount() > 0) + { + cacheComboBox.removeAllItems(); + } + + Set cacheItems = getAllCachedItemsFor(cacheKey); + if (cacheItems != null && !cacheItems.isEmpty()) + { + for (String cacheItem : cacheItems) + { + cacheComboBox.addItem(cacheItem); + } + } + + if (!lastSearch.isEmpty()) + { + cacheComboBox.setSelectedItem(lastSearch); + cacheComboBox.requestFocus(); + } + else + { + cacheable.init(); + cacheComboBox.addItem(""); + cacheComboBox.setSelectedItem(""); + } + } + +} diff --git a/src/jalview/io/cache/AppCacheI.java b/src/jalview/io/cache/AppCacheI.java new file mode 100644 index 0000000..51d51c2 --- /dev/null +++ b/src/jalview/io/cache/AppCacheI.java @@ -0,0 +1,11 @@ +package jalview.io.cache; + +import java.util.Set; + +public interface AppCacheI +{ + + public Set getAllCachedItemsFor(String cacheKey); + + public void updateCache(Cacheable cacheable); +} diff --git a/src/jalview/io/cache/Cacheable.java b/src/jalview/io/cache/Cacheable.java new file mode 100644 index 0000000..d17cab4 --- /dev/null +++ b/src/jalview/io/cache/Cacheable.java @@ -0,0 +1,37 @@ +package jalview.io.cache; + +import javax.swing.JComboBox; +import javax.swing.JComponent; + +public interface Cacheable +{ + + /** + * method executed on cache initialisation + */ + public void init(); + + /** + * Combo-box instance for the cache component + * + * @return + */ + public JComboBox getCacheComboBox(); + + /** + * The unique key that will be used for storing user input for this cacheable + * in the cache dictionary + * + * @return + */ + public String getCacheKey(); + + /** + * Get next focusable component. Required to delegate focus while updating the + * cacheable component cache + * + * @return + */ + public JComponent getNextFocusableElement(); + +} diff --git a/src/jalview/jbgui/GFinder.java b/src/jalview/jbgui/GFinder.java index fef4568..76f75e1 100755 --- a/src/jalview/jbgui/GFinder.java +++ b/src/jalview/jbgui/GFinder.java @@ -24,6 +24,8 @@ import jalview.datamodel.AlignmentI; import jalview.io.DataSourceType; import jalview.io.FileFormat; import jalview.io.FormatAdapter; +import jalview.io.cache.AppCache; +import jalview.io.cache.Cacheable; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -36,16 +38,17 @@ import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; +import javax.swing.text.JTextComponent; -public class GFinder extends JPanel +public class GFinder extends JPanel implements Cacheable { JLabel jLabelFind = new JLabel(); @@ -59,9 +62,8 @@ public class GFinder extends JPanel protected JButton createNewGroup = new JButton(); - JScrollPane jScrollPane1 = new JScrollPane(); - protected JTextArea textfield = new JTextArea(); + protected JComboBox searchBox = new JComboBox(); BorderLayout mainBorderLayout = new BorderLayout(); @@ -81,6 +83,8 @@ public class GFinder extends JPanel GridLayout optionsGridLayout = new GridLayout(); + private static final String FINDER_CACHE_KEY = "FINDER_CACHE_KEY"; + public GFinder() { try @@ -133,10 +137,12 @@ public class GFinder extends JPanel createNewGroup_actionPerformed(e); } }); - textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12)); - textfield.setText(""); - textfield.setLineWrap(true); - textfield.addCaretListener(new CaretListener() + searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12)); + searchBox.setEditable(true); + searchBox +.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + ((JTextComponent) searchBox.getEditor().getEditorComponent()) + .addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) @@ -144,7 +150,8 @@ public class GFinder extends JPanel textfield_caretUpdate(e); } }); - textfield.addKeyListener(new java.awt.event.KeyAdapter() + searchBox.getEditor().getEditorComponent() + .addKeyListener(new java.awt.event.KeyAdapter() { @Override public void keyPressed(KeyEvent e) @@ -172,8 +179,7 @@ public class GFinder extends JPanel this.add(jPanel2, java.awt.BorderLayout.SOUTH); this.add(jPanel3, java.awt.BorderLayout.NORTH); this.add(jPanel4, java.awt.BorderLayout.CENTER); - jPanel4.add(jScrollPane1, java.awt.BorderLayout.NORTH); - jScrollPane1.getViewport().add(textfield); + jPanel4.add(searchBox, java.awt.BorderLayout.NORTH); JPanel optionsPanel = new JPanel(); @@ -185,6 +191,7 @@ public class GFinder extends JPanel optionsPanel.add(searchDescription, null); jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST); + fireCache(); } protected void findNext_actionPerformed(ActionEvent e) @@ -201,6 +208,7 @@ public class GFinder extends JPanel { e.consume(); findNext_actionPerformed(null); + fireCache(); } } @@ -210,14 +218,14 @@ public class GFinder extends JPanel public void textfield_caretUpdate(CaretEvent e) { - if (textfield.getText().indexOf(">") > -1) + if (searchBox.getEditor().getItem().toString().indexOf(">") > -1) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - String str = textfield.getText(); + String str = searchBox.getEditor().getItem().toString(); AlignmentI al = null; try { @@ -232,10 +240,40 @@ public class GFinder extends JPanel jalview.util.Comparison.GapChars, al.getSequenceAt(0) .getSequenceAsString()); - textfield.setText(str); + searchBox.setSelectedItem(str); } } }); } } + + + protected void fireCache() + { + AppCache.getInstance().updateCache(this); + } + + @Override + public void init() + { + // TODO Auto-generated method stub + } + + @Override + public JComboBox getCacheComboBox() + { + return searchBox; + } + + @Override + public String getCacheKey() + { + return FINDER_CACHE_KEY; + } + + @Override + public JComponent getNextFocusableElement() + { + return this; + } } diff --git a/test/jalview/fts/service/pdb/PDBFTSPanelTest.java b/test/jalview/fts/service/pdb/PDBFTSPanelTest.java index 901bffc..9912e44 100644 --- a/test/jalview/fts/service/pdb/PDBFTSPanelTest.java +++ b/test/jalview/fts/service/pdb/PDBFTSPanelTest.java @@ -25,8 +25,8 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.gui.JvOptionPane; +import javax.swing.JComboBox; import javax.swing.JInternalFrame; -import javax.swing.JTextField; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; @@ -98,17 +98,17 @@ public class PDBFTSPanelTest assertEquals(expectedString, outcome); } - @Test(groups = { "External" }, timeOut = 7000) + @Test(groups = { "External" }, timeOut = 8000) public void txt_search_ActionPerformedTest() { PDBFTSPanel searchPanel = new PDBFTSPanel(null); JInternalFrame mainFrame = searchPanel.getMainFrame(); - JTextField txt_search = searchPanel.getTxtSearch(); + JComboBox txt_search = searchPanel.getTxtSearch(); assertTrue(mainFrame.getTitle().length() == 20); assertTrue(mainFrame.getTitle() .equalsIgnoreCase("PDB Sequence Fetcher")); - txt_search.setText("ABC"); + txt_search.setSelectedItem("ABC"); try { // wait for web-service to handle response -- 1.7.10.2