001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.aspect.view.echo2;
018:
019: import java.io.InputStream;
020:
021: import nextapp.echo2.app.ApplicationInstance;
022: import nextapp.echo2.app.Component;
023: import nextapp.echo2.app.Label;
024: import nextapp.echo2.app.filetransfer.Download;
025: import nextapp.echo2.app.filetransfer.DownloadProvider;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.romaframework.aspect.session.SessionInfo;
030: import org.romaframework.aspect.view.ViewAspectAbstract;
031: import org.romaframework.aspect.view.area.AreaModeManager;
032: import org.romaframework.aspect.view.echo2.area.impl.CellAreaMode;
033: import org.romaframework.aspect.view.echo2.area.impl.ColumnAreaMode;
034: import org.romaframework.aspect.view.echo2.area.impl.DashboardAreaMode;
035: import org.romaframework.aspect.view.echo2.area.impl.GridAreaMode;
036: import org.romaframework.aspect.view.echo2.area.impl.PlaceholderAreaMode;
037: import org.romaframework.aspect.view.echo2.area.impl.RowAreaMode;
038: import org.romaframework.aspect.view.echo2.component.Titleable;
039: import org.romaframework.aspect.view.echo2.form.ConfigurableEntityForm;
040: import org.romaframework.aspect.view.echo2.form.EntityForm;
041: import org.romaframework.aspect.view.echo2.form.FormUtil;
042: import org.romaframework.aspect.view.echo2.layout.impl.AccordionLayout;
043: import org.romaframework.aspect.view.echo2.layout.impl.BlockLayout;
044: import org.romaframework.aspect.view.echo2.layout.impl.DefaultLayout;
045: import org.romaframework.aspect.view.echo2.layout.impl.ExpandLayout;
046: import org.romaframework.aspect.view.echo2.layout.impl.FormLayout;
047: import org.romaframework.aspect.view.echo2.layout.impl.MenuLayout;
048: import org.romaframework.aspect.view.echo2.layout.impl.ScreenLayout;
049: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
050: import org.romaframework.aspect.view.echo2.push.DisplayFormPushTask;
051: import org.romaframework.aspect.view.echo2.push.RefreshFormPushTask;
052: import org.romaframework.aspect.view.echo2.rendering.impl.AccordionRendering;
053: import org.romaframework.aspect.view.echo2.rendering.impl.ButtonRendering;
054: import org.romaframework.aspect.view.echo2.rendering.impl.CheckRendering;
055: import org.romaframework.aspect.view.echo2.rendering.impl.ColumnSetRendering;
056: import org.romaframework.aspect.view.echo2.rendering.impl.DateRendering;
057: import org.romaframework.aspect.view.echo2.rendering.impl.DateTimeRendering;
058: import org.romaframework.aspect.view.echo2.rendering.impl.DefaultRendering;
059: import org.romaframework.aspect.view.echo2.rendering.impl.HtmlRendering;
060: import org.romaframework.aspect.view.echo2.rendering.impl.ImageButtonRendering;
061: import org.romaframework.aspect.view.echo2.rendering.impl.ImageRendering;
062: import org.romaframework.aspect.view.echo2.rendering.impl.LabelRendering;
063: import org.romaframework.aspect.view.echo2.rendering.impl.LinkRendering;
064: import org.romaframework.aspect.view.echo2.rendering.impl.ListRendering;
065: import org.romaframework.aspect.view.echo2.rendering.impl.MenuRendering;
066: import org.romaframework.aspect.view.echo2.rendering.impl.ObjectEmbeddedRendering;
067: import org.romaframework.aspect.view.echo2.rendering.impl.ObjectLinkRendering;
068: import org.romaframework.aspect.view.echo2.rendering.impl.PasswordRendering;
069: import org.romaframework.aspect.view.echo2.rendering.impl.PopUpRendering;
070: import org.romaframework.aspect.view.echo2.rendering.impl.RadioRendering;
071: import org.romaframework.aspect.view.echo2.rendering.impl.RichTextRendering;
072: import org.romaframework.aspect.view.echo2.rendering.impl.RowSetRendering;
073: import org.romaframework.aspect.view.echo2.rendering.impl.SelectRendering;
074: import org.romaframework.aspect.view.echo2.rendering.impl.TabRendering;
075: import org.romaframework.aspect.view.echo2.rendering.impl.TableEditRendering;
076: import org.romaframework.aspect.view.echo2.rendering.impl.TableRendering;
077: import org.romaframework.aspect.view.echo2.rendering.impl.TextAreaRendering;
078: import org.romaframework.aspect.view.echo2.rendering.impl.TextRendering;
079: import org.romaframework.aspect.view.echo2.rendering.impl.TimeRendering;
080: import org.romaframework.aspect.view.echo2.rendering.impl.TreeRendering;
081: import org.romaframework.aspect.view.echo2.rendering.impl.UploadRendering;
082: import org.romaframework.aspect.view.feature.ViewBaseFeatures;
083: import org.romaframework.aspect.view.feature.ViewElementFeatures;
084: import org.romaframework.aspect.view.form.ContentComponent;
085: import org.romaframework.aspect.view.form.ContentForm;
086: import org.romaframework.aspect.view.layout.LayoutModeManager;
087: import org.romaframework.aspect.view.rendering.RenderingModeManager;
088: import org.romaframework.aspect.view.screen.Screen;
089: import org.romaframework.core.config.RomaApplicationContext;
090: import org.romaframework.core.flow.Controller;
091: import org.romaframework.core.flow.ObjectContext;
092: import org.romaframework.core.flow.UserObjectEventListener;
093: import org.romaframework.core.schema.SchemaClassResolver;
094: import org.romaframework.core.schema.SchemaElement;
095: import org.romaframework.core.schema.SchemaFeaturesChangeListener;
096: import org.romaframework.core.schema.SchemaField;
097: import org.romaframework.core.schema.SchemaHelper;
098: import org.romaframework.core.schema.SchemaObject;
099:
100: public class Echo2ViewAspect extends ViewAspectAbstract implements
101: UserObjectEventListener, SchemaFeaturesChangeListener {
102:
103: private static Log log = LogFactory.getLog(Echo2ViewAspect.class);
104:
105: @Override
106: public void startup() {
107: super .startup();
108:
109: // REGISTER THE ECHO2 DOMAIN PACKAGE
110: ObjectContext.getInstance().getComponent(
111: SchemaClassResolver.class).addDomainPackage(
112: Echo2ViewAspect.class.getPackage().getName());
113:
114: ObjectContext.getInstance().getComponent(
115: LookAndFeelManager.class).init();
116:
117: try {
118: // REGISTER ALL RENDERING MODES
119: RenderingModeManager renderMgr = RomaApplicationContext
120: .getInstance().getBean(RenderingModeManager.class);
121:
122: renderMgr.addComponent(DefaultRendering.class);
123: renderMgr.addComponent(PasswordRendering.class);
124: renderMgr.addComponent(TextRendering.class);
125: renderMgr.addComponent(LabelRendering.class);
126: renderMgr.addComponent(TextAreaRendering.class);
127: renderMgr.addComponent(HtmlRendering.class);
128: renderMgr.addComponent(RichTextRendering.class);
129: renderMgr.addComponent(DateTimeRendering.class);
130: renderMgr.addComponent(DateRendering.class);
131: renderMgr.addComponent(TimeRendering.class);
132: renderMgr.addComponent(ObjectEmbeddedRendering.class);
133: renderMgr.addComponent(ObjectLinkRendering.class);
134: renderMgr.addComponent(PopUpRendering.class);
135: renderMgr.addComponent(SelectRendering.class);
136: renderMgr.addComponent(CheckRendering.class);
137: renderMgr.addComponent(RadioRendering.class);
138: renderMgr.addComponent(ListRendering.class);
139: renderMgr.addComponent(TableRendering.class);
140: renderMgr.addComponent(TableEditRendering.class);
141: renderMgr.addComponent(RowSetRendering.class);
142: renderMgr.addComponent(ColumnSetRendering.class);
143: renderMgr.addComponent(ButtonRendering.class);
144: renderMgr.addComponent(LinkRendering.class);
145: renderMgr.addComponent(UploadRendering.class);
146: renderMgr.addComponent(MenuRendering.class);
147: renderMgr.addComponent(ImageRendering.class);
148: renderMgr.addComponent(ImageButtonRendering.class);
149: renderMgr.addComponent(AccordionRendering.class);
150: renderMgr.addComponent(TabRendering.class);
151: renderMgr.addComponent(TreeRendering.class);
152:
153: // REGISTER ALL LAYOUT MODES
154: LayoutModeManager layoutMgr = RomaApplicationContext
155: .getInstance().getBean(LayoutModeManager.class);
156:
157: layoutMgr.addComponent(DefaultLayout.class);
158: layoutMgr.addComponent(FormLayout.class);
159: layoutMgr.addComponent(BlockLayout.class);
160: layoutMgr.addComponent(ExpandLayout.class);
161: layoutMgr.addComponent(MenuLayout.class);
162: layoutMgr.addComponent(ScreenLayout.class);
163: layoutMgr.addComponent(AccordionLayout.class);
164:
165: // REGISTER ALL AREA MODES
166: AreaModeManager areaMgr = RomaApplicationContext
167: .getInstance().getBean(AreaModeManager.class);
168:
169: areaMgr.addComponent(PlaceholderAreaMode.class);
170: areaMgr.addComponent(CellAreaMode.class);
171: areaMgr.addComponent(ColumnAreaMode.class);
172: areaMgr.addComponent(RowAreaMode.class);
173: areaMgr.addComponent(GridAreaMode.class);
174: areaMgr.addComponent(DashboardAreaMode.class);
175:
176: // REGISTER MYSELF AS EVENT LISTENER FOR ANY USER OBJECT CHANGES
177: Controller.getInstance().registerListener(
178: UserObjectEventListener.class, this );
179:
180: // REGISTER MYSELF AS EVENT LISTENER FROM ANY FEATURE CHANGES
181: Controller.getInstance().registerListener(
182: SchemaFeaturesChangeListener.class, this );
183: } catch (Exception e) {
184: log.error("[Echo2ViewAspect.aspectStartup]", e);
185: }
186: }
187:
188: /**
189: * Create the form reading the entity's render feature.
190: */
191: public ContentForm createForm(SchemaObject iSchema,
192: ContentComponent iParent) {
193: return new ConfigurableEntityForm(iParent);
194: }
195:
196: public String showForm(ContentForm iForm, String iWhere,
197: Screen iDesktop) {
198: return FormUtil.layoutForm((EntityForm) iForm,
199: (EntityForm) iForm, iWhere, iDesktop);
200: }
201:
202: public void pushShowForm(SessionInfo iSession, ContentForm iForm,
203: String iWhere) {
204: new DisplayFormPushTask(iSession, iForm, iWhere);
205: }
206:
207: public void pushRefreshForm(SessionInfo iSession,
208: ContentComponent iForm) {
209: new RefreshFormPushTask(iSession, iForm);
210: }
211:
212: public boolean onBeforeActionExecution(Object iContent,
213: SchemaElement iAction) {
214: return true;
215: }
216:
217: public void onAfterActionExecution(Object iContent,
218: SchemaElement iAction) {
219: }
220:
221: public void onFieldRefresh(SessionInfo iSession, Object iContent,
222: SchemaField iField) {
223: EntityForm form = (EntityForm) ObjectContext.getInstance()
224: .getFormByObject(iSession, iContent);
225:
226: if (form == null)
227: // FORM NOT YET CREATED: JUST RETURN
228: return;
229:
230: Component componentToUpdate = form.searchFieldComponent(iField
231: .getName());
232:
233: Object value = SchemaHelper.getFieldValue(form
234: .getSchemaInstance(), iField.getName(), iContent);
235:
236: FormUtil.setComponentValue(componentToUpdate, value);
237: }
238:
239: public Object onBeforeFieldRead(Object iContent,
240: SchemaField iField, Object iCurrentValue) {
241: return iCurrentValue;
242: }
243:
244: public void pushDownload(InputStream in, String iFileName,
245: String iContentType) {
246: DownloadProvider provider = new InputStreamDownloadProvider(in,
247: iContentType, iFileName);
248:
249: Download cmd = new Download();
250: cmd.setActive(true);
251: cmd.setProvider(provider);
252:
253: ApplicationInstance.getActive().enqueueCommand(cmd);
254: }
255:
256: public void signalChangeField(Object iUserObject,
257: String iAspectName, String iFieldName, String iFeatureName,
258: Object iOldValue, Object iFeatureValue) {
259: ContentComponent comp = ObjectContext.getInstance()
260: .getFormByObject(iUserObject);
261: if (!(comp instanceof EntityForm))
262: return;
263:
264: EntityForm form = (EntityForm) comp;
265: if (form != null) {
266: Component component = form.searchFieldComponent(iFieldName);
267: if (component == null)
268: return;
269:
270: if (iFeatureName.equals(ViewBaseFeatures.LABEL)) {
271: if (component instanceof Label)
272: ((Label) component).setText(iFeatureValue
273: .toString());
274: } else if (iFeatureName.equals(ViewElementFeatures.ENABLED))
275: component.setEnabled((Boolean) iFeatureValue);
276: else if (iFeatureName.equals(ViewElementFeatures.VISIBLE)) {
277: component.setVisible((Boolean) iFeatureValue);
278: Component label = (Component) component
279: .getProperty(DefaultLayout.PROPERTY_LABEL);
280: if (label != null)
281: label.setVisible((Boolean) iFeatureValue);
282: }
283: }
284: }
285:
286: public void signalChangeAction(Object iUserObject,
287: String iAspectName, String iActionName,
288: String iFeatureName, Object iOldValue, Object iFeatureValue) {
289: EntityForm form = (EntityForm) ObjectContext.getInstance()
290: .getFormByObject(iUserObject);
291: if (form != null) {
292: Component component = form.getActionComponent(iActionName);
293: if (component == null)
294: return;
295:
296: if (iFeatureName.equals(ViewBaseFeatures.LABEL)) {
297: if (component instanceof Label)
298: ((Label) component).setText(iFeatureValue
299: .toString());
300: } else if (iFeatureName.equals(ViewElementFeatures.ENABLED))
301: component.setEnabled((Boolean) iFeatureValue);
302: else if (iFeatureName.equals(ViewElementFeatures.VISIBLE))
303: component.setVisible((Boolean) iFeatureValue);
304: }
305: }
306:
307: public void signalChangeClass(Object iUserObject,
308: String iAspectName, String iFeatureName, Object iOldValue,
309: Object iFeatureValue) {
310: EntityForm form = (EntityForm) ObjectContext.getInstance()
311: .getFormByObject(iUserObject);
312: if (form != null) {
313: if (iFeatureName.equals(ViewBaseFeatures.LABEL)) {
314: if (form instanceof Titleable) {
315: if (iFeatureValue == null)
316: iFeatureValue = "";
317: ((Titleable) form).setTitle(iFeatureValue
318: .toString());
319: }
320: }
321: }
322: }
323:
324: public Object onBeforeFieldWrite(Object content, SchemaField field,
325: Object currentValue) {
326: return currentValue;
327: }
328:
329: public Object onAfterFieldWrite(Object content, SchemaField field,
330: Object currentValue) {
331: return currentValue;
332: }
333:
334: public Object onAfterFieldRead(Object content, SchemaField field,
335: Object currentValue) {
336: return currentValue;
337: }
338: }
|