KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > folders > SearchInSelectedFolder


1 package SnowMailClient.view.folders;
2
3 import SnowMailClient.model.folders.*;
4 import SnowMailClient.model.*;
5 import snow.utils.gui.*;
6 import SnowMailClient.SnowMailClientApp;
7 import SnowMailClient.Language.Language;
8
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import javax.swing.event.*;
13 import javax.swing.tree.*;
14
15 public class SearchInSelectedFolder extends AbstractAction implements TreeSelectionListener
16 {
17
18   JTree tree;
19   FolderTreeNode node;
20
21   public SearchInSelectedFolder( FolderTreeNode node, JTree tree)
22   {
23     super(Language.translate("Search in folder %",(node!=null?" "+node.getFolderName():"")));
24     putValue(AbstractAction.SMALL_ICON, Icons.SearchIcon.shared18);
25     this.tree = tree;
26     this.node = node;
27     tree.getSelectionModel().addTreeSelectionListener(this);
28   }
29
30   public void valueChanged(TreeSelectionEvent e)
31   {
32     this.setEnabled( tree.getSelectionCount()==1 );
33   }
34
35   public void actionPerformed(ActionEvent e)
36   {
37     Thread JavaDoc t = new Thread JavaDoc()
38     {
39       public void run()
40       {
41          search();
42       }
43     };
44     t.setPriority(Thread.NORM_PRIORITY-1);
45     t.start();
46
47   }
48
49   /** Should be called in a separate thread !
50   */

51   private void search()
52   {
53      String JavaDoc searchText = JOptionPane.showInputDialog(tree,
54        Language.translate("Enter the text to search in the folder"),
55        Language.translate("Text search in folder")+(node!=null?" "+node.getFolderName():""),
56        JOptionPane.QUESTION_MESSAGE);
57
58      if(searchText==null) return;
59
60      ProgressModalDialog progressDialog = new ProgressModalDialog(
61          SnowMailClientApp.getInstance(),
62          Language.translate("Searching")+"...", false, false);
63      progressDialog.start();
64
65      try
66      {
67         final SearchResults sr = new SearchResults();
68         SnowMailClientApp.getInstance().getSearchPanel().setModel(sr);
69         EventQueue.invokeLater(new Runnable JavaDoc() { public void run() {
70           SnowMailClientApp.getInstance().makeSearchTreeVisible();
71         }});
72
73         node.searchMailMessagesContaining(searchText, sr, true);
74
75      }
76      catch(Exception JavaDoc e2)
77      {
78        e2.printStackTrace();
79        JOptionPane.showMessageDialog(tree,
80          Language.translate("Error")+": "+e2.getMessage(),
81          Language.translate("Error occured during folder text search"),
82           JOptionPane.ERROR_MESSAGE);
83      }
84      finally
85      {
86        progressDialog.closeDialog();
87      }
88   }
89
90 } // SearchInSelectedFolder
Popular Tags