KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > context > RecentMessagesContextualProvider


1 package org.columba.mail.gui.context;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.ResourceBundle JavaDoc;
7 import java.util.Vector JavaDoc;
8
9 import javax.swing.BorderFactory JavaDoc;
10 import javax.swing.ImageIcon JavaDoc;
11 import javax.swing.JComponent JavaDoc;
12 import javax.swing.JPanel JavaDoc;
13 import javax.swing.JScrollPane JavaDoc;
14
15 import org.columba.api.gui.frame.IFrameMediator;
16 import org.columba.core.context.api.IContextProvider;
17 import org.columba.core.context.base.api.IStructureValue;
18 import org.columba.core.context.semantic.api.ISemanticContext;
19 import org.columba.core.search.api.ISearchResult;
20 import org.columba.mail.gui.search.ResultList;
21 import org.columba.mail.resourceloader.IconKeys;
22 import org.columba.mail.resourceloader.MailImageLoader;
23 import org.columba.mail.search.MailSearchProvider;
24
25 public class RecentMessagesContextualProvider implements IContextProvider {
26     private ResourceBundle JavaDoc bundle;
27
28     private ResultList list;
29
30     private MailSearchProvider p;
31
32     private List JavaDoc<ISearchResult> result = new Vector JavaDoc<ISearchResult>();
33
34     private String JavaDoc emailAddress;
35
36     private JPanel JavaDoc panel = new JPanel JavaDoc();
37
38     private JScrollPane JavaDoc scrollPane;
39
40     public RecentMessagesContextualProvider() {
41         bundle = ResourceBundle.getBundle("org.columba.mail.i18n.search");
42
43         panel.setLayout(new BorderLayout JavaDoc());
44         panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
45
46         list = new ResultList();
47
48         scrollPane = new JScrollPane JavaDoc(list);
49         scrollPane
50                 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
51         panel.add(scrollPane, BorderLayout.CENTER);
52     }
53
54     public String JavaDoc getTechnicalName() {
55         return "recent_messages_of_contact";
56     }
57
58     public String JavaDoc getName() {
59         return bundle.getString("provider_related_title");
60     }
61
62     public String JavaDoc getDescription() {
63         return bundle.getString("provider_related_title");
64     }
65
66     public ImageIcon JavaDoc getIcon() {
67         return MailImageLoader.getSmallIcon(IconKeys.MESSAGE_READ);
68     }
69
70     public int getTotalResultCount() {
71         return p.getTotalResultCount();
72     }
73
74     public void search(ISemanticContext context, int startIndex, int resultCount) {
75
76         IStructureValue value = context.getValue();
77         if (value == null)
78             return;
79
80         result.clear();
81
82         Iterator JavaDoc<IStructureValue> it = value.getChildIterator(
83                 ISemanticContext.CONTEXT_NODE_IDENTITY,
84                 ISemanticContext.CONTEXT_NAMESPACE_CORE);
85         // can be only one
86
IStructureValue identity = it.next();
87         if (identity == null)
88             return;
89
90         emailAddress = identity.getString(
91                 ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
92                 ISemanticContext.CONTEXT_NAMESPACE_CORE);
93
94         if (emailAddress == null)
95             return;
96
97         p = new MailSearchProvider();
98         List JavaDoc<ISearchResult> r = p.query(emailAddress,
99                 MailSearchProvider.CRITERIA_FROM_CONTAINS, false, 0, 20);
100
101         result.addAll(r);
102     }
103
104     public void showResult() {
105         list.addAll(result);
106     }
107
108     public JComponent JavaDoc getView() {
109         return panel;
110     }
111
112     public void clear() {
113
114         list.clear();
115     }
116
117     public boolean isEnabledShowMoreLink() {
118         return true;
119     }
120
121     public void showMoreResults(IFrameMediator mediator) {
122         if (emailAddress == null)
123             return;
124
125         // show all search results
126
p.showAllResults(mediator, emailAddress,
127                 MailSearchProvider.CRITERIA_FROM_CONTAINS);
128     }
129
130 }
131
Popular Tags