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: import javax.swing.JPanel;
011:
012: import org.columba.addressbook.model.IContactModel;
013: import org.columba.api.gui.frame.IFrameMediator;
014: import org.columba.contact.search.ContactSearchProvider;
015: import org.columba.contact.search.ContactSearchResult;
016: import org.columba.core.context.api.IContextProvider;
017: import org.columba.core.context.base.api.IStructureValue;
018: import org.columba.core.context.semantic.api.ISemanticContext;
019: import org.columba.core.resourceloader.IconKeys;
020: import org.columba.core.resourceloader.ImageLoader;
021: import org.columba.core.search.api.ISearchResult;
022: import org.jdesktop.swingx.VerticalLayout;
023:
024: // TODO: fix layout to look good, even if there's not enough information provided
025: public class ContactDetailsContextualProvider implements
026: IContextProvider {
027:
028: private ResourceBundle bundle;
029:
030: private ContactSearchProvider searchProvider;
031:
032: private List<ISearchResult> result;
033:
034: private JPanel panel = new JPanel();
035:
036: public ContactDetailsContextualProvider() {
037: super ();
038:
039: panel.setLayout(new VerticalLayout());
040:
041: bundle = ResourceBundle
042: .getBundle("org.columba.addressbook.i18n.search");
043:
044: result = new Vector<ISearchResult>();
045:
046: searchProvider = new ContactSearchProvider();
047: }
048:
049: public String getTechnicalName() {
050: return "contact_details_list";
051: }
052:
053: public String getName() {
054: return bundle.getString("provider_related_title");
055: }
056:
057: public String getDescription() {
058: return bundle.getString("provider_related_title");
059: }
060:
061: public ImageIcon getIcon() {
062: return ImageLoader.getSmallIcon(IconKeys.ADDRESSBOOK);
063: }
064:
065: public int getTotalResultCount() {
066: return searchProvider.getTotalResultCount();
067: }
068:
069: public void search(ISemanticContext context, int startIndex,
070: int resultCount) {
071:
072: IStructureValue value = context.getValue();
073: if (value == null)
074: return;
075:
076: Iterator<IStructureValue> it = value.getChildIterator(
077: ISemanticContext.CONTEXT_NODE_IDENTITY,
078: ISemanticContext.CONTEXT_NAMESPACE_CORE);
079: if (it.hasNext()) {
080: // can be only one
081: IStructureValue identity = it.next();
082: if (identity == null)
083: return;
084:
085: String emailAddress = identity.getString(
086: ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
087: ISemanticContext.CONTEXT_NAMESPACE_CORE);
088: String displayname = identity.getString(
089: ISemanticContext.CONTEXT_ATTR_DISPLAY_NAME,
090: ISemanticContext.CONTEXT_NAMESPACE_CORE);
091:
092: if (emailAddress == null && displayname == null)
093: return;
094:
095: List<ISearchResult> temp;
096:
097: if (emailAddress != null) {
098: temp = searchProvider.query(emailAddress,
099: ContactSearchProvider.CRITERIA_EMAIL_CONTAINS,
100: false, 0, 5);
101: result.addAll(temp);
102: }
103:
104: if (displayname != null) {
105: temp = searchProvider
106: .query(
107: displayname,
108: ContactSearchProvider.CRITERIA_DISPLAYNAME_CONTAINS,
109: false, 0, 5);
110: result.addAll(temp);
111: }
112: }
113:
114: }
115:
116: public void showResult() {
117: panel.removeAll();
118:
119: Iterator it2 = result.listIterator();
120: while (it2.hasNext()) {
121: ContactSearchResult r = (ContactSearchResult) it2.next();
122: IContactModel m = r.getModel();
123:
124: ContactDetailPanel p = new ContactDetailPanel(m, r);
125:
126: panel.add(p);
127: }
128:
129: panel.revalidate();
130: panel.validate();
131: }
132:
133: public JComponent getView() {
134: return panel;
135: }
136:
137: public void clear() {
138:
139: result.clear();
140: }
141:
142: public boolean isEnabledShowMoreLink() {
143: return false;
144: }
145:
146: public void showMoreResults(IFrameMediator mediator) {
147: }
148:
149: }
|