1 package net.sf.flock.webapp.components;
2 import java.util.Collection;
3 import java.util.Map;
4 import java.util.TreeMap;
5
6 import net.sf.flock.FilterI;
7 import net.sf.flock.FlockResourceException;
8 import net.sf.flock.filter.Limit;
9 import net.sf.flock.filter.MetaStartsWith;
10 import net.sf.flock.filter.SortByDate;
11 import net.sf.flock.webapp.FlockContext;
12 import net.sf.tapestry.ApplicationRuntimeException;
13 import net.sf.tapestry.BaseComponent;
14 import net.sf.tapestry.event.PageDetachListener;
15 import net.sf.tapestry.event.PageEvent;
16 import net.sf.tapestry.form.IPropertySelectionModel;
17 import net.sf.tapestry.form.StringPropertySelectionModel;
18
19 public class ShowAggregate extends BaseComponent implements PageDetachListener {
20
21 private final static Map ITEM_COUNTS = new TreeMap();
22 static {
23 ITEM_COUNTS.put("Show 10", new Integer(10));
24 ITEM_COUNTS.put("Show 20", new Integer(20));
25 ITEM_COUNTS.put("Show 50", new Integer(50));
26 ITEM_COUNTS.put("Show All", new Integer(Integer.MAX_VALUE));
27 }
28 private final static String[] ITEM_COUNT_STR = (String[])ITEM_COUNTS.keySet().toArray(new String[3]);
29
30 private String maxItems = ITEM_COUNT_STR[1];
31
32 private String path = "/";
33
34 private boolean allFolded = true;
35
36 public String getPath() {
37 return path;
38 }
39 public void setPath(String path) {
40 this.path = path;
41 }
42
43
44 public Collection getItems() {
45 try {
46 return FlockContext.getSubscriptionManager().findItems( new FilterI[] {
47 new MetaStartsWith("path", this.path),
48 new SortByDate(),
49 new Limit(this.getMaxItemsInt()),
50 });
51 } catch (FlockResourceException e) {
52 throw new ApplicationRuntimeException(e);
53 }
54 }
55
56 /***
57 * @see net.sf.tapestry.event.PageDetachListener#pageDetached(net.sf.tapestry.event.PageEvent)
58 */
59 public void pageDetached(PageEvent evt) {
60 this.maxItems = ITEM_COUNT_STR[1];
61 this.path = "/";
62 this.allFolded = true;
63 }
64
65 public IPropertySelectionModel getMaxItemsPropertySelection() {
66 return new StringPropertySelectionModel( ITEM_COUNT_STR );
67 }
68
69 public String getMaxItems() {
70 return maxItems;
71 }
72
73 public void setMaxItems(String maxItems) {
74 this.maxItems = maxItems;
75 this.fireObservedChange("maxItems", maxItems);
76 }
77
78 private int getMaxItemsInt() {
79 return ((Integer)ITEM_COUNTS.get(this.maxItems)).intValue();
80 }
81
82 public boolean isAllFolded() {
83 return allFolded;
84 }
85
86 public void setAllFolded(boolean allFolded) {
87 this.allFolded = allFolded;
88 this.fireObservedChange("allFolded", allFolded);
89 }
90
91 }
This page was automatically generated by Maven