View Javadoc
1 package net.sf.flock.webapp.components;
2
3 import java.net.URL;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import net.sf.tapestry.ApplicationRuntimeException;
8 import net.sf.tapestry.BaseComponent;
9 import net.sf.tapestry.ComponentAddress;
10 import net.sf.tapestry.IRender;
11 import net.sf.tapestry.IRequestCycle;
12 import net.sf.tapestry.RequestCycleException;
13 import net.sf.tapestry.components.Block;
14 import net.sf.tapestry.components.BlockRenderer;
15 import net.sf.tapestry.contrib.table.model.ITableColumn;
16 import net.sf.tapestry.contrib.table.model.ITableColumnModel;
17 import net.sf.tapestry.contrib.table.model.ITableDataModel;
18 import net.sf.tapestry.contrib.table.model.ITableModel;
19 import net.sf.tapestry.contrib.table.model.ITableModelSource;
20 import net.sf.tapestry.contrib.table.model.ITableSessionStateManager;
21 import net.sf.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
22 import net.sf.tapestry.contrib.table.model.simple.SimpleListTableDataModel;
23 import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn;
24 import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumnModel;
25 import net.sf.tapestry.contrib.table.model.simple.SimpleTableSessionStateManager;
26 import net.sf.tapestry.contrib.table.model.simple.SimpleTableState;
27 import net.sf.tapestry.event.PageDetachListener;
28 import net.sf.tapestry.event.PageEvent;
29 import net.sf.flock.SubscriptionInfoI;
30 import net.sf.flock.FlockResourceException;
31 import net.sf.flock.webapp.FlockContext;
32 import org.apache.log4j.LogManager;
33 import org.apache.log4j.Logger;
34
35 public class SubscriptionsTable extends BaseComponent implements PageDetachListener {
36
37 private final static Logger LOGGER = LogManager.getLogger(SubscriptionsTable.class);
38
39 private SubscriptionInfoI currentSubscription;
40
41 private ITableSessionStateManager tableStateSessionManager;
42
43 public SubscriptionInfoI getCurrentSubscription() {
44 return currentSubscription;
45 }
46
47 public void setCurrentSubscription(SubscriptionInfoI currentSubscription) {
48 this.currentSubscription = currentSubscription;
49 }
50
51 /***
52 * @see net.sf.tapestry.AbstractComponent#finishLoad()
53 */
54 protected void finishLoad() {
55 super.finishLoad();
56 this.getPage().addPageDetachListener(this);
57 }
58
59
60 /***
61 * @see net.sf.tapestry.event.PageDetachListener#pageDetached(net.sf.tapestry.event.PageEvent)
62 */
63 public void pageDetached(PageEvent evt) {
64 this.tableStateSessionManager = null;
65 }
66
67 private void initTableSessionStateManager() {
68 LOGGER.debug("initTableSessionStateManager");
69 ITableDataModel tableDataModel = this.createTableDataModel();
70 ITableColumnModel tableColumnModel = this.createTableColumnModel();
71 this.tableStateSessionManager = new SimpleTableSessionStateManager(tableDataModel, tableColumnModel);
72 }
73
74 private ITableColumnModel createTableColumnModel() {
75 final ComponentAddress componentAddress = new ComponentAddress(this);
76 return new SimpleTableColumnModel(
77 new ITableColumn[] {
78 new BlockColumn(componentAddress, "Location", "blockLocation"),
79 new BlockColumn(componentAddress, "Title", "blockTitle"),
80 new ExpressionTableColumn("Category", "metaData.get(\"path\")", true),
81 new BlockColumn(componentAddress, "Action", "blockAction")
82 }
83 );
84 }
85
86 private ITableDataModel createTableDataModel() {
87 try {
88 List feedList = new ArrayList(FlockContext.getSubscriptionManager().getSubscriptionInfos());
89 return new SimpleListTableDataModel(feedList);
90 } catch (FlockResourceException e) {
91 throw new ApplicationRuntimeException(e);
92 }
93 }
94
95 public ITableModel getTableModel() {
96 if (this.tableStateSessionManager==null) {
97 this.initTableSessionStateManager();
98 }
99 return this.tableStateSessionManager.recreateTableModel( new SimpleTableState() );
100 }
101
102 public ITableSessionStateManager getTableSessionStateManager() {
103 LOGGER.debug("getTableSessionStateManager");
104 if (this.tableStateSessionManager==null) {
105 this.initTableSessionStateManager();
106 }
107 return this.tableStateSessionManager;
108 }
109
110
111 public void deleteFeed(IRequestCycle cycle) throws RequestCycleException {
112 URL location = (URL)cycle.getServiceParameters()[0];
113 LOGGER.info("Unsubscribe feed "+location);
114 try {
115 FlockContext.getSubscriptionManager().unsubscribe(location);
116 } catch (FlockResourceException e) {
117 throw new ApplicationRuntimeException(e);
118 }
119 }
120
121 public void refreshFeed(IRequestCycle cycle) throws RequestCycleException {
122 URL location = (URL)cycle.getServiceParameters()[0];
123 LOGGER.info("Refresh feed "+location);
124 try {
125 FlockContext.getSubscriptionManager().refresh(location);
126 } catch (FlockResourceException e) {
127 throw new ApplicationRuntimeException(e);
128 }
129 }
130
131 private static class BlockColumn extends SimpleTableColumn {
132 private String blockName;
133 private ComponentAddress componentAddress;
134
135 public BlockColumn(ComponentAddress componentAddress, String title, String blockName) {
136 super(title, true);
137 this.blockName = blockName;
138 this.componentAddress = componentAddress;
139 }
140
141 public IRender getValueRenderer(IRequestCycle cycle, ITableModelSource source, Object row) {
142 SubscriptionsTable comp = (SubscriptionsTable) componentAddress.findComponent(cycle);
143 comp.setCurrentSubscription((SubscriptionInfoI)row);
144 Block block = (Block) comp.getComponent(this.blockName);
145 return new BlockRenderer(block);
146 }
147
148 }
149
150 }
This page was automatically generated by Maven