001: package org.columba.calendar.ui.tagging;
002:
003: import java.util.Collection;
004:
005: import javax.swing.event.ListSelectionEvent;
006: import javax.swing.event.ListSelectionListener;
007:
008: import org.columba.api.gui.frame.IFrameMediator;
009: import org.columba.calendar.ui.frame.CalendarFrameMediator;
010: import org.columba.core.association.AssociationStore;
011: import org.columba.core.gui.tagging.TagList;
012: import org.columba.core.tagging.api.ITag;
013:
014: import com.miginfocom.calendar.activity.Activity;
015: import com.miginfocom.calendar.activity.ActivityDepository;
016: import com.miginfocom.calendar.category.Category;
017: import com.miginfocom.calendar.category.CategoryDepository;
018: import com.miginfocom.util.MigUtil;
019:
020: public class CalendarTagList extends TagList {
021:
022: private static final java.util.logging.Logger LOG = java.util.logging.Logger
023: .getLogger("org.columba.calendar.ui.tagging"); //$NON-NLS-1$
024:
025: public static final String PROP_FILTERED = "filterRow";
026:
027: private IFrameMediator frameMediator;
028:
029: public CalendarTagList(IFrameMediator frameMediator) {
030: super ();
031:
032: this .frameMediator = frameMediator;
033:
034: addListSelectionListener(new MyListSelectionListener());
035: }
036:
037: class MyListSelectionListener implements ListSelectionListener {
038: MyListSelectionListener() {
039: }
040:
041: public void valueChanged(ListSelectionEvent event) {
042: // return if selection change is in flux
043: if (event.getValueIsAdjusting()) {
044: return;
045: }
046:
047: ITag result = (ITag) getSelectedValue();
048:
049: //
050: // mark all activities with the tag
051: //
052:
053: Collection<String> messageList = AssociationStore
054: .getInstance().getAssociatedItems("tagging",
055: result.getId());
056: for (String id : messageList) {
057:
058: // example:
059: // "columba://org.columba.contact/<folder-id>/<contact-id>"
060: String s = id.toString();
061:
062: // TODO: @author fdietz replace with regular expression
063: int activityIndex = s.lastIndexOf('/');
064: String activityId = s.substring(activityIndex + 1, s
065: .length());
066: int folderIndex = s.lastIndexOf('/', activityIndex - 1);
067: String folderId = s.substring(folderIndex + 1,
068: activityIndex);
069: int componentIndex = s
070: .lastIndexOf('/', folderIndex - 1);
071: String componentId = s.substring(componentIndex + 1,
072: folderIndex);
073:
074: // check if its a calendar component
075: if (componentId.equals("org.columba.calendar")) {
076: // get calendar ui component depository
077: Activity act = ActivityDepository.getInstance()
078: .getActivity(activityId);
079: // add tag id as last
080: act.addCategoryID("tag_" + result.getId(),
081: MigUtil.BIG_INT);
082: }
083: }
084:
085: //
086: // now change all global categories
087: //
088:
089: // set all tags/categories to be *not* selected
090: clearAllTagCategories();
091:
092: // retrieve tag/category to be selected
093: Category category = retrieveTagCategory(result.getId());
094: if (category == null) {
095: System.out.println("add: " + result.getId());
096: // create new one
097: category = CategoryDepository.getRoot().addSubCategory(
098: "tag_" + result.getId(), result.getName());
099: }
100:
101: // mark it as selected
102: category.setProperty(Category.PROP_IS_HIDDEN, Boolean
103: .valueOf(false), Boolean.TRUE);
104: System.out.println("tag: " + category.getId().toString());
105:
106: // update calendar viewer
107: ((CalendarFrameMediator) frameMediator).getCalendarView()
108: .recreateFilterRows();
109:
110: }
111: }
112:
113: private Category retrieveTagCategory(String tagId) {
114: Collection<Category> c = CategoryDepository.getRoot()
115: .getChildrenDeep();
116: for (Category category : c) {
117: String categoryId = (String) category.getId();
118: if (categoryId.equals("tag_" + tagId))
119: return category;
120: }
121:
122: return null;
123: }
124:
125: private void clearAllTagCategories() {
126: CategoryDepository.getRoot().setPropertyDeep(
127: Category.PROP_IS_HIDDEN, Boolean.valueOf(true),
128: Boolean.TRUE);
129: }
130: }
|