001: package org.columba.addressbook.gui.context;
002:
003: import java.util.Iterator;
004: import java.util.List;
005: import java.util.ResourceBundle;
006: import java.util.Vector;
007:
008: import javax.swing.ImageIcon;
009: import javax.swing.JComponent;
010:
011: import org.columba.addressbook.gui.search.SearchResultList;
012: import org.columba.api.gui.frame.IFrameMediator;
013: import org.columba.contact.search.ContactSearchProvider;
014: import org.columba.core.context.api.IContextProvider;
015: import org.columba.core.context.base.api.IStructureValue;
016: import org.columba.core.context.semantic.api.ISemanticContext;
017: import org.columba.core.resourceloader.IconKeys;
018: import org.columba.core.resourceloader.ImageLoader;
019: import org.columba.core.search.api.ISearchResult;
020:
021: // TODO: replace view with more detailed info view
022: public class ContactContextualProvider implements IContextProvider {
023:
024: private ResourceBundle bundle;
025:
026: private SearchResultList list;
027:
028: private ContactSearchProvider searchProvider;
029:
030: private List<ISearchResult> result;
031:
032: public ContactContextualProvider() {
033: super ();
034:
035: bundle = ResourceBundle
036: .getBundle("org.columba.addressbook.i18n.search");
037:
038: list = new SearchResultList();
039:
040: result = new Vector<ISearchResult>();
041:
042: searchProvider = new ContactSearchProvider();
043: }
044:
045: public String getTechnicalName() {
046: return "contact_list";
047: }
048:
049: public String getName() {
050: return bundle.getString("provider_title");
051: }
052:
053: public String getDescription() {
054: return bundle.getString("provider_title");
055: }
056:
057: public ImageIcon getIcon() {
058: return ImageLoader.getSmallIcon(IconKeys.ADDRESSBOOK);
059: }
060:
061: public int getTotalResultCount() {
062: return searchProvider.getTotalResultCount();
063: }
064:
065: public void search(ISemanticContext context, int startIndex,
066: int resultCount) {
067:
068: IStructureValue value = context.getValue();
069: if (value == null)
070: return;
071:
072: Iterator<IStructureValue> it = value.getChildIterator(
073: ISemanticContext.CONTEXT_NODE_IDENTITY,
074: ISemanticContext.CONTEXT_NAMESPACE_CORE);
075: // can be only one
076: IStructureValue identity = it.next();
077: if (identity == null)
078: return;
079:
080: String emailAddress = identity.getString(
081: ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
082: ISemanticContext.CONTEXT_NAMESPACE_CORE);
083: String displayname = identity.getString(
084: ISemanticContext.CONTEXT_ATTR_DISPLAY_NAME,
085: ISemanticContext.CONTEXT_NAMESPACE_CORE);
086:
087: if (emailAddress == null && displayname == null)
088: return;
089:
090: List<ISearchResult> temp;
091:
092: if (emailAddress != null) {
093: temp = searchProvider.query(emailAddress,
094: ContactSearchProvider.CRITERIA_EMAIL_CONTAINS,
095: false, 0, 5);
096: result.addAll(temp);
097: }
098:
099: if (displayname != null) {
100: temp = searchProvider
101: .query(
102: displayname,
103: ContactSearchProvider.CRITERIA_DISPLAYNAME_CONTAINS,
104: false, 0, 5);
105: result.addAll(temp);
106: }
107:
108: }
109:
110: public void showResult() {
111: list.addAll(result);
112: }
113:
114: public JComponent getView() {
115: return list;
116: }
117:
118: public void clear() {
119: result.clear();
120: list.clear();
121: }
122:
123: public boolean isEnabledShowMoreLink() {
124: return false;
125: }
126:
127: public void showMoreResults(IFrameMediator mediator) {
128: }
129:
130: }
|