X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fcore%2FGFTSPanel.java;h=7a98fcaf89e7860c17e98f46c6937d55d5ae6473;hb=44db4288c5102d925c67e5b15ff80dc5e8c27b41;hp=918b3c99c0b6b55d0352b93c7415248d0273c932;hpb=3cd147b2caead40e9abea8c58eb48f6a47975378;p=jalview.git diff --git a/src/jalview/fts/core/GFTSPanel.java b/src/jalview/fts/core/GFTSPanel.java index 918b3c9..7a98fca 100644 --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@ -28,9 +28,7 @@ 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.CacheBoxI; -import jalview.io.cache.Cacheable; +import jalview.io.cache.JvCacheableInputBox; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -58,6 +56,7 @@ import java.util.List; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JInternalFrame; @@ -85,11 +84,12 @@ import javax.swing.text.JTextComponent; */ @SuppressWarnings("serial") -public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable +public abstract class GFTSPanel extends JPanel implements GFTSPanelI { protected JInternalFrame mainFrame = new JInternalFrame( getFTSFrameTitle()); + protected JTabbedPane mainFramTabs = new JTabbedPane(); protected IProgressIndicator progressIndicator; protected JComboBox cmb_searchTarget = new JComboBox(); @@ -100,7 +100,9 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable protected JButton btn_cancel = new JButton(); - protected JComboBox txt_search; + protected JCheckBox btn_autosearch = new JCheckBox(); + + protected JvCacheableInputBox txt_search; protected SequenceFetcher seqFetcher; @@ -114,14 +116,14 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable protected StringBuilder errorWarning = new StringBuilder(); - protected ImageIcon warningImage = new ImageIcon(getClass().getResource( - "/images/warning.gif")); + protected ImageIcon warningImage = new ImageIcon( + getClass().getResource("/images/warning.gif")); - protected ImageIcon loadingImage = new ImageIcon(getClass().getResource( - "/images/loading.gif")); + protected ImageIcon loadingImage = new ImageIcon( + getClass().getResource("/images/loading.gif")); - protected ImageIcon balnkPlaceholderImage = new ImageIcon(getClass() - .getResource("/images/blank_16x16_placeholder.png")); + protected ImageIcon balnkPlaceholderImage = new ImageIcon( + getClass().getResource("/images/blank_16x16_placeholder.png")); protected JLabel lbl_warning = new JLabel(warningImage); @@ -151,6 +153,10 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable protected HashSet paginatorCart = new HashSet(); + private static final int MIN_WIDTH = 670; + + private static final int MIN_HEIGHT = 300; + protected static final DecimalFormat totalNumberformatter = new DecimalFormat( "###,###"); @@ -224,8 +230,9 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable e.printStackTrace(); } toolTipText = (toolTipText == null ? null - : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip( - true, toolTipText.subSequence(0, 500) + "...") + : (toolTipText.length() > 500 + ? JvSwingUtils.wrapTooltip(true, + toolTipText.subSequence(0, 500) + "...") : JvSwingUtils.wrapTooltip(true, toolTipText))); return toolTipText; @@ -236,15 +243,36 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable public GFTSPanel() { + this(null); + } + + public GFTSPanel(SequenceFetcher fetcher) + { try { + if (fetcher == null) + { + mainFramTabs = null; + } jbInit(); + if (fetcher != null) + { + mainFramTabs.addTab("Retrieve IDs", fetcher); + fetcher.setDatabaseChooserVisible(false); + } + mainFrame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); + final JPanel ftsPanel = this; mainFrame.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { - txt_search.requestFocusInWindow(); + // TODO: make selected tab gain focus in correct widget + if (mainFramTabs != null + && mainFramTabs.getSelectedComponent() == ftsPanel) + { + txt_search.requestFocusInWindow(); + } } }); mainFrame.invalidate(); @@ -263,10 +291,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable private void jbInit() throws Exception { - txt_search = new JComboBox(); - txt_search.setEditable(true); - txt_search - .setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + txt_search = new JvCacheableInputBox(getCacheKey()); populateCmbSearchTargetOptions(); Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800 : getTempUserPrefs().get("FTSPanel.width"); @@ -330,6 +355,9 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable } }); + btn_autosearch.setText(""); + btn_autosearch.setToolTipText( + MessageManager.getString("option.enable_disable_autosearch")); btn_back.setFont(new java.awt.Font("Verdana", 0, 12)); btn_back.setText(MessageManager.getString("action.back")); btn_back.addActionListener(new java.awt.event.ActionListener() @@ -375,8 +403,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable } }); btn_next_page.setEnabled(false); - btn_next_page.setToolTipText(MessageManager - .getString("label.next_page_tooltip")); + btn_next_page.setToolTipText( + MessageManager.getString("label.next_page_tooltip")); btn_next_page.setFont(new java.awt.Font("Verdana", 0, 12)); btn_next_page.setText(MessageManager.getString("action.next_page")); btn_next_page.addActionListener(new java.awt.event.ActionListener() @@ -400,8 +428,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable }); btn_prev_page.setEnabled(false); - btn_prev_page.setToolTipText(MessageManager - .getString("label.prev_page_tooltip")); + btn_prev_page.setToolTipText( + MessageManager.getString("label.prev_page_tooltip")); btn_prev_page.setFont(new java.awt.Font("Verdana", 0, 12)); btn_prev_page.setText(MessageManager.getString("action.prev_page")); btn_prev_page.addActionListener(new java.awt.event.ActionListener() @@ -467,13 +495,13 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable if (e.getStateChange() == ItemEvent.SELECTED) { String tooltipText; - if ("all".equalsIgnoreCase(getCmbSearchTarget().getSelectedItem() - .toString())) + if ("all".equalsIgnoreCase( + getCmbSearchTarget().getSelectedItem().toString())) { tooltipText = MessageManager.getString("label.search_all"); } - else if ("pdb id".equalsIgnoreCase(getCmbSearchTarget() - .getSelectedItem().toString())) + else if ("pdb id".equalsIgnoreCase( + getCmbSearchTarget().getSelectedItem().toString())) { tooltipText = MessageManager .getString("label.separate_multiple_accession_ids"); @@ -481,55 +509,56 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable else { tooltipText = MessageManager.formatMessage( - "label.separate_multiple_query_values", - new Object[] { getCmbSearchTarget().getSelectedItem() - .toString() }); + "label.separate_multiple_query_values", new Object[] + { getCmbSearchTarget().getSelectedItem().toString() }); } - txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true, - tooltipText)); + txt_search.setToolTipText( + JvSwingUtils.wrapTooltip(true, tooltipText)); searchAction(true); } } }); - txt_search.setFont(new java.awt.Font("Verdana", 0, 12)); txt_search.getEditor().getEditorComponent() .addKeyListener(new KeyAdapter() - { - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_ENTER) - { - if (getTypedText() == null || getTypedText().isEmpty()) - { - return; - } - String primaryKeyName = getFTSRestClient().getPrimaryKeyColumn() - .getName(); - if (primaryKeyName.equalsIgnoreCase(getCmbSearchTarget() - .getSelectedItem().toString())) - { - transferToSequenceFetcher(getTypedText()); - } - } - } - }); - + { + @Override + public void keyPressed(KeyEvent e) + { + if (e.getKeyCode() == KeyEvent.VK_ENTER) + { + if (getTypedText() == null || getTypedText().isEmpty()) + { + return; + } + String primaryKeyName = getFTSRestClient() + .getPrimaryKeyColumn().getName(); + if (primaryKeyName.equalsIgnoreCase(getCmbSearchTarget() + .getSelectedItem().toString())) + { + // TODO: nicer to show the list in the result set before + // viewing in Jalview perhaps ? + transferToSequenceFetcher(getTypedText()); + } + else + { + performSearchAction(); + } + } + } + }); final DeferredTextInputListener listener = new DeferredTextInputListener( 1500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - String typed = getTypedText(); - if (!typed.equalsIgnoreCase(lastSearchTerm)) + if (btn_autosearch.isSelected() + || txt_search.wasEnterPressed()) { - searchAction(true); - paginatorCart.clear(); - lastSearchTerm = typed; + performSearchAction(); } } }, false); @@ -551,6 +580,15 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable } }); + txt_search.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + performSearchAction(); + } + }); final String searchTabTitle = MessageManager .getString("label.search_result"); final String configureCols = MessageManager @@ -580,8 +618,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable txt_search.setEnabled(false); cmb_searchTarget.setEnabled(false); previousWantedFields = getFTSRestClient() - .getAllDefaultDisplayedFTSDataColumns().toArray( - new Object[0]); + .getAllDefaultDisplayedFTSDataColumns() + .toArray(new Object[0]); } if (sourceTabbedPane.getTitleAt(index).equals(searchTabTitle)) { @@ -615,6 +653,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable pnl_results.add(tabbedPane); pnl_inputs.add(cmb_searchTarget); pnl_inputs.add(txt_search); + pnl_inputs.add(btn_autosearch); pnl_inputs.add(lbl_loading); pnl_inputs.add(lbl_warning); pnl_inputs.add(lbl_blank); @@ -626,10 +665,20 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable this.add(pnl_results, java.awt.BorderLayout.CENTER); this.add(pnl_actions, java.awt.BorderLayout.SOUTH); mainFrame.setVisible(true); - mainFrame.setContentPane(this); + if (mainFramTabs != null) + { + mainFramTabs.setOpaque(true); + mainFramTabs.insertTab("Free Text Search", null, this, "", 0); + mainFrame.setContentPane(mainFramTabs); + mainFramTabs.setVisible(true); + } + else + { + mainFrame.setContentPane(this); + } mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - mainFrame - .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + mainFrame.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() { @Override public void internalFrameClosing(InternalFrameEvent e) @@ -637,8 +686,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable closeAction(); } }); - mainFrame.setVisible(true); - mainFrame.setContentPane(this); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Integer x = getTempUserPrefs().get("FTSPanel.x"); Integer y = getTempUserPrefs().get("FTSPanel.y"); @@ -656,7 +703,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable getTempUserPrefs().put("FTSPanel.x", mainFrame.getX()); getTempUserPrefs().put("FTSPanel.y", mainFrame.getY()); mainFrame.dispose(); - AppCache.getInstance().persistCache(this); + txt_search.persistCache(); } public class DeferredTextInputListener implements DocumentListener @@ -700,6 +747,18 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable } + void performSearchAction() + { + String typed = getTypedText(); + if (typed != null && typed.length() > 0 + && !typed.equalsIgnoreCase(lastSearchTerm)) + { + searchAction(true); + paginatorCart.clear(); + lastSearchTerm = typed; + } + } + public boolean wantedFieldsUpdated() { if (previousWantedFields == null) @@ -770,8 +829,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable { lbl_loading.setVisible(false); lbl_blank.setVisible(false); - lbl_warning.setToolTipText(JvSwingUtils.wrapTooltip(true, - errorWarning.toString())); + lbl_warning.setToolTipText( + JvSwingUtils.wrapTooltip(true, errorWarning.toString())); lbl_warning.setVisible(true); } } @@ -835,11 +894,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable @Override public String getTypedText() { - String typed = txt_search.getEditor().getItem() == null ? "" - : txt_search - .getEditor().getItem().toString().trim(); - System.out.println("Typed : " + typed); - return typed; + return txt_search.getUserInput(); } @Override @@ -923,8 +978,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable int totalRows = resultTable.getRowCount(); try { - primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( - wantedFields, false); + primaryKeyColIndex = getFTSRestClient() + .getPrimaryKeyColumIndex(wantedFields, false); } catch (Exception e) { e.printStackTrace(); @@ -957,8 +1012,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable int primaryKeyColIndex = 0; try { - primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( - wantedFields, false); + primaryKeyColIndex = getFTSRestClient() + .getPrimaryKeyColumIndex(wantedFields, false); } catch (Exception e) { e.printStackTrace(); @@ -998,77 +1053,4 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable mainFrame.setTitle(getFTSFrameTitle()); } - @Override - public void initCache() - { - AppCache.getInstance().initCache(this); - } - - @Override - public void updateCache() - { - AppCache.getInstance().updateCache(this); - } - - - - @Override - public String getCacheKey() - { - return getCacheKey(); - } - - @Override - public CacheBoxI getCacheComboBox() - { - return new CacheBoxI() - { - - @Override - public void setSelectedItem(Object anObject) - { - txt_search.setSelectedItem(anObject); - } - - @Override - public void requestFocus() - { - txt_search.requestFocusInWindow(); - } - - @Override - public void looseFocus() - { - mainFrame.requestFocusInWindow(); - } - - @Override - public void addItem(String item) - { - txt_search.addItem(item); - } - - @Override - public void removeAllItems() - { - txt_search.removeAllItems(); - } - - @Override - public int getItemCount() - { - return txt_search.getItemCount(); - } - - @Override - public String getUserInput() - { - return txt_search.getEditor().getItem() == null ? "" : txt_search - .getEditor().getItem().toString().trim(); - } - }; - } - - - }