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 java.util.ArrayList;
018: import java.util.List;
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021: import org.araneaframework.InputData;
022: import org.araneaframework.OutputData;
023: import org.araneaframework.core.StandardActionListener;
024: import org.araneaframework.uilib.core.BaseUIWidget;
025: import org.araneaframework.uilib.tree.TreeDataProvider;
026: import org.araneaframework.uilib.tree.TreeNodeContext;
027: import org.araneaframework.uilib.tree.TreeNodeWidget;
028: import org.araneaframework.uilib.tree.TreeWidget;
029:
030: /**
031: * Tree, that uses unsynchronized actions. Each node has five child nodes and
032: * depth of the tree is limited to five nodes. Child nodes are disposed when
033: * parent node is collapsed.
034: *
035: * @author Alar Kvell (alar@araneaframework.org)
036: */
037: public class UnsynchronizedTreeWidget extends BaseUIWidget {
038:
039: private static final Log log = LogFactory
040: .getLog(UnsynchronizedTreeWidget.class);
041:
042: private TreeWidget tree;
043:
044: protected void init() throws Exception {
045: setViewSelector("tree/unsynchronizedTree");
046: tree = new TreeWidget(new UnsynchronizedTreeDataProvider());
047: tree.setUseActions(true);
048: tree.setUseSynchronizedActions(false);
049: addWidget("tree", tree);
050: }
051:
052: public static class UnsynchronizedTreeDataProvider implements
053: TreeDataProvider {
054:
055: public List getChildren(TreeNodeContext parent) {
056: List children = new ArrayList();
057: for (int i = 0; i < 5; i++) {
058: children.add(new TreeNodeWidget(
059: new UnsynchronizedTreeDisplayWidget()));
060: }
061: return children;
062: }
063:
064: public boolean hasChildren(TreeNodeContext parent) {
065: return parent.getParentCount() < 5;
066: }
067:
068: }
069:
070: public static class UnsynchronizedTreeDisplayWidget extends
071: BaseUIWidget {
072:
073: private int counter;
074:
075: protected void init() throws Exception {
076: setViewSelector("tree/unsynchronizedTreeDisplay");
077: putViewData("counter", new Integer(counter));
078:
079: addActionListener("test", new StandardActionListener() {
080:
081: public void processAction(Object actionId,
082: String actionParam, InputData input,
083: OutputData output) throws Exception {
084: log.debug("Received action with id='" + actionId
085: + "' and param='" + actionParam + "'");
086: putViewData("counter", new Integer(++counter));
087: getTreeNodeCtx().renderNode(output); // Boilerplate code
088: }
089:
090: });
091:
092: addActionListener("sleep", new StandardActionListener() {
093:
094: public void processAction(Object actionId,
095: String actionParam, InputData input,
096: OutputData output) throws Exception {
097: log.debug("Received action with id='" + actionId
098: + "' and param='" + actionParam + "'");
099: Thread.sleep(10000);
100: getTreeNodeCtx().renderNode(output); // Boilerplate code
101: }
102:
103: });
104: }
105:
106: protected TreeNodeContext getTreeNodeCtx() {
107: return (TreeNodeContext) getEnvironment().getEntry(
108: TreeNodeContext.class);
109: }
110:
111: }
112:
113: }
|