KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > component > UINodeDescendants


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.repo.component;
18
19 import javax.faces.component.UICommand;
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23 import javax.faces.event.ActionEvent;
24
25 import org.alfresco.service.cmr.repository.NodeRef;
26
27 /**
28  * @author Kevin Roast
29  */

30 public class UINodeDescendants extends UICommand
31 {
32    // ------------------------------------------------------------------------------
33
// Construction
34

35    /**
36     * Default constructor
37     */

38    public UINodeDescendants()
39    {
40       setRendererType("org.alfresco.faces.NodeDescendantsLinkRenderer");
41    }
42    
43    
44    // ------------------------------------------------------------------------------
45
// Component implementation
46

47    /**
48     * @see javax.faces.component.UIComponent#getFamily()
49     */

50    public String JavaDoc getFamily()
51    {
52       return "org.alfresco.faces.NodeDescendants";
53    }
54    
55    /**
56     * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
57     */

58    public void restoreState(FacesContext context, Object JavaDoc state)
59    {
60       Object JavaDoc values[] = (Object JavaDoc[])state;
61       // standard component attributes are restored by the super class
62
super.restoreState(context, values[0]);
63       this.maxChildren = (Integer JavaDoc)values[1];
64       this.showEllipses = (Boolean JavaDoc)values[2];
65    }
66    
67    /**
68     * @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
69     */

70    public Object JavaDoc saveState(FacesContext context)
71    {
72       Object JavaDoc values[] = new Object JavaDoc[3];
73       // standard component attributes are saved by the super class
74
values[0] = super.saveState(context);
75       values[1] = this.maxChildren;
76       values[2] = this.showEllipses;
77       return (values);
78    }
79    
80    
81    // ------------------------------------------------------------------------------
82
// Strongly typed component property accessors
83

84    /**
85     * @return the maximum number of child descendants to be displayed, default maximum is 3.
86     */

87    public int getMaxChildren()
88    {
89       ValueBinding vb = getValueBinding("maxChildren");
90       if (vb != null)
91       {
92          this.maxChildren = (Integer JavaDoc)vb.getValue(getFacesContext());
93       }
94       
95       if (this.maxChildren != null)
96       {
97          return this.maxChildren.intValue();
98       }
99       else
100       {
101          // return default
102
return 3;
103       }
104    }
105    
106    /**
107     * @param value The maximum allowed before the no more links are shown
108     */

109    public void setMaxChildren(int value)
110    {
111       if (value > 0 && value <= 256)
112       {
113          this.maxChildren = Integer.valueOf(value);
114       }
115    }
116    
117    /**
118     * @return whether to show ellipses "..." if more descendants than the maxChildren value are found
119     */

120    public boolean getShowEllipses()
121    {
122       ValueBinding vb = getValueBinding("showEllipses");
123       if (vb != null)
124       {
125          this.showEllipses = (Boolean JavaDoc)vb.getValue(getFacesContext());
126       }
127       
128       if (this.showEllipses != null)
129       {
130          return this.showEllipses.booleanValue();
131       }
132       else
133       {
134          // return default
135
return true;
136       }
137    }
138    
139    /**
140     * @param showLink True to show ellipses "..." if more descendants than maxChildren are found
141     */

142    public void setShowEllipses(boolean showEllipses)
143    {
144       this.showEllipses = Boolean.valueOf(showEllipses);
145    }
146    
147    
148    // ------------------------------------------------------------------------------
149
// Inner classes
150

151    /**
152     * Class representing the clicking of a node descendant element.
153     */

154    public static class NodeSelectedEvent extends ActionEvent
155    {
156       public NodeSelectedEvent(UIComponent component, NodeRef nodeRef, boolean isParent)
157       {
158          super(component);
159          this.NodeReference = nodeRef;
160          this.IsParent = isParent;
161       }
162       
163       public NodeRef NodeReference;
164       public boolean IsParent;
165    }
166    
167    
168    // ------------------------------------------------------------------------------
169
// Private data
170

171    /** maximum number of child descendants to display */
172    private Integer JavaDoc maxChildren = null;
173    
174    /** whether to show ellipses if more descendants than the maxChildren are found */
175    private Boolean JavaDoc showEllipses = null;
176 }
177
Popular Tags