001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.wrapping;
019:
020: import net.ar.webonswing.visitor.*;
021: import net.ar.webonswing.walkers.*;
022:
023: public abstract class HierarchyWrapper {
024: protected final String COMPONENT_PROPERTY = "theComponent";
025:
026: protected ComponentWrapper theRootComponent;
027: protected ComponentWrapper theCurrentComponentWrapper;
028:
029: protected abstract ComponentWrapper createComponentWrapper(
030: Object aComponent);
031:
032: protected abstract Object getUnwrappedRootComponent(
033: VisualWindow aWindow);
034:
035: protected abstract VisitableContainer getContainerVisitableOfVisualComponent(
036: VisualComponent aComponent);
037:
038: public abstract boolean isWrapped(Object theComponent);
039:
040: public abstract void setComponentWrapper(Object aComponent,
041: ComponentWrapper aWrapper);
042:
043: public abstract ComponentWrapper getComponentWrapper(
044: Object component);
045:
046: public abstract VisitableContainer getContainerVisitable(
047: Object aComponent);
048:
049: public abstract WindowWrapper wrapWindow(Object aWindow);
050:
051: public VisualWindow createHierarchy(VisualWindow aWindow) {
052: Object aComponent = getUnwrappedRootComponent(aWindow);
053: theCurrentComponentWrapper = null;
054: VisitableContainer theContainerVisitable = getContainerVisitable(aComponent);
055:
056: theContainerVisitable.accept(new ContainerVisitor() {
057: public void visitContainerBegin(Object aVisitedComponent) {
058: ComponentWrapper theComponentWrapper = createComponentWrapper(aVisitedComponent);
059: setComponentWrapper(aVisitedComponent,
060: theComponentWrapper);
061:
062: if (theCurrentComponentWrapper != null)
063: theCurrentComponentWrapper
064: .addChild(theComponentWrapper);
065: else
066: theRootComponent = theComponentWrapper;
067:
068: theCurrentComponentWrapper = theComponentWrapper;
069: }
070:
071: public void visitContainerEnd(Object aVisitedComponent) {
072: theCurrentComponentWrapper = (ComponentWrapper) theCurrentComponentWrapper
073: .getParent();
074: }
075: });
076:
077: aWindow.setRootComponent(theRootComponent);
078:
079: return aWindow;
080: }
081:
082: public ComponentWrapper createChildsHierarchy(
083: VisualComponent aComponent) {
084: theCurrentComponentWrapper = null;
085: VisitableContainer theContainerVisitable = getContainerVisitableOfVisualComponent(aComponent);
086:
087: theContainerVisitable.accept(new ContainerVisitor() {
088: public void visitContainerBegin(Object aVisitedComponent) {
089: ComponentWrapper theComponentWrapper = isWrapped(aVisitedComponent) ? getComponentWrapper(aVisitedComponent)
090: : createComponentWrapper(aVisitedComponent);
091:
092: if (theCurrentComponentWrapper != null) {
093: if (!isWrapped(aVisitedComponent))
094: theCurrentComponentWrapper
095: .addChild(theComponentWrapper);
096: } else
097: theRootComponent = theComponentWrapper;
098:
099: setComponentWrapper(aVisitedComponent,
100: theComponentWrapper);
101: theCurrentComponentWrapper = theComponentWrapper;
102: }
103:
104: public void visitContainerEnd(Object aVisitedComponent) {
105: theCurrentComponentWrapper = (ComponentWrapper) theCurrentComponentWrapper
106: .getParent();
107: }
108: });
109:
110: return theRootComponent;
111: }
112: }
|