JAL-1648 enabled caching for Select / Hide columns by annotation window
[jalview.git] / src / jalview / gui / AnnotationColumnChooser.java
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.gui;
23
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.io.cache.JvCacheableInputBox;
27 import jalview.schemes.AnnotationColourGradient;
28 import jalview.util.MessageManager;
29 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
30
31 import java.awt.BorderLayout;
32 import java.awt.CardLayout;
33 import java.awt.Color;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.awt.event.KeyEvent;
39 import java.util.Iterator;
40
41 import javax.swing.ButtonGroup;
42 import javax.swing.JCheckBox;
43 import javax.swing.JComboBox;
44 import javax.swing.JInternalFrame;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
48 import javax.swing.border.TitledBorder;
49
50 import net.miginfocom.swing.MigLayout;
51
52 @SuppressWarnings("serial")
53 public class AnnotationColumnChooser extends AnnotationRowFilter implements
54         ItemListener
55 {
56   private JPanel switchableViewsPanel = new JPanel(new CardLayout());
57
58   private JPanel annotationComboBoxPanel = new JPanel();
59
60   private StructureFilterPanel gStructureFilterPanel;
61
62   private StructureFilterPanel ngStructureFilterPanel;
63
64   private StructureFilterPanel currentStructureFilterPanel;
65
66   private SearchPanel currentSearchPanel;
67
68   private SearchPanel gSearchPanel;
69
70   private SearchPanel ngSearchPanel;
71
72   private FurtherActionPanel currentFurtherActionPanel;
73
74   private FurtherActionPanel gFurtherActionPanel;
75
76   private FurtherActionPanel ngFurtherActionPanel;
77
78   public static final int ACTION_OPTION_SELECT = 1;
79
80   public static int ACTION_OPTION_HIDE = 2;
81
82   public static String NO_GRAPH_VIEW = "0";
83
84   public static String GRAPH_VIEW = "1";
85
86   private int actionOption = ACTION_OPTION_SELECT;
87
88   private ColumnSelection oldColumnSelection;
89
90   public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
91   {
92     super(av, ap);
93     frame = new JInternalFrame();
94     frame.setContentPane(this);
95     frame.setLayer(JLayeredPane.PALETTE_LAYER);
96     Desktop.addInternalFrame(frame,
97             MessageManager.getString("label.select_by_annotation"), 520,
98             215);
99
100     addSliderChangeListener();
101     addSliderMouseListeners();
102
103     if (av.getAlignment().getAlignmentAnnotation() == null)
104     {
105       return;
106     }
107     setOldColumnSelection(av.getColumnSelection());
108     adjusting = true;
109
110     setAnnotations(new JComboBox<String>(getAnnotationItems(false)));
111     populateThresholdComboBox(threshold);
112
113     // restore Object state from the previous session if one exists
114     if (av.getAnnotationColumnSelectionState() != null)
115     {
116       currentSearchPanel = av.getAnnotationColumnSelectionState()
117               .getCurrentSearchPanel();
118       currentStructureFilterPanel = av.getAnnotationColumnSelectionState()
119               .getCurrentStructureFilterPanel();
120       annotations.setSelectedIndex(av.getAnnotationColumnSelectionState()
121               .getAnnotations().getSelectedIndex());
122       threshold.setSelectedIndex(av.getAnnotationColumnSelectionState()
123               .getThreshold().getSelectedIndex());
124       actionOption = av.getAnnotationColumnSelectionState()
125               .getActionOption();
126     }
127
128     try
129     {
130       jbInit();
131     } catch (Exception ex)
132     {
133     }
134     adjusting = false;
135
136     updateView();
137     frame.invalidate();
138     frame.pack();
139   }
140
141   @Override
142   protected void jbInit()
143   {
144     super.jbInit();
145
146     JPanel thresholdPanel = new JPanel();
147     thresholdPanel.setBorder(new TitledBorder(MessageManager
148             .getString("label.threshold_filter")));
149     thresholdPanel.setBackground(Color.white);
150     thresholdPanel.setFont(JvSwingUtils.getLabelFont());
151     thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
152
153     JPanel actionPanel = new JPanel();
154     actionPanel.setBackground(Color.white);
155     actionPanel.setFont(JvSwingUtils.getLabelFont());
156
157     JPanel graphFilterView = new JPanel();
158     graphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
159     graphFilterView.setBackground(Color.white);
160
161     JPanel noGraphFilterView = new JPanel();
162     noGraphFilterView.setLayout(new MigLayout("", "[left][right]", "[][]"));
163     noGraphFilterView.setBackground(Color.white);
164
165     annotationComboBoxPanel.setBackground(Color.white);
166     annotationComboBoxPanel.setFont(JvSwingUtils.getLabelFont());
167
168     gSearchPanel = new SearchPanel(this);
169     ngSearchPanel = new SearchPanel(this);
170     gFurtherActionPanel = new FurtherActionPanel(this);
171     ngFurtherActionPanel = new FurtherActionPanel(this);
172     gStructureFilterPanel = new StructureFilterPanel(this);
173     ngStructureFilterPanel = new StructureFilterPanel(this);
174
175     thresholdPanel.add(getThreshold());
176     thresholdPanel.add(thresholdValue, "wrap");
177     thresholdPanel.add(slider, "grow, span, wrap");
178
179     actionPanel.add(ok);
180     actionPanel.add(cancel);
181
182     graphFilterView.add(gSearchPanel, "grow, span, wrap");
183     graphFilterView.add(gStructureFilterPanel, "grow, span, wrap");
184     graphFilterView.add(thresholdPanel, "grow, span, wrap");
185     graphFilterView.add(gFurtherActionPanel);
186
187     noGraphFilterView.add(ngSearchPanel, "grow, span, wrap");
188     noGraphFilterView.add(ngStructureFilterPanel, "grow, span, wrap");
189     noGraphFilterView.add(ngFurtherActionPanel);
190
191     annotationComboBoxPanel.add(getAnnotations());
192     switchableViewsPanel.add(noGraphFilterView,
193             AnnotationColumnChooser.NO_GRAPH_VIEW);
194     switchableViewsPanel.add(graphFilterView,
195             AnnotationColumnChooser.GRAPH_VIEW);
196
197     this.setLayout(new BorderLayout());
198     this.add(annotationComboBoxPanel, java.awt.BorderLayout.PAGE_START);
199     this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
200     this.add(actionPanel, java.awt.BorderLayout.SOUTH);
201
202     selectedAnnotationChanged();
203     updateThresholdPanelToolTip();
204     this.validate();
205   }
206
207   protected void updateThresholdPanelToolTip()
208   {
209     thresholdValue.setToolTipText("");
210     slider.setToolTipText("");
211
212     String defaultTtip = MessageManager
213             .getString("info.change_threshold_mode_to_enable");
214
215     String thresh = getThreshold().getSelectedItem().toString();
216     if (thresh.equalsIgnoreCase("No Threshold"))
217     {
218       thresholdValue.setToolTipText(defaultTtip);
219       slider.setToolTipText(defaultTtip);
220     }
221   }
222
223   @Override
224   protected void reset()
225   {
226     if (this.getOldColumnSelection() != null)
227     {
228       av.getColumnSelection().clear();
229
230       if (av.getAnnotationColumnSelectionState() != null)
231       {
232         ColumnSelection oldSelection = av
233                 .getAnnotationColumnSelectionState()
234                 .getOldColumnSelection();
235         if (oldSelection != null && oldSelection.getHiddenColumns() != null
236                 && !oldSelection.getHiddenColumns().isEmpty())
237         {
238           for (Iterator<int[]> itr = oldSelection.getHiddenColumns()
239                   .iterator(); itr.hasNext();)
240           {
241             int positions[] = itr.next();
242             av.hideColumns(positions[0], positions[1]);
243           }
244         }
245         av.setColumnSelection(oldSelection);
246       }
247       ap.paintAlignment(true);
248     }
249
250   }
251
252   @Override
253   public void valueChanged(boolean updateAllAnnotation)
254   {
255     if (slider.isEnabled())
256     {
257       getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
258       updateView();
259       propagateSeqAssociatedThreshold(updateAllAnnotation,
260               getCurrentAnnotation());
261       ap.paintAlignment(false);
262     }
263   }
264
265   @Override
266   public void updateView()
267   {
268     // Check if combobox is still adjusting
269     if (adjusting)
270     {
271       return;
272     }
273
274     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
275
276     setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
277             .getSelectedIndex()]]);
278
279     int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
280             .getSelectedIndex());
281
282     slider.setEnabled(true);
283     thresholdValue.setEnabled(true);
284
285     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
286     {
287       slider.setEnabled(false);
288       thresholdValue.setEnabled(false);
289       thresholdValue.setText("");
290       // build filter params
291     }
292     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
293     {
294       if (getCurrentAnnotation().threshold == null)
295       {
296         getCurrentAnnotation()
297                 .setThreshold(
298                         new jalview.datamodel.GraphLine(
299                                 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
300                                 "Threshold", Color.black));
301       }
302
303       adjusting = true;
304       float range = getCurrentAnnotation().graphMax * 1000
305               - getCurrentAnnotation().graphMin * 1000;
306
307       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
308       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
309       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
310       thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
311       slider.setMajorTickSpacing((int) (range / 10f));
312       slider.setEnabled(true);
313       thresholdValue.setEnabled(true);
314       adjusting = false;
315
316       // build filter params
317       filterParams
318               .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
319       if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
320       {
321         filterParams
322                 .setThresholdValue(getCurrentAnnotation().threshold.value);
323
324         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
325         {
326           filterParams
327                   .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
328         }
329         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
330         {
331           filterParams
332                   .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
333         }
334       }
335     }
336
337     updateThresholdPanelToolTip();
338     if (currentStructureFilterPanel != null)
339     {
340       if (currentStructureFilterPanel.alphaHelix.isSelected())
341       {
342         filterParams.setFilterAlphaHelix(true);
343       }
344       if (currentStructureFilterPanel.betaStrand.isSelected())
345       {
346         filterParams.setFilterBetaSheet(true);
347       }
348       if (currentStructureFilterPanel.turn.isSelected())
349       {
350         filterParams.setFilterTurn(true);
351       }
352     }
353
354     if (currentSearchPanel != null)
355     {
356       if (!currentSearchPanel.searchBox.getUserInput().isEmpty())
357       {
358         filterParams.setRegexString(currentSearchPanel.searchBox
359                 .getUserInput());
360         if (currentSearchPanel.displayName.isSelected())
361         {
362           filterParams
363                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
364         }
365         if (currentSearchPanel.description.isSelected())
366         {
367           filterParams
368                   .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
369         }
370       }
371     }
372
373     av.getColumnSelection().filterAnnotations(
374             getCurrentAnnotation().annotations, filterParams);
375
376     av.showAllHiddenColumns();
377     if (getActionOption() == ACTION_OPTION_HIDE)
378     {
379       av.hideSelectedColumns();
380     }
381
382     filterParams = null;
383     av.setAnnotationColumnSelectionState(this);
384     ap.paintAlignment(true);
385   }
386
387   public ColumnSelection getOldColumnSelection()
388   {
389     return oldColumnSelection;
390   }
391
392   public void setOldColumnSelection(ColumnSelection currentColumnSelection)
393   {
394     if (currentColumnSelection != null)
395     {
396       this.oldColumnSelection = new ColumnSelection(currentColumnSelection);
397     }
398   }
399
400   public FurtherActionPanel getCurrentFutherActionPanel()
401   {
402     return currentFurtherActionPanel;
403   }
404
405   public void setCurrentFutherActionPanel(
406           FurtherActionPanel currentFutherActionPanel)
407   {
408     this.currentFurtherActionPanel = currentFutherActionPanel;
409   }
410
411   public SearchPanel getCurrentSearchPanel()
412   {
413     return currentSearchPanel;
414   }
415
416   public void setCurrentSearchPanel(SearchPanel currentSearchPanel)
417   {
418     this.currentSearchPanel = currentSearchPanel;
419   }
420
421   public int getActionOption()
422   {
423     return actionOption;
424   }
425
426   public void setActionOption(int actionOption)
427   {
428     this.actionOption = actionOption;
429   }
430
431   public StructureFilterPanel getCurrentStructureFilterPanel()
432   {
433     return currentStructureFilterPanel;
434   }
435
436   public void setCurrentStructureFilterPanel(
437           StructureFilterPanel currentStructureFilterPanel)
438   {
439     this.currentStructureFilterPanel = currentStructureFilterPanel;
440   }
441
442   public void select_action(ActionEvent actionEvent)
443   {
444     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
445     if (radioButton.isSelected())
446     {
447       setActionOption(ACTION_OPTION_SELECT);
448       updateView();
449     }
450   }
451
452   public void hide_action(ActionEvent actionEvent)
453   {
454     JRadioButton radioButton = (JRadioButton) actionEvent.getSource();
455     if (radioButton.isSelected())
456     {
457       setActionOption(ACTION_OPTION_HIDE);
458       updateView();
459     }
460   }
461
462   @Override
463   public void itemStateChanged(ItemEvent e)
464   {
465     selectedAnnotationChanged();
466   }
467
468   @Override
469   public void selectedAnnotationChanged()
470   {
471     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
472     if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
473             .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH)
474     {
475       currentView = AnnotationColumnChooser.GRAPH_VIEW;
476     }
477     saveCache();
478     gSearchPanel.syncState();
479     gFurtherActionPanel.syncState();
480     gStructureFilterPanel.syncState();
481
482     ngSearchPanel.syncState();
483     ngFurtherActionPanel.syncState();
484     ngStructureFilterPanel.syncState();
485
486     CardLayout switchableViewsLayout = (CardLayout) switchableViewsPanel
487             .getLayout();
488     switchableViewsLayout.show(switchableViewsPanel, currentView);
489     updateView();
490   }
491
492   public class FurtherActionPanel extends JPanel
493   {
494     private AnnotationColumnChooser aColChooser;
495
496     private JRadioButton hideOption = new JRadioButton();
497
498     private JRadioButton selectOption = new JRadioButton();
499
500     private ButtonGroup optionsGroup = new ButtonGroup();
501
502     public FurtherActionPanel(AnnotationColumnChooser aColChooser)
503     {
504       this.aColChooser = aColChooser;
505       JvSwingUtils.jvInitComponent(selectOption, "action.select");
506       selectOption.addActionListener(new ActionListener()
507       {
508         @Override
509         public void actionPerformed(ActionEvent actionEvent)
510         {
511           selectRadioAction(actionEvent);
512         }
513       });
514
515       JvSwingUtils.jvInitComponent(hideOption, "action.hide");
516       hideOption.addActionListener(new ActionListener()
517       {
518         @Override
519         public void actionPerformed(ActionEvent actionEvent)
520         {
521           hideRadioAction(actionEvent);
522         }
523       });
524
525       optionsGroup.add(selectOption);
526       optionsGroup.add(hideOption);
527       optionsGroup.setSelected(selectOption.getModel(), true);
528
529       JvSwingUtils.jvInitComponent(this);
530       syncState();
531
532       this.add(selectOption);
533       this.add(hideOption);
534     }
535
536     public void selectRadioAction(ActionEvent actionEvent)
537     {
538       aColChooser.setCurrentFutherActionPanel(this);
539       aColChooser.select_action(actionEvent);
540     }
541
542     public void hideRadioAction(ActionEvent actionEvent)
543     {
544       aColChooser.setCurrentFutherActionPanel(this);
545       aColChooser.hide_action(actionEvent);
546     }
547
548     public void syncState()
549     {
550       if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
551       {
552         this.optionsGroup.setSelected(this.hideOption.getModel(), true);
553       }
554       else
555       {
556         this.optionsGroup.setSelected(this.selectOption.getModel(), true);
557       }
558     }
559   }
560
561   public class StructureFilterPanel extends JPanel
562   {
563     private AnnotationColumnChooser aColChooser;
564
565     private JCheckBox alphaHelix = new JCheckBox();
566
567     private JCheckBox betaStrand = new JCheckBox();
568
569     private JCheckBox turn = new JCheckBox();
570
571     private JCheckBox all = new JCheckBox();
572
573     public StructureFilterPanel(AnnotationColumnChooser aColChooser)
574     {
575       this.aColChooser = aColChooser;
576
577       JvSwingUtils.jvInitComponent(alphaHelix, "label.alpha_helix");
578       alphaHelix.addActionListener(new ActionListener()
579       {
580         @Override
581         public void actionPerformed(ActionEvent actionEvent)
582         {
583           alphaHelix_actionPerformed();
584         }
585       });
586
587       JvSwingUtils.jvInitComponent(betaStrand, "label.beta_strand");
588       betaStrand.addActionListener(new ActionListener()
589       {
590         @Override
591         public void actionPerformed(ActionEvent actionEvent)
592         {
593           betaStrand_actionPerformed();
594         }
595       });
596
597       JvSwingUtils.jvInitComponent(turn, "label.turn");
598       turn.addActionListener(new ActionListener()
599       {
600         @Override
601         public void actionPerformed(ActionEvent actionEvent)
602         {
603           turn_actionPerformed();
604         }
605       });
606
607       JvSwingUtils.jvInitComponent(all, "label.select_all");
608       all.addActionListener(new ActionListener()
609       {
610         @Override
611         public void actionPerformed(ActionEvent actionEvent)
612         {
613           all_actionPerformed();
614         }
615       });
616
617       this.setBorder(new TitledBorder(MessageManager
618               .getString("label.structures_filter")));
619       JvSwingUtils.jvInitComponent(this);
620
621       this.add(all);
622       this.add(alphaHelix);
623       this.add(betaStrand);
624       this.add(turn);
625     }
626
627     public void alphaHelix_actionPerformed()
628     {
629       updateSelectAllState();
630       aColChooser.setCurrentStructureFilterPanel(this);
631       aColChooser.updateView();
632     }
633
634     public void betaStrand_actionPerformed()
635     {
636       updateSelectAllState();
637       aColChooser.setCurrentStructureFilterPanel(this);
638       aColChooser.updateView();
639     }
640
641     public void turn_actionPerformed()
642     {
643       updateSelectAllState();
644       aColChooser.setCurrentStructureFilterPanel(this);
645       aColChooser.updateView();
646     }
647
648     public void all_actionPerformed()
649     {
650       if (all.isSelected())
651       {
652         alphaHelix.setSelected(true);
653         betaStrand.setSelected(true);
654         turn.setSelected(true);
655       }
656       else
657       {
658         alphaHelix.setSelected(false);
659         betaStrand.setSelected(false);
660         turn.setSelected(false);
661       }
662       aColChooser.setCurrentStructureFilterPanel(this);
663       aColChooser.updateView();
664     }
665
666     public void updateSelectAllState()
667     {
668       if (alphaHelix.isSelected() && betaStrand.isSelected()
669               && turn.isSelected())
670       {
671         all.setSelected(true);
672       }
673       else
674       {
675         all.setSelected(false);
676       }
677     }
678
679     public void syncState()
680     {
681       StructureFilterPanel sfp = aColChooser
682               .getCurrentStructureFilterPanel();
683       if (sfp != null)
684       {
685         alphaHelix.setSelected(sfp.alphaHelix.isSelected());
686         betaStrand.setSelected(sfp.betaStrand.isSelected());
687         turn.setSelected(sfp.turn.isSelected());
688         if (sfp.all.isSelected())
689         {
690           all.setSelected(true);
691           alphaHelix.setSelected(true);
692           betaStrand.setSelected(true);
693           turn.setSelected(true);
694         }
695       }
696
697     }
698   }
699
700   public class SearchPanel extends JPanel
701   {
702     private AnnotationColumnChooser aColChooser;
703
704     private JCheckBox displayName = new JCheckBox();
705
706     private JCheckBox description = new JCheckBox();
707
708     private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT";
709
710     public JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<String>(
711             FILTER_BY_ANN_CACHE_KEY);
712
713     public SearchPanel(AnnotationColumnChooser aColChooser)
714     {
715
716       this.aColChooser = aColChooser;
717       JvSwingUtils.jvInitComponent(this);
718       this.setBorder(new TitledBorder(MessageManager
719               .getString("label.search_filter")));
720
721       searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX");
722       searchBox.setToolTipText(MessageManager
723               .getString("info.enter_search_text_here"));
724       searchBox.getEditor().getEditorComponent()
725               .addKeyListener(new java.awt.event.KeyAdapter()
726               {
727                 @Override
728                 public void keyPressed(KeyEvent e)
729                 {
730                   if (e.getKeyCode() == KeyEvent.VK_ENTER)
731                   {
732                     e.consume();
733                     searchStringAction();
734                   }
735                 }
736               });
737
738
739
740       JvSwingUtils.jvInitComponent(displayName, "label.label");
741       displayName.addActionListener(new ActionListener()
742       {
743         @Override
744         public void actionPerformed(ActionEvent actionEvent)
745         {
746           displayNameCheckboxAction();
747         }
748       });
749
750       JvSwingUtils.jvInitComponent(description, "label.description");
751       description.addActionListener(new ActionListener()
752       {
753         @Override
754         public void actionPerformed(ActionEvent actionEvent)
755         {
756           discriptionCheckboxAction();
757         }
758       });
759
760       syncState();
761       this.add(searchBox);
762       this.add(displayName);
763       this.add(description);
764     }
765
766     public void displayNameCheckboxAction()
767     {
768       aColChooser.setCurrentSearchPanel(this);
769       aColChooser.updateView();
770     }
771
772     public void discriptionCheckboxAction()
773     {
774       aColChooser.setCurrentSearchPanel(this);
775       aColChooser.updateView();
776     }
777
778     public void searchStringAction()
779     {
780       aColChooser.setCurrentSearchPanel(this);
781       aColChooser.updateView();
782       updateSearchPanelToolTips();
783       searchBox.updateCache();
784     }
785
786     public void syncState()
787     {
788       SearchPanel sp = aColChooser.getCurrentSearchPanel();
789       if (sp != null)
790       {
791         description.setEnabled(sp.description.isEnabled());
792         description.setSelected(sp.description.isSelected());
793
794         displayName.setEnabled(sp.displayName.isEnabled());
795         displayName.setSelected(sp.displayName.isSelected());
796
797         searchBox.setSelectedItem(sp.searchBox.getUserInput());
798       }
799       updateSearchPanelToolTips();
800     }
801
802     public void updateSearchPanelToolTips()
803     {
804       String defaultTtip = MessageManager
805               .getString("info.enter_search_text_to_enable");
806       String labelTtip = MessageManager.formatMessage(
807               "info.search_in_annotation_label", annotations
808                       .getSelectedItem().toString());
809       String descTtip = MessageManager.formatMessage(
810               "info.search_in_annotation_description", annotations
811                       .getSelectedItem().toString());
812       displayName.setToolTipText(displayName.isEnabled() ? labelTtip
813               : defaultTtip);
814       description.setToolTipText(description.isEnabled() ? descTtip
815               : defaultTtip);
816     }
817   }
818
819   @Override
820   public void ok_actionPerformed()
821   {
822     saveCache();
823     super.ok_actionPerformed();
824   }
825
826   @Override
827   public void cancel_actionPerformed()
828   {
829     saveCache();
830     super.cancel_actionPerformed();
831   }
832
833   private void saveCache()
834   {
835     gSearchPanel.searchBox.persistCache();
836     ngSearchPanel.searchBox.persistCache();
837     gSearchPanel.searchBox.updateCache();
838     ngSearchPanel.searchBox.updateCache();
839   }
840 }