001: package org.columba.mail.gui.context;
002:
003: import java.awt.BorderLayout;
004: import java.util.Iterator;
005: import java.util.List;
006: import java.util.ResourceBundle;
007: import java.util.Vector;
008:
009: import javax.swing.BorderFactory;
010: import javax.swing.ImageIcon;
011: import javax.swing.JComponent;
012: import javax.swing.JPanel;
013: import javax.swing.JScrollPane;
014:
015: import org.columba.api.gui.frame.IFrameMediator;
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.search.api.ISearchResult;
020: import org.columba.mail.gui.search.ResultList;
021: import org.columba.mail.resourceloader.IconKeys;
022: import org.columba.mail.resourceloader.MailImageLoader;
023: import org.columba.mail.search.MailSearchProvider;
024:
025: public class RecentMessagesContextualProvider implements
026: IContextProvider {
027: private ResourceBundle bundle;
028:
029: private ResultList list;
030:
031: private MailSearchProvider p;
032:
033: private List<ISearchResult> result = new Vector<ISearchResult>();
034:
035: private String emailAddress;
036:
037: private JPanel panel = new JPanel();
038:
039: private JScrollPane scrollPane;
040:
041: public RecentMessagesContextualProvider() {
042: bundle = ResourceBundle
043: .getBundle("org.columba.mail.i18n.search");
044:
045: panel.setLayout(new BorderLayout());
046: panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
047:
048: list = new ResultList();
049:
050: scrollPane = new JScrollPane(list);
051: scrollPane
052: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
053: panel.add(scrollPane, BorderLayout.CENTER);
054: }
055:
056: public String getTechnicalName() {
057: return "recent_messages_of_contact";
058: }
059:
060: public String getName() {
061: return bundle.getString("provider_related_title");
062: }
063:
064: public String getDescription() {
065: return bundle.getString("provider_related_title");
066: }
067:
068: public ImageIcon getIcon() {
069: return MailImageLoader.getSmallIcon(IconKeys.MESSAGE_READ);
070: }
071:
072: public int getTotalResultCount() {
073: return p.getTotalResultCount();
074: }
075:
076: public void search(ISemanticContext context, int startIndex,
077: int resultCount) {
078:
079: IStructureValue value = context.getValue();
080: if (value == null)
081: return;
082:
083: result.clear();
084:
085: Iterator<IStructureValue> it = value.getChildIterator(
086: ISemanticContext.CONTEXT_NODE_IDENTITY,
087: ISemanticContext.CONTEXT_NAMESPACE_CORE);
088: // can be only one
089: IStructureValue identity = it.next();
090: if (identity == null)
091: return;
092:
093: emailAddress = identity.getString(
094: ISemanticContext.CONTEXT_ATTR_EMAIL_ADDRESS,
095: ISemanticContext.CONTEXT_NAMESPACE_CORE);
096:
097: if (emailAddress == null)
098: return;
099:
100: p = new MailSearchProvider();
101: List<ISearchResult> r = p
102: .query(emailAddress,
103: MailSearchProvider.CRITERIA_FROM_CONTAINS,
104: false, 0, 20);
105:
106: result.addAll(r);
107: }
108:
109: public void showResult() {
110: list.addAll(result);
111: }
112:
113: public JComponent getView() {
114: return panel;
115: }
116:
117: public void clear() {
118:
119: list.clear();
120: }
121:
122: public boolean isEnabledShowMoreLink() {
123: return true;
124: }
125:
126: public void showMoreResults(IFrameMediator mediator) {
127: if (emailAddress == null)
128: return;
129:
130: // show all search results
131: p.showAllResults(mediator, emailAddress,
132: MailSearchProvider.CRITERIA_FROM_CONTAINS);
133: }
134:
135: }
|