001: package org.columba.calendar.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.api.gui.frame.IFrameMediator;
012: import org.columba.calendar.search.CalendarSearchProvider;
013: import org.columba.calendar.ui.search.SearchResultList;
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: public class CalendarContextProvider implements IContextProvider {
022: private ResourceBundle bundle;
023:
024: private List<ISearchResult> result;
025:
026: private SearchResultList resultList;
027:
028: private CalendarSearchProvider searchProvider;
029:
030: public CalendarContextProvider() {
031: resultList = new SearchResultList();
032:
033: bundle = ResourceBundle
034: .getBundle("org.columba.calendar.i18n.search");
035:
036: result = new Vector<ISearchResult>();
037:
038: searchProvider = new CalendarSearchProvider();
039: }
040:
041: public void clear() {
042: resultList.clear();
043: result.clear();
044: }
045:
046: public String getTechnicalName() {
047: return "calendar_list";
048: }
049:
050: public String getName() {
051: return bundle.getString("provider_related_title");
052: }
053:
054: public String getDescription() {
055: return bundle.getString("provider_related_title");
056: }
057:
058: public ImageIcon getIcon() {
059: return ImageLoader.getSmallIcon(IconKeys.CALENDAR);
060: }
061:
062: public int getTotalResultCount() {
063: return searchProvider.getTotalResultCount();
064: }
065:
066: public JComponent getView() {
067: return resultList;
068: }
069:
070: public boolean isEnabledShowMoreLink() {
071: return false;
072: }
073:
074: public void search(ISemanticContext context, int startIndex,
075: int resultCount) {
076: IStructureValue value = context.getValue();
077: if (value == null)
078: return;
079:
080: Iterator<IStructureValue> it = value.getChildIterator(
081: ISemanticContext.CONTEXT_NODE_MESSAGE,
082: ISemanticContext.CONTEXT_NAMESPACE_CORE);
083:
084: if (it.hasNext()) {
085: // we only use the first message
086: IStructureValue message = it.next();
087:
088: // retrieve subject
089: String subject = message.getString(
090: ISemanticContext.CONTEXT_ATTR_SUBJECT,
091: ISemanticContext.CONTEXT_NAMESPACE_CORE);
092:
093: if (subject != null) {
094: List<ISearchResult> temp = searchProvider
095: .query(
096: subject,
097: CalendarSearchProvider.CRITERIA_SUMMARY_CONTAINS,
098: false, 0, 5);
099: result.addAll(temp);
100: }
101: }
102:
103: }
104:
105: public void showMoreResults(IFrameMediator mediator) {
106: throw new IllegalArgumentException("not implemented yet");
107: }
108:
109: public void showResult() {
110: resultList.addAll(result);
111: }
112: }
|