Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.fts.core

File GFTSPanel.java

 

Coverage histogram

../../../img/srcFileCovDistChart4.png
49% of files have more coverage

Code metrics

94
361
68
2
1,117
952
134
0.37
5.31
34
1.97

Classes

Class Line # Actions
GFTSPanel 89 354 128
0.401960840.2%
GFTSPanel.DeferredTextInputListener 745 7 6
0.2307692323.1%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21   
22    package jalview.fts.core;
23   
24    import java.awt.BorderLayout;
25    import java.awt.CardLayout;
26    import java.awt.Dimension;
27    import java.awt.Font;
28    import java.awt.event.ActionEvent;
29    import java.awt.event.ActionListener;
30    import java.awt.event.FocusAdapter;
31    import java.awt.event.FocusEvent;
32    import java.awt.event.FocusListener;
33    import java.awt.event.ItemEvent;
34    import java.awt.event.ItemListener;
35    import java.awt.event.KeyAdapter;
36    import java.awt.event.KeyEvent;
37    import java.awt.event.MouseAdapter;
38    import java.awt.event.MouseEvent;
39    import java.text.DecimalFormat;
40    import java.util.ArrayList;
41    import java.util.Arrays;
42    import java.util.Collection;
43    import java.util.Collections;
44    import java.util.Comparator;
45    import java.util.HashSet;
46    import java.util.List;
47   
48    import javax.swing.ImageIcon;
49    import javax.swing.JButton;
50    import javax.swing.JCheckBox;
51    import javax.swing.JComboBox;
52    import javax.swing.JFrame;
53    import javax.swing.JInternalFrame;
54    import javax.swing.JLabel;
55    import javax.swing.JPanel;
56    import javax.swing.JScrollPane;
57    import javax.swing.JTabbedPane;
58    import javax.swing.JTable;
59    import javax.swing.Timer;
60    import javax.swing.event.ChangeEvent;
61    import javax.swing.event.ChangeListener;
62    import javax.swing.event.DocumentEvent;
63    import javax.swing.event.DocumentListener;
64    import javax.swing.event.InternalFrameEvent;
65    import javax.swing.table.DefaultTableModel;
66    import javax.swing.table.TableColumn;
67   
68    import jalview.bin.Cache;
69    import jalview.fts.api.FTSDataColumnI;
70    import jalview.fts.api.GFTSPanelI;
71    import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
72    import jalview.gui.Desktop;
73    import jalview.gui.IProgressIndicator;
74    import jalview.gui.JvSwingUtils;
75    import jalview.gui.SequenceFetcher;
76    import jalview.io.cache.JvCacheableInputBox;
77    import jalview.util.MessageManager;
78    import jalview.util.Platform;
79   
80    /**
81    * This class provides the swing GUI layout for FTS Panel and implements most of
82    * the contracts defined in GFSPanelI
83    *
84    * @author tcnofoegbu
85    *
86    */
87   
88    @SuppressWarnings("serial")
 
89    public abstract class GFTSPanel extends JPanel implements GFTSPanelI
90    {
91    private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
92   
93    protected JInternalFrame mainFrame = new JInternalFrame(
94    getFTSFrameTitle());
95   
96    protected JTabbedPane tabs = new JTabbedPane();
97   
98    protected IProgressIndicator progressIndicator;
99   
100    protected JComboBox<FTSDataColumnI> cmb_searchTarget = new JComboBox<>();
101   
102    protected JButton btn_ok = new JButton();
103   
104    protected JButton btn_back = new JButton();
105   
106    protected JButton btn_cancel = new JButton();
107   
108    protected JCheckBox btn_autosearch = new JCheckBox();
109   
110    protected JvCacheableInputBox<String> txt_search;
111   
112    protected SequenceFetcher seqFetcher;
113   
114    protected Collection<FTSDataColumnI> wantedFields;
115   
116    private String lastSearchTerm = "";
117   
118    protected JButton btn_next_page = new JButton();
119   
120    protected JButton btn_prev_page = new JButton();
121   
122    protected StringBuilder errorWarning = new StringBuilder();
123   
124    protected ImageIcon warningImage = new ImageIcon(
125    getClass().getResource("/images/warning.gif"));
126   
127    protected ImageIcon loadingImage = new ImageIcon(
128    getClass().getResource("/images/loading.gif"));
129   
130    protected ImageIcon balnkPlaceholderImage = new ImageIcon(
131    getClass().getResource("/images/blank_16x16_placeholder.png"));
132   
133    protected JLabel lbl_warning = new JLabel(warningImage);
134   
135    protected JLabel lbl_loading = new JLabel(loadingImage);
136   
137    protected JLabel lbl_blank = new JLabel(balnkPlaceholderImage);
138   
139    JTabbedPane tabbedPane = new JTabbedPane();
140   
141    private JPanel pnl_actions = new JPanel();
142   
143    private JPanel pnl_results = new JPanel(new CardLayout());
144   
145    private JPanel pnl_inputs = new JPanel();
146   
147    private BorderLayout mainLayout = new BorderLayout();
148   
149    protected Object[] previousWantedFields;
150   
151    protected int resultSetCount;
152   
153    protected int totalResultSetCount;
154   
155    protected int offSet;
156   
157    protected int pageLimit;
158   
159    protected HashSet<String> paginatorCart = new HashSet<>();
160   
161    private static final int MIN_WIDTH = 670;
162   
163    private static final int MIN_HEIGHT = 300;
164   
165    protected static final DecimalFormat totalNumberformatter = new DecimalFormat(
166    "###,###");
167   
168    private JTable tbl_summary = new JTable()
169    {
170    private boolean inLayout;
171   
 
172  28 toggle @Override
173    public boolean getScrollableTracksViewportWidth()
174    {
175  28 return hasExcessWidth();
176   
177    }
178   
 
179  4 toggle @Override
180    public void doLayout()
181    {
182  4 if (hasExcessWidth())
183    {
184  4 autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
185    }
186  4 inLayout = true;
187  4 super.doLayout();
188  4 inLayout = false;
189  4 autoResizeMode = AUTO_RESIZE_OFF;
190    }
191   
 
192  32 toggle protected boolean hasExcessWidth()
193    {
194  32 return getPreferredSize().width < getParent().getWidth();
195    }
196   
 
197  2 toggle @Override
198    public void columnMarginChanged(ChangeEvent e)
199    {
200  2 if (isEditing())
201    {
202  0 removeEditor();
203    }
204  2 TableColumn resizingColumn = getTableHeader().getResizingColumn();
205    // Need to do this here, before the parent's
206    // layout manager calls getPreferredSize().
207  2 if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF
208    && !inLayout)
209    {
210  0 resizingColumn.setPreferredWidth(resizingColumn.getWidth());
211  0 String colHeader = resizingColumn.getHeaderValue().toString();
212  0 getTempUserPrefs().put(colHeader, resizingColumn.getWidth());
213    }
214  2 resizeAndRepaint();
215    }
216   
 
217  0 toggle @Override
218    public String getToolTipText(MouseEvent evt)
219    {
220  0 String toolTipText = null;
221  0 java.awt.Point pnt = evt.getPoint();
222  0 int rowIndex = rowAtPoint(pnt);
223  0 int colIndex = columnAtPoint(pnt);
224   
225  0 try
226    {
227  0 if (getValueAt(rowIndex, colIndex) == null)
228    {
229  0 return null;
230    }
231  0 toolTipText = getValueAt(rowIndex, colIndex).toString();
232   
233    } catch (Exception e)
234    {
235  0 e.printStackTrace();
236    }
237  0 toolTipText = (toolTipText == null ? null
238  0 : (toolTipText.length() > 500
239    ? JvSwingUtils.wrapTooltip(true,
240    toolTipText.subSequence(0, 500) + "...")
241    : JvSwingUtils.wrapTooltip(true, toolTipText)));
242   
243  0 return toolTipText;
244    }
245    };
246   
247    protected JScrollPane scrl_searchResult = new JScrollPane(tbl_summary);
248   
 
249  0 toggle public GFTSPanel()
250    {
251  0 this(null);
252    }
253   
 
254  2 toggle public GFTSPanel(SequenceFetcher fetcher)
255    {
256  2 try
257    {
258  2 if (fetcher == null)
259    {
260  2 tabs = null;
261    }
262  2 jbInit();
263  2 if (fetcher != null)
264    {
265  0 tabs.addTab(MessageManager.getString("label.retrieve_ids"),
266    fetcher);
267  0 fetcher.embedIn(this);
268    }
269  2 mainFrame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
270  2 final JPanel ftsPanel = this;
271  2 mainFrame.addFocusListener(new FocusAdapter()
272    {
 
273  2 toggle @Override
274    public void focusGained(FocusEvent e)
275    {
276    // TODO: make selected tab gain focus in correct widget
277  2 if (tabs != null && tabs.getSelectedComponent() == ftsPanel)
278    {
279  0 txt_search.getComponent().requestFocusInWindow();
280    }
281    }
282    });
283  2 mainFrame.invalidate();
284  2 mainFrame.pack();
285    } catch (Exception e)
286    {
287  0 e.printStackTrace();
288    }
289    }
290   
291    /**
292    * Initializes the GUI default properties
293    *
294    * @throws Exception
295    */
 
296  2 toggle private void jbInit() throws Exception
297    {
298   
299  2 txt_search = new JvCacheableInputBox<>(getCacheKey(), 45);
300  2 populateCmbSearchTargetOptions();
301  2 Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800
302    : getTempUserPrefs().get("FTSPanel.width");
303  2 Integer height = getTempUserPrefs().get("FTSPanel.height") == null ? 400
304    : getTempUserPrefs().get("FTSPanel.height");
305  2 lbl_warning.setVisible(false);
306  2 lbl_warning.setFont(VERDANA_12);
307  2 lbl_loading.setVisible(false);
308  2 lbl_loading.setFont(VERDANA_12);
309  2 lbl_blank.setVisible(true);
310  2 lbl_blank.setFont(VERDANA_12);
311   
312  2 tbl_summary.setAutoCreateRowSorter(true);
313  2 tbl_summary.getTableHeader().setReorderingAllowed(false);
314  2 tbl_summary.addMouseListener(new MouseAdapter()
315    {
 
316  0 toggle @Override
317    public void mouseClicked(MouseEvent e)
318    {
319  0 validateSelection();
320    }
321   
 
322  0 toggle @Override
323    public void mouseReleased(MouseEvent e)
324    {
325  0 validateSelection();
326    }
327    });
328  2 tbl_summary.addKeyListener(new KeyAdapter()
329    {
 
330  0 toggle @Override
331    public void keyPressed(KeyEvent evt)
332    {
333  0 validateSelection();
334  0 switch (evt.getKeyCode())
335    {
336  0 case KeyEvent.VK_ESCAPE: // escape key
337  0 btn_back_ActionPerformed();
338  0 break;
339  0 case KeyEvent.VK_ENTER: // enter key
340  0 if (btn_ok.isEnabled())
341    {
342  0 okAction();
343    }
344  0 evt.consume();
345  0 break;
346  0 case KeyEvent.VK_TAB: // tab key
347  0 if (evt.isShiftDown())
348    {
349  0 tabbedPane.requestFocus();
350    }
351    else
352    {
353  0 btn_back.requestFocus();
354    }
355  0 evt.consume();
356  0 break;
357  0 default:
358  0 return;
359    }
360    }
361    });
362   
363  2 JButton txt_help = new JButton("?");
364  2 txt_help.setFont(VERDANA_12);
365  2 txt_help.setPreferredSize(new Dimension(15, 15));
366  2 txt_help.setToolTipText(MessageManager.getString("action.help"));
367  2 txt_help.addActionListener(new ActionListener()
368    {
 
369  0 toggle @Override
370    public void actionPerformed(ActionEvent e)
371    {
372  0 showHelp();
373    }
374    });
375   
376  2 btn_autosearch.setText(MessageManager.getString("option.autosearch"));
377  2 btn_autosearch.setToolTipText(
378    MessageManager.getString("option.enable_disable_autosearch"));
379    // disable autosearch by default
380  2 btn_autosearch.setSelected(!Platform.isJS()
381    && Cache.getDefault(getAutosearchPreference(), false));
382  2 btn_autosearch.addActionListener(new java.awt.event.ActionListener()
383    {
 
384  0 toggle @Override
385    public void actionPerformed(ActionEvent e)
386    {
387  0 Cache.setProperty(getAutosearchPreference(),
388    Boolean.toString(btn_autosearch.isSelected()));
389    }
390    });
391  2 btn_back.setFont(VERDANA_12);
392  2 btn_back.setText(MessageManager.getString("action.back"));
393  2 btn_back.addActionListener(new java.awt.event.ActionListener()
394    {
 
395  0 toggle @Override
396    public void actionPerformed(ActionEvent e)
397    {
398  0 btn_back_ActionPerformed();
399    }
400    });
401  2 btn_back.addKeyListener(new KeyAdapter()
402    {
 
403  0 toggle @Override
404    public void keyPressed(KeyEvent evt)
405    {
406  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
407    {
408  0 btn_back_ActionPerformed();
409    }
410    }
411    });
412   
413  2 btn_ok.setEnabled(false);
414  2 btn_ok.setFont(VERDANA_12);
415  2 btn_ok.setText(MessageManager.getString("action.ok"));
416  2 btn_ok.addActionListener(new java.awt.event.ActionListener()
417    {
 
418  0 toggle @Override
419    public void actionPerformed(ActionEvent e)
420    {
421  0 okAction();
422    }
423    });
424  2 btn_ok.addKeyListener(new KeyAdapter()
425    {
 
426  0 toggle @Override
427    public void keyPressed(KeyEvent evt)
428    {
429  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
430    {
431  0 okAction();
432    }
433    }
434    });
435  2 btn_next_page.setEnabled(false);
436  2 btn_next_page.setToolTipText(
437    MessageManager.getString("label.next_page_tooltip"));
438  2 btn_next_page.setFont(VERDANA_12);
439  2 btn_next_page.setText(MessageManager.getString("action.next_page"));
440  2 btn_next_page.addActionListener(new java.awt.event.ActionListener()
441    {
 
442  0 toggle @Override
443    public void actionPerformed(ActionEvent e)
444    {
445  0 nextPageAction();
446    }
447    });
448  2 btn_next_page.addKeyListener(new KeyAdapter()
449    {
 
450  0 toggle @Override
451    public void keyPressed(KeyEvent evt)
452    {
453  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
454    {
455  0 nextPageAction();
456    }
457    }
458    });
459   
460  2 btn_prev_page.setEnabled(false);
461  2 btn_prev_page.setToolTipText(
462    MessageManager.getString("label.prev_page_tooltip"));
463  2 btn_prev_page.setFont(VERDANA_12);
464  2 btn_prev_page.setText(MessageManager.getString("action.prev_page"));
465  2 btn_prev_page.addActionListener(new java.awt.event.ActionListener()
466    {
 
467  0 toggle @Override
468    public void actionPerformed(ActionEvent e)
469    {
470  0 prevPageAction();
471    }
472    });
473  2 btn_prev_page.addKeyListener(new KeyAdapter()
474    {
 
475  0 toggle @Override
476    public void keyPressed(KeyEvent evt)
477    {
478  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
479    {
480  0 prevPageAction();
481    }
482    }
483    });
484   
485  2 if (isPaginationEnabled())
486    {
487  2 btn_prev_page.setVisible(true);
488  2 btn_next_page.setVisible(true);
489    }
490    else
491    {
492  0 btn_prev_page.setVisible(false);
493  0 btn_next_page.setVisible(false);
494    }
495   
496  2 btn_cancel.setFont(VERDANA_12);
497  2 btn_cancel.setText(MessageManager.getString("action.cancel"));
498  2 btn_cancel.addActionListener(new java.awt.event.ActionListener()
499    {
 
500  0 toggle @Override
501    public void actionPerformed(ActionEvent e)
502    {
503  0 btn_cancel_ActionPerformed();
504    }
505    });
506  2 btn_cancel.addKeyListener(new KeyAdapter()
507    {
 
508  0 toggle @Override
509    public void keyPressed(KeyEvent evt)
510    {
511  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
512    {
513  0 btn_cancel_ActionPerformed();
514    }
515    }
516    });
517  2 scrl_searchResult.setPreferredSize(new Dimension(width, height));
518   
519  2 cmb_searchTarget.setFont(VERDANA_12);
520  2 cmb_searchTarget.addItemListener(new ItemListener()
521    {
 
522  0 toggle @Override
523    public void itemStateChanged(ItemEvent e)
524    {
525  0 if (e.getStateChange() == ItemEvent.SELECTED)
526    {
527  0 String tooltipText;
528  0 if ("all".equalsIgnoreCase(
529    getCmbSearchTarget().getSelectedItem().toString()))
530    {
531  0 tooltipText = MessageManager.getString("label.search_all");
532    }
533  0 else if ("pdb id".equalsIgnoreCase(
534    getCmbSearchTarget().getSelectedItem().toString()))
535    {
536  0 tooltipText = MessageManager
537    .getString("label.separate_multiple_accession_ids");
538    }
539    else
540    {
541  0 tooltipText = MessageManager.formatMessage(
542    "label.separate_multiple_query_values", new Object[]
543    { getCmbSearchTarget().getSelectedItem().toString() });
544    }
545  0 txt_search.getComponent().setToolTipText(
546    JvSwingUtils.wrapTooltip(true, tooltipText));
547    // if (btn_autosearch.isSelected())
548  0 searchAction(true);
549   
550  0 setCmbSearchTargetTooltip();
551    }
552    }
553    });
554   
555  2 txt_search.getComponent().setFont(VERDANA_12);
556   
557  2 txt_search.addKeyListener(new KeyAdapter()
558    {
 
559  0 toggle @Override
560    public void keyPressed(KeyEvent e)
561    {
562  0 if (e.getKeyCode() == KeyEvent.VK_ENTER)
563    {
564  0 if (getTypedText() == null || getTypedText().isEmpty())
565    {
566  0 return;
567    }
568  0 String primaryKeyName = getFTSRestClient().getPrimaryKeyColumn()
569    .getName();
570  0 if (primaryKeyName.equalsIgnoreCase(
571    getCmbSearchTarget().getSelectedItem().toString()))
572    {
573    // TODO: nicer to show the list in the result set before
574    // viewing in Jalview perhaps ?
575  0 transferToSequenceFetcher(getTypedText());
576    }
577    else
578    {
579  0 performSearchAction();
580    }
581    }
582    }
583    });
584  2 final DeferredTextInputListener listener = new DeferredTextInputListener(
585    1500, new ActionListener()
586    {
 
587  0 toggle @Override
588    public void actionPerformed(ActionEvent e)
589    {
590  0 if (btn_autosearch.isSelected()
591    || txt_search.wasEnterPressed())
592    {
593  0 performSearchAction();
594    }
595    }
596    }, false);
597  2 txt_search.addDocumentListener(listener);
598   
599  2 txt_search.addFocusListener(new FocusListener()
600    {
 
601  0 toggle @Override
602    public void focusGained(FocusEvent e)
603    {
604  0 listener.start();
605    }
606   
 
607  0 toggle @Override
608    public void focusLost(FocusEvent e)
609    {
610    // listener.stop();
611    }
612    });
613   
614  2 txt_search.addActionListener(new ActionListener()
615    {
 
616  2 toggle @Override
617    public void actionPerformed(ActionEvent e)
618    {
619  2 performSearchAction();
620    }
621    });
622  2 final String searchTabTitle = MessageManager
623    .getString("label.search_result");
624  2 final String configureCols = MessageManager
625    .getString("label.configure_displayed_columns");
626  2 ChangeListener changeListener = new ChangeListener()
627    {
 
628  2 toggle @Override
629    public void stateChanged(ChangeEvent changeEvent)
630    {
631  2 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
632    .getSource();
633  2 int index = sourceTabbedPane.getSelectedIndex();
634   
635  2 btn_back.setVisible(true);
636  2 btn_cancel.setVisible(true);
637  2 btn_ok.setVisible(true);
638  2 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
639    {
640  0 btn_back.setVisible(false);
641  0 btn_cancel.setVisible(false);
642  0 btn_ok.setVisible(false);
643  0 btn_back.setEnabled(false);
644  0 btn_cancel.setEnabled(false);
645  0 btn_ok.setEnabled(false);
646  0 btn_next_page.setEnabled(false);
647  0 btn_prev_page.setEnabled(false);
648  0 txt_search.getComponent().setEnabled(false);
649  0 cmb_searchTarget.setEnabled(false);
650  0 previousWantedFields = getFTSRestClient()
651    .getAllDefaultDisplayedFTSDataColumns()
652    .toArray(new Object[0]);
653    }
654  2 if (sourceTabbedPane.getTitleAt(index).equals(searchTabTitle))
655    {
656  2 btn_back.setEnabled(true);
657  2 btn_cancel.setEnabled(true);
658  2 refreshPaginatorState();
659  2 txt_search.getComponent().setEnabled(true);
660  2 cmb_searchTarget.setEnabled(true);
661  2 if (wantedFieldsUpdated())
662    {
663  0 searchAction(true);
664  0 paginatorCart.clear();
665    }
666    else
667    {
668  2 validateSelection();
669    }
670    }
671    }
672    };
673  2 tabbedPane.addChangeListener(changeListener);
674  2 tabbedPane.setPreferredSize(new Dimension(width, height));
675  2 tabbedPane.add(searchTabTitle, scrl_searchResult);
676  2 tabbedPane.add(configureCols, new FTSDataColumnPreferences(
677    PreferenceSource.SEARCH_SUMMARY, getFTSRestClient()));
678   
679  2 pnl_actions.add(btn_back);
680  2 pnl_actions.add(btn_ok);
681  2 pnl_actions.add(btn_cancel);
682   
683  2 pnl_results.add(tabbedPane);
684  2 setCmbSearchTargetTooltip();
685  2 pnl_inputs.add(cmb_searchTarget);
686  2 pnl_inputs.add(txt_search.getComponent());
687  2 pnl_inputs.add(txt_help);
688  2 pnl_inputs.add(btn_autosearch);
689  2 pnl_inputs.add(lbl_loading);
690  2 pnl_inputs.add(lbl_warning);
691  2 pnl_inputs.add(lbl_blank);
692  2 pnl_inputs.add(btn_prev_page);
693  2 pnl_inputs.add(btn_next_page);
694   
695  2 this.setLayout(mainLayout);
696  2 this.add(pnl_inputs, java.awt.BorderLayout.NORTH);
697  2 this.add(pnl_results, java.awt.BorderLayout.CENTER);
698  2 this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
699  2 mainFrame.setFrameIcon(null);
700  2 mainFrame.setVisible(true);
701  2 if (tabs != null)
702    {
703  0 tabs.setOpaque(true);
704  0 tabs.insertTab(MessageManager.getString("label.free_text_search"),
705    null, this, "", 0);
706  0 mainFrame.setContentPane(tabs);
707  0 tabs.setVisible(true);
708    }
709    else
710    {
711  2 mainFrame.setContentPane(this);
712    }
713  2 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
714  2 mainFrame.addInternalFrameListener(
715    new javax.swing.event.InternalFrameAdapter()
716    {
 
717  0 toggle @Override
718    public void internalFrameClosing(InternalFrameEvent e)
719    {
720  0 closeAction();
721    }
722    });
723  2 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
724  2 Integer x = getTempUserPrefs().get("FTSPanel.x");
725  2 Integer y = getTempUserPrefs().get("FTSPanel.y");
726  2 if (x != null && y != null)
727    {
728  0 mainFrame.setLocation(x, y);
729    }
730  2 Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), width, height);
731    }
732   
733    abstract protected void showHelp();
734   
 
735  0 toggle protected void closeAction()
736    {
737  0 getTempUserPrefs().put("FTSPanel.width", this.getWidth());
738  0 getTempUserPrefs().put("FTSPanel.height", pnl_results.getHeight());
739  0 getTempUserPrefs().put("FTSPanel.x", mainFrame.getX());
740  0 getTempUserPrefs().put("FTSPanel.y", mainFrame.getY());
741  0 mainFrame.dispose();
742  0 txt_search.persistCache();
743    }
744   
 
745    public class DeferredTextInputListener implements DocumentListener
746    {
747    private final Timer swingTimer;
748   
 
749  2 toggle public DeferredTextInputListener(int timeOut, ActionListener listener,
750    boolean repeats)
751    {
752  2 swingTimer = new Timer(timeOut, listener);
753  2 swingTimer.setRepeats(repeats);
754    }
755   
 
756  0 toggle public void start()
757    {
758  0 swingTimer.start();
759    }
760   
 
761  0 toggle public void stop()
762    {
763  0 swingTimer.stop();
764    }
765   
 
766  0 toggle @Override
767    public void insertUpdate(DocumentEvent e)
768    {
769  0 swingTimer.restart();
770    }
771   
 
772  0 toggle @Override
773    public void removeUpdate(DocumentEvent e)
774    {
775  0 swingTimer.restart();
776    }
777   
 
778  0 toggle @Override
779    public void changedUpdate(DocumentEvent e)
780    {
781  0 swingTimer.restart();
782    }
783   
784    }
785   
 
786  2 toggle void performSearchAction()
787    {
788  2 String typed = getTypedText();
789  2 if (typed != null && typed.length() > 0
790    && !typed.equalsIgnoreCase(lastSearchTerm))
791    {
792  0 searchAction(true);
793  0 paginatorCart.clear();
794  0 lastSearchTerm = typed;
795    }
796    }
797   
 
798  2 toggle public boolean wantedFieldsUpdated()
799    {
800  2 if (previousWantedFields == null)
801    {
802  2 return false;
803    }
804   
805  0 return Arrays.equals(getFTSRestClient()
806    .getAllDefaultDisplayedFTSDataColumns().toArray(new Object[0]),
807    previousWantedFields) ? false : true;
808   
809    }
810   
 
811  2 toggle public void validateSelection()
812    {
813  2 if (tbl_summary.getSelectedRows().length > 0
814    || !paginatorCart.isEmpty())
815    {
816  0 btn_ok.setEnabled(true);
817    }
818    else
819    {
820  2 btn_ok.setEnabled(false);
821    }
822    }
823   
 
824  4 toggle public JComboBox<FTSDataColumnI> getCmbSearchTarget()
825    {
826  4 return cmb_searchTarget;
827    }
828   
 
829  0 toggle public JInternalFrame getMainFrame()
830    {
831  0 return mainFrame;
832    }
833   
 
834  0 toggle protected void delayAndEnableActionButtons()
835    {
836  0 new Thread()
837    {
 
838  0 toggle @Override
839    public void run()
840    {
841  0 try
842    {
843  0 Thread.sleep(1500);
844    } catch (InterruptedException e)
845    {
846  0 e.printStackTrace();
847    }
848  0 btn_ok.setEnabled(true);
849  0 btn_back.setEnabled(true);
850  0 btn_cancel.setEnabled(true);
851    }
852    }.start();
853    }
854   
 
855  0 toggle protected void checkForErrors()
856    {
857  0 lbl_warning.setVisible(false);
858  0 lbl_blank.setVisible(true);
859  0 if (errorWarning.length() > 0)
860    {
861  0 lbl_loading.setVisible(false);
862  0 lbl_blank.setVisible(false);
863  0 lbl_warning.setToolTipText(
864    JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
865  0 lbl_warning.setVisible(true);
866    }
867    }
868   
869    /**
870    * Action on Back button is to close this panel and open a new Sequence
871    * Fetcher panel
872    */
 
873  0 toggle public void btn_back_ActionPerformed()
874    {
875  0 closeAction();
876  0 new SequenceFetcher(progressIndicator);
877    }
878   
 
879  0 toggle protected void disableActionButtons()
880    {
881  0 btn_ok.setEnabled(false);
882  0 btn_back.setEnabled(false);
883  0 btn_cancel.setEnabled(false);
884    }
885   
 
886  0 toggle public void btn_cancel_ActionPerformed()
887    {
888  0 closeAction();
889    }
890   
891    /**
892    * Populates search target combo-box options
893    */
 
894  4 toggle public void populateCmbSearchTargetOptions()
895    {
896  4 List<FTSDataColumnI> searchableTargets = new ArrayList<>();
897  4 try
898    {
899  4 Collection<FTSDataColumnI> foundFTSTargets = getFTSRestClient()
900    .getSearchableDataColumns();
901  4 searchableTargets.addAll(foundFTSTargets);
902    } catch (Exception e)
903    {
904  0 e.printStackTrace();
905    }
906   
907  4 Collections.sort(searchableTargets, new Comparator<FTSDataColumnI>()
908    {
 
909  40 toggle @Override
910    public int compare(FTSDataColumnI o1, FTSDataColumnI o2)
911    {
912  40 return o1.getName().compareTo(o2.getName());
913    }
914    });
915   
916  4 for (FTSDataColumnI searchTarget : searchableTargets)
917    {
918  20 cmb_searchTarget.addItem(searchTarget);
919    }
920    }
921   
 
922  0 toggle public void transferToSequenceFetcher(String ids)
923    {
924  0 seqFetcher.setQuery(ids);
925  0 Thread worker = new Thread(seqFetcher);
926  0 worker.start();
927    }
928   
 
929  2 toggle @Override
930    public String getTypedText()
931    {
932  2 return txt_search.getUserInput();
933    }
934   
 
935  0 toggle @Override
936    public JTable getResultTable()
937    {
938  0 return tbl_summary;
939    }
940   
 
941  0 toggle public void reset()
942    {
943  0 lbl_loading.setVisible(false);
944  0 errorWarning.setLength(0);
945  0 lbl_warning.setVisible(false);
946  0 lbl_blank.setVisible(true);
947  0 btn_ok.setEnabled(false);
948  0 mainFrame.setTitle(getFTSFrameTitle());
949  0 refresh();
950  0 tbl_summary.setModel(new DefaultTableModel());
951  0 tbl_summary.setVisible(false);
952    }
953   
 
954  2 toggle @Override
955    public void setPrevPageButtonEnabled(boolean isEnabled)
956    {
957  2 btn_prev_page.setEnabled(isEnabled);
958    }
959   
 
960  2 toggle @Override
961    public void setNextPageButtonEnabled(boolean isEnabled)
962    {
963  2 btn_next_page.setEnabled(isEnabled);
964    }
965   
 
966  0 toggle @Override
967    public void setErrorMessage(String message)
968    {
969  0 errorWarning.append(message);
970    }
971   
 
972  0 toggle @Override
973    public void updateSearchFrameTitle(String title)
974    {
975  0 mainFrame.setTitle(title);
976    }
977   
 
978  0 toggle @Override
979    public void setSearchInProgress(Boolean isSearchInProgress)
980    {
981  0 lbl_blank.setVisible(!isSearchInProgress);
982  0 lbl_loading.setVisible(isSearchInProgress);
983  0 txt_search.setEditable(!isSearchInProgress);
984    }
985   
 
986  0 toggle @Override
987    public void prevPageAction()
988    {
989  0 updatePaginatorCart();
990  0 if (offSet >= pageLimit)
991    {
992  0 offSet = offSet - pageLimit;
993  0 searchAction(false);
994    }
995    else
996    {
997  0 refreshPaginatorState();
998    }
999    }
1000   
 
1001  0 toggle @Override
1002    public void nextPageAction()
1003    {
1004  0 updatePaginatorCart();
1005  0 offSet = offSet + pageLimit;
1006  0 searchAction(false);
1007    }
1008   
 
1009  0 toggle public void updatePaginatorCart()
1010    {
1011  0 int primaryKeyColIndex = 0;
1012  0 JTable resultTable = getResultTable();
1013  0 int totalRows = resultTable.getRowCount();
1014  0 try
1015    {
1016  0 primaryKeyColIndex = getFTSRestClient()
1017    .getPrimaryKeyColumIndex(wantedFields, false);
1018    } catch (Exception e)
1019    {
1020  0 e.printStackTrace();
1021    }
1022   
1023  0 for (int row = 0; row < totalRows; row++)
1024    {
1025  0 String id = (String) resultTable.getValueAt(row, primaryKeyColIndex);
1026  0 if (paginatorCart.contains(id))
1027    {
1028  0 paginatorCart.remove(id);
1029    }
1030    }
1031  0 int[] selectedRows = resultTable.getSelectedRows();
1032  0 for (int summaryRow : selectedRows)
1033    {
1034  0 String idStr = resultTable.getValueAt(summaryRow, primaryKeyColIndex)
1035    .toString();
1036  0 paginatorCart.add(idStr);
1037    }
1038    }
1039   
 
1040  0 toggle public void updateSummaryTableSelections()
1041    {
1042  0 JTable resultTable = getResultTable();
1043  0 if (paginatorCart.isEmpty())
1044    {
1045  0 return;
1046    }
1047  0 int primaryKeyColIndex = 0;
1048  0 try
1049    {
1050  0 primaryKeyColIndex = getFTSRestClient()
1051    .getPrimaryKeyColumIndex(wantedFields, false);
1052    } catch (Exception e)
1053    {
1054  0 e.printStackTrace();
1055    }
1056  0 int totalRows = resultTable.getRowCount();
1057  0 for (int row = 0; row < totalRows; row++)
1058    {
1059  0 String id = (String) resultTable.getValueAt(row, primaryKeyColIndex);
1060  0 if (paginatorCart.contains(id))
1061    {
1062  0 resultTable.addRowSelectionInterval(row, row);
1063    }
1064    }
1065  0 validateSelection();
1066    }
1067   
 
1068  2 toggle public void refreshPaginatorState()
1069    {
1070  2 setPrevPageButtonEnabled(false);
1071  2 setNextPageButtonEnabled(false);
1072  2 if (resultSetCount == 0 && pageLimit == 0)
1073    {
1074  2 return;
1075    }
1076  0 if (resultSetCount >= pageLimit)
1077    {
1078  0 setNextPageButtonEnabled(true);
1079    }
1080  0 if (offSet >= pageLimit)
1081    {
1082  0 setPrevPageButtonEnabled(true);
1083    }
1084    }
1085   
 
1086  0 toggle public void refresh()
1087    {
1088  0 mainFrame.setTitle(getFTSFrameTitle());
1089    }
1090   
1091    @Override
1092    public abstract void okAction();
1093   
 
1094  2 toggle private void setCmbSearchTargetTooltip()
1095    {
1096  2 JComboBox<FTSDataColumnI> cmb = getCmbSearchTarget();
1097  2 if (cmb.isEnabled())
1098    {
1099  2 boolean isAll = "all"
1100    .equalsIgnoreCase(cmb.getSelectedItem().toString());
1101  2 FTSDataColumnI index = (FTSDataColumnI) cmb.getSelectedItem();
1102  2 String indexCode = index.getAltCode();
1103  2 String dbName = getDbName();
1104  2 String message = isAll ? MessageManager
1105    .formatMessage("label.search_db_all", new Object[]
1106    { dbName })
1107    : MessageManager.formatMessage("label.search_db_index",
1108    new Object[]
1109    { dbName, indexCode });
1110  2 cmb.setToolTipText(message);
1111    }
1112    else
1113    {
1114  0 cmb.setToolTipText("");
1115    }
1116    }
1117    }