001: /*
002: * Copyright 2006-2007 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.layout.impl;
018:
019: import nextapp.echo2.app.Component;
020:
021: import org.romaframework.aspect.view.ViewAspect;
022: import org.romaframework.aspect.view.ViewConstants;
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.layout.InvalidLayoutMode;
031: import org.romaframework.aspect.view.layout.LayoutMode;
032: import org.romaframework.aspect.view.screen.Screen;
033: import org.romaframework.core.config.RomaApplicationContext;
034: import org.romaframework.core.flow.ObjectContext;
035: import org.romaframework.core.schema.SchemaAction;
036: import org.romaframework.core.schema.SchemaField;
037:
038: /**
039: * Layout an element in an area defined in the current form.
040: *
041: * @author Luca Garulli (luca.garulli@assetdata.it)
042: */
043: public class FormLayout implements LayoutMode<Component> {
044:
045: protected ComponentFactory componentFactory;
046: public static final String NAME = ViewConstants.LAYOUT_FORM;
047:
048: public FormLayout() {
049: componentFactory = ObjectContext.getInstance().getComponent(
050: ComponentFactory.class);
051: }
052:
053: public String layoutClass(ContentForm iForm, Component iComponent,
054: String iWhere, Screen iDesktop) throws InvalidLayoutMode {
055: throw new InvalidLayoutMode(NAME);
056: }
057:
058: public String layoutField(SchemaField iField, ContentForm iForm,
059: Component iComponent, String iMode)
060: throws InvalidLayoutMode {
061: try {
062: EntityForm form = (EntityForm) iForm;
063:
064: String labelText = (String) iField.getFeature(
065: ViewAspect.ASPECT_NAME, ViewBaseFeatures.LABEL);
066: if (labelText != null && labelText.length() > 0) {
067: // SET THE LABEL
068: Component label = componentFactory
069: .createLabelComponent(iForm, iField);
070:
071: RomaApplicationContext.getInstance().getBean(
072: LookAndFeelManager.class).assignStyle(
073: label,
074: iForm.getSchemaInstance().getSchemaClass()
075: .getClazz());
076: FormUtil
077: .assignLabel(label, (String) iField.getFeature(
078: ViewAspect.ASPECT_NAME,
079: ViewBaseFeatures.LABEL));
080: FormUtil.assignHint(label, (String) iField.getFeature(
081: ViewAspect.ASPECT_NAME,
082: ViewBaseFeatures.DESCRIPTION));
083:
084: iComponent.setProperty("LABEL", label);
085:
086: form.addComponent(iMode, label);
087: }
088: form.addComponent(iMode, iComponent);
089: return null;
090: } catch (Throwable e) {
091: throw new InvalidLayoutMode(toString(), e);
092: }
093: }
094:
095: public String layoutAction(SchemaAction iAction, ContentForm iForm,
096: Component iComponent, String iMode)
097: throws InvalidLayoutMode {
098: try {
099: ((EntityForm) iForm).addComponent(iMode, iComponent);
100: return null;
101: } catch (Throwable e) {
102: throw new InvalidLayoutMode(toString(), e);
103: }
104: }
105:
106: public ContentComponent getContainerForm(ContentComponent iForm) {
107: return iForm;
108: }
109:
110: public boolean renderOwnerField() {
111: return true;
112: }
113:
114: @Override
115: public String toString() {
116: return NAME;
117: }
118: }
|