KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > context > ContactContextualProvider


1 package org.columba.addressbook.gui.context;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.ResourceBundle JavaDoc;
6 import java.util.Vector JavaDoc;
7
8 import javax.swing.ImageIcon JavaDoc;
9 import javax.swing.JComponent JavaDoc;
10
11 import org.columba.addressbook.gui.search.SearchResultList;
12 import org.columba.api.gui.frame.IFrameMediator;
13 import org.columba.contact.search.ContactSearchProvider;
14 import org.columba.core.context.api.IContextProvider;
15 import org.columba.core.context.base.api.IStructureValue;
16 import org.columba.core.context.semantic.api.ISemanticContext;
17 import org.columba.core.resourceloader.IconKeys;
18 import org.columba.core.resourceloader.ImageLoader;
19 import org.columba.core.search.api.ISearchResult;
20
21 // TODO: replace view with more detailed info view
22
public class ContactContextualProvider implements
23         IContextProvider {
24
25     private ResourceBundle JavaDoc bundle;
26
27     private SearchResultList list;
28
29     private ContactSearchProvider searchProvider;
30
31     private List JavaDoc<ISearchResult> result;
32
33     public ContactContextualProvider() {
34         super();
35
36         bundle = ResourceBundle
37                 .getBundle("org.columba.addressbook.i18n.search");
38
39         list = new SearchResultList();
40
41         result = new Vector JavaDoc<ISearchResult>();
42         
43         searchProvider = new ContactSearchProvider();
44     }
45
46     public String JavaDoc getTechnicalName() {
47         return "contact_list";
48     }
49     
50     public String JavaDoc getName() {
51         return bundle.getString("provider_title");
52     }
53
54     public String JavaDoc getDescription() {
55         return bundle.getString("provider_title");
56     }
57
58     public ImageIcon JavaDoc getIcon() {
59         return ImageLoader.getSmallIcon(IconKeys.ADDRESSBOOK);
60     }
61
62     public int getTotalResultCount() {
63         return searchProvider.getTotalResultCount();
64     }
65
66     public void search(ISemanticContext context, int startIndex, int resultCount) {
67
68         IStructureValue value = context.getValue();
69         if ( value == null ) return;
70         
71         Iterator JavaDoc<IStructureValue> it = value.getChildIterator(
72                 ISemanticContext.CONTEXT_NODE_IDENTITY,
73                 ISemanticContext.CONTEXT_NAMESPACE_CORE);
74         // can be only one
75
IStructureValue identity = it.next();
76         if (identity == null)
77             return;
78
79         String JavaDoc emailAddress = identity.getString(
80                 ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
81                 ISemanticContext.CONTEXT_NAMESPACE_CORE);
82         String JavaDoc displayname = identity.getString(
83                 ISemanticContext.CONTEXT_ATTR_DISPLAY_NAME,
84                 ISemanticContext.CONTEXT_NAMESPACE_CORE);
85
86         if (emailAddress == null && displayname == null)
87             return;
88
89         List JavaDoc<ISearchResult> temp;
90
91         if (emailAddress != null) {
92             temp = searchProvider.query(emailAddress,
93                     ContactSearchProvider.CRITERIA_EMAIL_CONTAINS, false, 0, 5);
94             result.addAll(temp);
95         }
96
97         if (displayname != null) {
98             temp = searchProvider.query(displayname,
99             ContactSearchProvider.CRITERIA_DISPLAYNAME_CONTAINS, false, 0, 5);
100             result.addAll(temp);
101         }
102
103     }
104
105     public void showResult() {
106         list.addAll(result);
107     }
108
109     public JComponent JavaDoc getView() {
110         return list;
111     }
112
113     public void clear() {
114         result.clear();
115         list.clear();
116     }
117
118     public boolean isEnabledShowMoreLink() {
119         return false;
120     }
121
122     public void showMoreResults(IFrameMediator mediator) {
123     }
124
125     
126
127 }
128
Popular Tags