001: /**
002: * Copyright 2006 Webmedia Group Ltd.
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: **/package org.araneaframework.example.main.web.tree;
016:
017: import org.araneaframework.example.main.TemplateBaseWidget;
018: import org.araneaframework.uilib.core.BaseUIWidget;
019: import org.araneaframework.uilib.tree.TreeNodeContext;
020: import org.araneaframework.uilib.tree.TreeNodeWidget;
021: import org.araneaframework.uilib.tree.TreeWidget;
022:
023: /**
024: * Tree without a data provider - nodes are added during events.
025: *
026: * @author Alar Kvell (alar@araneaframework.org)
027: */
028: public class ComplexTreeWidget extends TemplateBaseWidget {
029:
030: protected TreeWidget tree;
031:
032: protected void init() throws Exception {
033: setViewSelector("tree/complexTree");
034: tree = new TreeWidget();
035: tree.setRemoveChildrenOnCollapse(false);
036: addWidget("tree", tree);
037: }
038:
039: public void handleEventAddNode() {
040: tree.addNode(new TreeNodeWidget(
041: new ComplexTreeFirstDisplayWidget()));
042: }
043:
044: public static class ComplexTreeFirstDisplayWidget extends
045: BaseUIWidget {
046:
047: protected void init() throws Exception {
048: setViewSelector("tree/complexTreeFirstDisplay");
049: }
050:
051: public void handleEventDelete() {
052: getTreeNodeCtx().getParentNode().removeNode(
053: getTreeNodeCtx().getIndex());
054: }
055:
056: public void handleEventAddChildren() {
057: TreeNodeWidget secondNode = new TreeNodeWidget(
058: new ComplexTreeSecondDisplayWidget());
059: getTreeNodeCtx().addNode(secondNode);
060: getTreeNodeCtx().setCollapsed(false);
061: secondNode.setCollapsed(false);
062: for (int i = 0; i < 4; i++) {
063: secondNode.addNode(new TreeNodeWidget(
064: new ComplexTreeThirdDisplayWidget()));
065: }
066: }
067:
068: protected TreeNodeContext getTreeNodeCtx() {
069: return (TreeNodeContext) getEnvironment().getEntry(
070: TreeNodeContext.class);
071: }
072:
073: }
074:
075: public static class ComplexTreeSecondDisplayWidget extends
076: BaseUIWidget {
077:
078: protected void init() throws Exception {
079: setViewSelector("tree/complexTreeSecondDisplay");
080: }
081:
082: public void handleEventInvertCollapsed() {
083: getTreeNodeCtx().toggleCollapsed();
084: }
085:
086: protected TreeNodeContext getTreeNodeCtx() {
087: return (TreeNodeContext) getEnvironment().getEntry(
088: TreeNodeContext.class);
089: }
090:
091: }
092:
093: public static class ComplexTreeThirdDisplayWidget extends
094: BaseUIWidget {
095:
096: protected void init() throws Exception {
097: setViewSelector("tree/complexTreeThirdDisplay");
098: }
099:
100: public int getLevel() {
101: return getTreeNodeCtx().getParentCount();
102: }
103:
104: protected TreeNodeContext getTreeNodeCtx() {
105: return (TreeNodeContext) getEnvironment().getEntry(
106: TreeNodeContext.class);
107: }
108:
109: }
110:
111: }
|