1
2
3
4
5
6
7
8
9
10 package com.sri.emo.controller;
11
12 import com.jcorporate.expresso.core.controller.*;
13 import com.jcorporate.expresso.core.db.DBException;
14 import com.sri.common.controller.AbstractDBController;
15 import com.sri.common.controller.IFooterStateHandler;
16 import com.sri.common.controller.IHeaderStateHandler;
17 import com.sri.emo.dbobj.INodeHandler;
18 import com.sri.emo.dbobj.NodeType;
19 import com.sri.emo.dbobj.PartsFactory;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.TreeSet;
24
25
26 /***
27 * Common methods (header, footer) which are typically called via a strategy pattern.
28 *
29 * @author Larry Hamel
30 */
31 public class EmoAction extends AbstractDBController
32 implements IFooterStateHandler, IHeaderStateHandler {
33
34 /***
35 *
36 */
37 private static final long serialVersionUID = 1L;
38
39 public EmoAction() {
40 }
41
42 /***
43 * Return the title of this Controller
44 *
45 * @return java.lang.String The Title of the controller
46 */
47 public String getTitle() {
48 return "EmoAction Controller";
49 }
50
51 /***
52 * footer will be executed here.
53 */
54 public void runFooterState(ControllerRequest request,
55 ControllerResponse response) throws ControllerException {
56 try {
57 addFooter(request, response);
58 } catch (DBException e) {
59 throw new ControllerException(e);
60 }
61 }
62
63 /***
64 * // footer contains links to real and 'fake' entities
65 */
66 protected void addFooter(ControllerRequest request, ControllerResponse response) throws ControllerException,
67 DBException {
68
69
70 if (isEmbeddedMode(request)) {
71 return;
72 }
73
74 TreeSet real = PartsFactory.getEntities();
75 ArrayList fake = PartsFactory.getFakeEntities();
76 real.addAll(fake);
77
78 Transition trans = null;
79
80 if (real.size() > 0) {
81 Block footerblock = new Block(FOOTER);
82 response.add(footerblock);
83
84 for (Iterator iterator = real.iterator(); iterator.hasNext();) {
85 NodeType type = (NodeType) iterator.next();
86
87 Block row = new Block(ROW_BLOCK);
88 footerblock.add(row);
89
90 if (type.hasCustomHandler()) {
91 INodeHandler handler = type.getCustomHandler();
92 trans = handler.getListTransition(request);
93 } else {
94 trans = NodeAction.getListTransition(type.getEntityName());
95 }
96
97 row.add(trans);
98
99 row.add(new Output(NodeType.DISPLAY_TITLE, type.getDisplayName()));
100 }
101 }
102 }
103
104 protected void addHeader(final ControllerRequest request, final ControllerResponse response) throws DBException,
105 ControllerException {
106
107
108 if (isEmbeddedMode(request)) {
109 return;
110 }
111
112
113 response.add(new Transition("", PartAction.class, PartAction.LIST_ENTITIES));
114 }
115
116 /***
117 * a special state call will execute this state
118 */
119 public void runHeaderState(ControllerRequest request,
120 ControllerResponse response) throws ControllerException {
121 try {
122 addHeader(request, response);
123 } catch (DBException e) {
124 throw new ControllerException(e);
125 }
126 }
127 }