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.layout.impl;
018:
019: import nextapp.echo2.app.Column;
020: import nextapp.echo2.app.Component;
021:
022: import org.romaframework.aspect.view.ViewAspect;
023: import org.romaframework.aspect.view.ViewConstants;
024: import org.romaframework.aspect.view.echo2.component.ComponentFactory;
025: import org.romaframework.aspect.view.echo2.form.EntityForm;
026: import org.romaframework.aspect.view.echo2.form.FormUtil;
027: import org.romaframework.aspect.view.echo2.look.LookAndFeelManager;
028: import org.romaframework.aspect.view.feature.ViewBaseFeatures;
029: import org.romaframework.aspect.view.form.ContentComponent;
030: import org.romaframework.aspect.view.form.ContentForm;
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.flow.ObjectContext;
036: import org.romaframework.core.schema.SchemaAction;
037: import org.romaframework.core.schema.SchemaField;
038:
039: /**
040: * layout a field in a separate block.
041: *
042: * @author Luca Garulli (luca.garulli@assetdata.it)
043: */
044: public class BlockLayout implements LayoutMode<Component> {
045:
046: public BlockLayout() {
047: componentFactory = ObjectContext.getInstance().getComponent(
048: ComponentFactory.class);
049: }
050:
051: public String layoutClass(ContentForm iForm, Component iComponent,
052: String iWhere, Screen iDesktop) throws InvalidLayoutMode {
053: throw new InvalidLayoutMode(NAME);
054: }
055:
056: public String layoutField(SchemaField iField, ContentForm iForm,
057: Component iComponent, String iMode)
058: throws InvalidLayoutMode {
059: try {
060: EntityForm form = (EntityForm) iForm;
061:
062: String labelValue = (String) iField.getFeature(
063: ViewAspect.ASPECT_NAME, ViewBaseFeatures.LABEL);
064:
065: if (labelValue != null && labelValue.length() > 0) {
066: // INSERT A COLUMN WITH LABEL + COMPONENT
067: Column col = new Column();
068:
069: ObjectContext.getInstance().getComponent(
070: LookAndFeelManager.class).assignStyle(
071: col,
072: iForm.getSchemaInstance().getSchemaClass()
073: .getClazz(),
074: (String) iField.getFeature(
075: ViewAspect.ASPECT_NAME,
076: ViewBaseFeatures.STYLE));
077:
078: // SET THE LABEL
079: Component label = componentFactory
080: .createLabelComponent(iForm, iField);
081:
082: RomaApplicationContext.getInstance().getBean(
083: LookAndFeelManager.class).assignStyle(
084: label,
085: iForm.getSchemaInstance().getSchemaClass()
086: .getClazz());
087: FormUtil.assignLabel(label, labelValue);
088: FormUtil.assignHint(label, (String) iField.getFeature(
089: ViewAspect.ASPECT_NAME,
090: ViewBaseFeatures.DESCRIPTION));
091:
092: col.add(label);
093: col.add(iComponent);
094:
095: form.addComponent(iMode, col);
096: } else
097: // INSERT ONLY THE COMPONENT
098: form.addComponent(iMode, iComponent);
099:
100: return null;
101: } catch (Throwable e) {
102: throw new InvalidLayoutMode(toString(), e);
103: }
104: }
105:
106: public String layoutAction(SchemaAction iAction, ContentForm iForm,
107: Component iComponent, String iMode)
108: throws InvalidLayoutMode {
109: try {
110: ((EntityForm) iForm).addComponent(iMode, iComponent);
111: return null;
112: } catch (Throwable e) {
113: throw new InvalidLayoutMode(toString(), e);
114: }
115: }
116:
117: public ContentComponent getContainerForm(ContentComponent iForm) {
118: return iForm;
119: }
120:
121: public boolean renderOwnerField() {
122: return true;
123: }
124:
125: @Override
126: public String toString() {
127: return NAME;
128: }
129:
130: protected ComponentFactory componentFactory;
131: public static final String NAME = ViewConstants.LAYOUT_BLOCK;
132: }
|