001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * 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, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.romaframework.aspect.view.echo2.layout.impl;
017:
018: import nextapp.echo2.app.Component;
019:
020: import org.romaframework.aspect.view.ViewAspect;
021: import org.romaframework.aspect.view.ViewConstants;
022: import org.romaframework.aspect.view.echo2.area.AreaRendering;
023: import org.romaframework.aspect.view.echo2.component.ComponentFactory;
024: import org.romaframework.aspect.view.echo2.form.EntityForm;
025: import org.romaframework.aspect.view.echo2.form.FormUtil;
026: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
027: import org.romaframework.aspect.view.feature.ViewBaseFeatures;
028: import org.romaframework.aspect.view.form.ContentComponent;
029: import org.romaframework.aspect.view.form.ContentForm;
030: import org.romaframework.aspect.view.form.FormViewer;
031: import org.romaframework.aspect.view.layout.InvalidLayoutMode;
032: import org.romaframework.aspect.view.layout.LayoutMode;
033: import org.romaframework.aspect.view.screen.Screen;
034: import org.romaframework.core.config.RomaApplicationContext;
035: import org.romaframework.core.domain.type.TreeNodeHelper;
036: import org.romaframework.core.flow.ObjectContext;
037: import org.romaframework.core.schema.SchemaAction;
038: import org.romaframework.core.schema.SchemaField;
039:
040: /**
041: * Layout a field in a default way.
042: *
043: * @author Luca Garulli (luca.garulli@assetdata.it)
044: */
045: public class DefaultLayout implements LayoutMode<Component> {
046:
047: protected ComponentFactory componentFactory;
048: public final static String NAME = ViewConstants.LAYOUT_DEFAULT;
049: public static final String PROPERTY_LABEL = "LABEL";
050:
051: public DefaultLayout() {
052: componentFactory = ObjectContext.getInstance().getComponent(
053: ComponentFactory.class);
054: }
055:
056: public String layoutClass(ContentForm iForm, Component iComponent,
057: String iWhere, Screen iDesktop) throws InvalidLayoutMode {
058: return FormViewer.getInstance().display(iWhere, iComponent,
059: iDesktop);
060: }
061:
062: public String layoutField(SchemaField iField, ContentForm iForm,
063: Component iComponent, String iMode)
064: throws InvalidLayoutMode {
065: try {
066: EntityForm form = (EntityForm) iForm;
067: AreaRendering area = form
068: .getArea(TreeNodeHelper.ANY_POSITION
069: + iField.getName());
070: String areaName = area != null ? TreeNodeHelper.ANY_POSITION
071: + iField.getName()
072: : EntityForm.AREA_FIELDS;
073: String labelText = (String) iField.getFeature(
074: ViewAspect.ASPECT_NAME, ViewBaseFeatures.LABEL);
075: if (labelText != null && labelText.length() > 0) {
076: // SET THE LABEL
077: Component label = componentFactory
078: .createLabelComponent(iForm, iField);
079: RomaApplicationContext.getInstance().getBean(
080: LookAndFeelManager.class).assignStyle(
081: label,
082: iForm.getSchemaInstance().getSchemaClass()
083: .getClazz());
084: FormUtil
085: .assignLabel(label, (String) iField.getFeature(
086: ViewAspect.ASPECT_NAME,
087: ViewBaseFeatures.LABEL));
088: FormUtil.assignHint(label, (String) iField.getFeature(
089: ViewAspect.ASPECT_NAME,
090: ViewBaseFeatures.DESCRIPTION));
091: iComponent.setProperty(PROPERTY_LABEL, label);
092: form.addComponent(areaName, label);
093: }
094: form.addComponent(areaName, iComponent);
095: return null;
096: } catch (Throwable e) {
097: throw new InvalidLayoutMode(toString(), e);
098: }
099: }
100:
101: public String layoutAction(SchemaAction iAction, ContentForm iForm,
102: Component iComponent, String iMode)
103: throws InvalidLayoutMode {
104: EntityForm form = (EntityForm) iForm;
105: AreaRendering area = form.getArea(TreeNodeHelper.ANY_POSITION
106: + iAction.getName());
107: String areaName = area != null ? TreeNodeHelper.ANY_POSITION
108: + iAction.getName() : EntityForm.AREA_ACTIONS;
109:
110: try {
111: ((EntityForm) iForm).addComponent(areaName, iComponent);
112: return null;
113: } catch (Throwable e) {
114: throw new InvalidLayoutMode(toString(), e);
115: }
116: }
117:
118: public ContentComponent getContainerForm(ContentComponent iForm) {
119: return iForm;
120: }
121:
122: public boolean renderOwnerField() {
123: return true;
124: }
125:
126: @Override
127: public String toString() {
128: return NAME;
129: }
130: }
|