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.uilib.tree;
016:
017: import java.io.Writer;
018: import java.util.List;
019: import org.araneaframework.Environment;
020: import org.araneaframework.OutputData;
021: import org.araneaframework.Widget;
022: import org.araneaframework.core.Assert;
023: import org.araneaframework.core.StandardEnvironment;
024: import org.araneaframework.http.HttpOutputData;
025:
026: /**
027: * @author Alar Kvell (alar@araneaframework.org)
028: * @since 1.0.7
029: */
030: public class TreeWidget extends TreeNodeWidget implements TreeContext {
031:
032: private static final long serialVersionUID = 1L;
033:
034: private TreeDataProvider dataProvider;
035: private boolean removeChildrenOnCollapse = true;
036: private boolean useActions = false;
037: private boolean useSynchronizedActions = true;
038: private TreeRenderer renderer;
039:
040: //TODO features:
041: // * not-dispose-children in client side
042: // * some nodes not collapsable
043: // * disable concrete tree node toggling client-side when request has been
044: // submitted - response not yet arrived and processed
045: // * make sure that all methods can be called before init
046:
047: /**
048: * Creates a new {@link TreeWidget} instance.
049: */
050: public TreeWidget() {
051: }
052:
053: /**
054: * Creates a new {@link TreeWidget} instance which will acquire the
055: * tree data from supplied {@link TreeDataProvider}.
056: *
057: * @param dataProvider
058: * tree data provider.
059: */
060: public TreeWidget(TreeDataProvider dataProvider) {
061: Assert.notNullParam(dataProvider, "dataProvider");
062: this .dataProvider = dataProvider;
063: }
064:
065: protected void init() throws Exception {
066: List children = loadChildren();
067: if (children != null)
068: addAllNodes(children);
069: }
070:
071: public Environment getEnvironment() {
072: return new StandardEnvironment(super .getEnvironment(),
073: TreeContext.class, this );
074: }
075:
076: public TreeDataProvider getDataProvider() {
077: return dataProvider;
078: }
079:
080: /**
081: * Set if actions are used instead of events in submit links. See
082: * {@link TreeContext#useActions()}.
083: */
084: public void setUseActions(boolean useActions) {
085: this .useActions = useActions;
086: }
087:
088: public boolean useActions() {
089: return useActions;
090: }
091:
092: /**
093: * Set if AJAX requests to tree widget are synchronized. See
094: * {@link TreeContext#useSynchronizedActions()}.
095: *
096: * @since 1.1
097: */
098: public void setUseSynchronizedActions(boolean useSynchronizedActions) {
099: this .useSynchronizedActions = useSynchronizedActions;
100: }
101:
102: public boolean useSynchronizedActions() {
103: return useSynchronizedActions;
104: }
105:
106: /**
107: * Set if child nodes are removed and discarded when a node is closed.
108: */
109: public void setRemoveChildrenOnCollapse(
110: boolean removeChildrenOnCollapse) {
111: this .removeChildrenOnCollapse = removeChildrenOnCollapse;
112: }
113:
114: public boolean isRemoveChildrenOnCollapse() {
115: return removeChildrenOnCollapse;
116: }
117:
118: /**
119: * Set tree renderer.
120: */
121: public void setRenderer(TreeRenderer renderer) {
122: Assert.notNullParam(renderer, "renderer");
123: this .renderer = renderer;
124: }
125:
126: public TreeRenderer getRenderer() {
127: return renderer;
128: }
129:
130: protected void render(OutputData output) throws Exception {
131: super .render(output);
132: Writer out = ((HttpOutputData) output).getWriter();
133: out.flush();
134: }
135:
136: // The following methods do nothing, because the root node of the tree has no
137: // display widget and therefore is always expanded.
138:
139: public Widget getDisplayWidget() {
140: return null;
141: }
142:
143: public void setCollapsed(boolean collapsed) {
144: }
145:
146: public void toggleCollapsed() {
147: }
148:
149: }
|