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.screen;
017:
018: import java.io.Serializable;
019:
020: import nextapp.echo2.app.Component;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.romaframework.aspect.view.echo2.area.AreaInstance;
025: import org.romaframework.aspect.view.echo2.area.AreaRendering;
026: import org.romaframework.xml.config.XmlConfigAreaType;
027:
028: /**
029: * Dynamic desktop defined by XML configuration descriptor.
030: *
031: * @author Luca Garulli (luca.garulli@assetdata.it)
032: */
033: public class ConfigurableScreen extends Echo2Screen implements
034: AreaRendering, Serializable {
035:
036: protected AreaInstance root;
037: private static Log log = LogFactory
038: .getLog(ConfigurableScreen.class);
039:
040: public AreaInstance getRootArea() {
041: return root;
042: }
043:
044: @Override
045: public String view(String iArea, Component iComponent) {
046: if (iArea == null)
047: // USE LAST AREA POSITION
048: iArea = lastArea;
049:
050: if (iArea != null && !iArea.equals(lastArea)
051: && iComponent != null)
052: // UPDATE LAST AREA
053: lastArea = iArea;
054:
055: if (iArea.equals(NULL)) {
056: // DO NOTHING
057: } else if (iArea.startsWith(POPUP)) {
058: displayPopUp(iArea, iComponent);
059: } else {
060: AreaInstance area = (AreaInstance) root.searchNode(iArea);
061: if (area == null) {
062: log.warn("[ConfigurableDesktop.view] area " + iArea
063: + " not found in current desktop");
064: return null;
065: }
066: area.placeComponent(iComponent);
067: }
068: return iArea;
069: }
070:
071: public void configure(XmlConfigAreaType iConfiguration) {
072: root = new AreaInstance(null, this , this , iConfiguration);
073: }
074:
075: public void addComponent(Component iComponentToPlace) {
076: add(iComponentToPlace);
077: }
078:
079: @Override
080: public Object getComponentInArea(String area) {
081: Object component = super .getComponentInArea(area);
082: if (component != null)
083: return component;
084: AreaInstance rootArea = (AreaInstance) root.searchNode(area);
085: if (rootArea == null)
086: return null;
087: return rootArea.getComponent();
088: }
089:
090: public void setRootArea(AreaInstance root) {
091: this .root = root;
092: }
093:
094: public void setVisibleArea(String iArea, boolean iValue) {
095: if (iArea == null)
096: // USE LAST AREA POSITION
097: iArea = lastArea;
098: if (iArea != null && !iArea.equals(lastArea))
099: // UPDATE LAST AREA
100: lastArea = iArea;
101: if (iArea.equals(NULL)) {
102: // DO NOTHING
103: } else if (iArea.startsWith(POPUP)) {
104: return;
105: } else {
106: AreaInstance area = (AreaInstance) root.searchNode(iArea);
107: if (area == null) {
108: log.warn("[ConfigurableDesktop.view] area " + iArea
109: + " not found in current desktop");
110: return;
111: }
112: area.getComponent().setVisible(iValue);
113: }
114: }
115: }
|