001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it) Licensed under the
003: * Apache License, Version 2.0 (the "License"); you may not use this file except
004: * in compliance with the License. You may obtain a copy of the License at
005: * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
006: * or agreed to in writing, software distributed under the License is
007: * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
008: * KIND, either express or implied. See the License for the specific language
009: * governing permissions and limitations under the License.
010: */
011: package org.romaframework.aspect.view.echo2.area;
012:
013: import java.io.Serializable;
014:
015: import nextapp.echo2.app.Component;
016:
017: import org.romaframework.aspect.view.area.AreaMode;
018: import org.romaframework.aspect.view.area.AreaModeManager;
019: import org.romaframework.aspect.view.echo2.component.Titleable;
020: import org.romaframework.core.domain.type.TreeNodeLinkedHashMap;
021: import org.romaframework.core.flow.ObjectContext;
022: import org.romaframework.xml.config.XmlConfigAreaType;
023:
024: import tucana.echo2.app.widgetdash.DefaultWidgetContainer;
025:
026: /**
027: * Handle an Area node of the desktop tree.
028: *
029: * @author Luca Garulli (luca.garulli@assetdata.it)
030: */
031: public class AreaInstance extends TreeNodeLinkedHashMap implements
032: AreaRendering, Serializable {
033:
034: private static final String DEF_CHILDREN_CONTAINER_AREA = "column";
035:
036: protected transient Component component;
037: protected AreaMode areaMode;
038: protected String value;
039: protected Integer areaSize;
040:
041: /**
042: * Auto setup from AreaDefinition object. Initialization is recursive and build a full area tree instances respecting the
043: * AreaDefinition tree.
044: *
045: * @param iParentAreaInstance
046: * Echo2 AreaInstance parent object
047: * @param iParentAreaRendering
048: * Echo2 AreaRendering: AreaInstance or ConfigurableDesktop
049: * @param iParentComponent
050: * TODO
051: * @param iAreaDef
052: * AreaDefinition object containing area definition
053: */
054: public AreaInstance(AreaInstance iParentAreaInstance,
055: AreaRendering iParentAreaRendering,
056: Component iParentComponent, XmlConfigAreaType iAreaTag) {
057: this (iParentAreaInstance, iParentAreaRendering, iAreaTag
058: .getName(), iAreaTag.getType(), iAreaTag.getSize());
059:
060: if (!areaMode.isChildrenAllowed()
061: && iAreaTag.getAreaArray().length > 0) {
062: // FORCE DEFAULT AREA TO CONTAIN CHILDREN
063: areaMode = ObjectContext.getInstance().getComponent(
064: AreaModeManager.class).getComponent(
065: DEF_CHILDREN_CONTAINER_AREA);
066: }
067:
068: // BROWSE RECURSIVELY ALL CHILDREN
069: for (XmlConfigAreaType areaDef : iAreaTag.getAreaArray()) {
070: // value = filterNodeContent(areaDef.xmlText());
071: AreaInstance subArea = new AreaInstance(this , this ,
072: component, areaDef);
073:
074: if (areaDef.getName() != null)
075: addChild(areaDef.getName(), subArea);
076: }
077: }
078:
079: /**
080: * Construct a new AreaInstance component.
081: *
082: * @param iParentAreaInstance
083: * Echo2 AreaInstance parent object
084: * @param iParentAreaRendering
085: * Echo2 AreaRendering: AreaInstance or ConfigurableDesktop
086: * @param iAreaName
087: * @param iAreaType
088: * @param iAreaSize
089: */
090: public AreaInstance(AreaInstance iParentAreaInstance,
091: AreaRendering iParentAreaRendering, String iAreaName,
092: String iAreaType, int iAreaSize) {
093: super (iParentAreaInstance, iAreaName);
094: areaSize = iAreaSize;
095: areaMode = ObjectContext.getInstance().getComponent(
096: AreaModeManager.class).getComponent(iAreaType);
097:
098: // CREATE THE ECHO2 COMPONENT AND ADD TO THE PARENT'S COMPONENT
099: component = (Component) areaMode.createComponent(iAreaSize);
100:
101: if (iParentAreaRendering != null)
102: iParentAreaRendering.addComponent(component);
103: }
104:
105: private String filterNodeContent(String iNodeValue) {
106: if (iNodeValue == null || iNodeValue.length() == 0)
107: return null;
108: int beginIndex = iNodeValue.indexOf(">");
109: if (beginIndex > -1) {
110: int endIndex = iNodeValue.indexOf("<", beginIndex + 1);
111: if (endIndex > -1)
112: return iNodeValue.substring(beginIndex + 1, endIndex)
113: .trim();
114: }
115: return null;
116: }
117:
118: public AreaMode getAreaMode() {
119: return areaMode;
120: }
121:
122: public Component getComponent() {
123: return component;
124: }
125:
126: public void placeComponent(Component iComponentToPlace) {
127: if (component.getParent() != null
128: && component.getParent().getParent() != null
129: && component.getParent().getParent().getParent() != null) {
130: Component comp = component.getParent().getParent()
131: .getParent();
132: if (comp instanceof Titleable
133: && iComponentToPlace instanceof Titleable) {
134: // TRANSFER TITLE UPPER LEVEL
135: ((Titleable) comp)
136: .setTitle(((Titleable) iComponentToPlace)
137: .getTitle());
138: ((Titleable) iComponentToPlace).setTitle("");
139: }
140: if (comp instanceof DefaultWidgetContainer) {
141: if (!(((DefaultWidgetContainer) comp).isVisible())) {
142: }
143: }
144: component = (Component) areaMode.placeComponent(component,
145: iComponentToPlace);
146: }
147: }
148:
149: public void addComponent(Component iComponentToPlace) {
150: component = (Component) areaMode.createComponentContainer(
151: component, iComponentToPlace);
152: }
153:
154: public String getValue() {
155: return value;
156: }
157:
158: public Integer getAreaSize() {
159: return areaSize;
160: }
161:
162: public AreaInstance getRootArea() {
163: return this;
164: }
165: }
|