KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > panelpositioned > PanelPositioned


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.panelpositioned;
35
36 import com.icesoft.faces.component.CSS_DEFAULT;
37 import com.icesoft.faces.component.dragdrop.DndEvent;
38 import com.icesoft.faces.component.ext.taglib.Util;
39 import com.icesoft.faces.component.panelseries.UISeries;
40 import com.icesoft.faces.context.effects.JavascriptContext;
41
42 import javax.faces.context.FacesContext;
43 import javax.faces.el.MethodBinding;
44 import javax.faces.el.ValueBinding;
45 import javax.faces.event.AbortProcessingException;
46 import javax.faces.event.FacesEvent;
47 import javax.faces.event.PhaseId;
48
49 /**
50  * Panel Positioned Componenet class
51  */

52 public class PanelPositioned extends UISeries {
53
54     public static final String JavaDoc COMPONENET_TYPE =
55             "com.icesoft.faces.dragdrop.PanelPositioned";
56     public static final String JavaDoc DEFAULT_RENDERER_TYPE =
57             "com.icesoft.faces.dragdrop.PanelPositionedRenderer";
58     public static final String JavaDoc COMPONENT_FAMILY =
59             "com.icesoft.faces.dragdrop.PanelPositionedFamily";
60
61     private String JavaDoc styleClass;
62     private String JavaDoc style;
63     private MethodBinding listener;
64     private String JavaDoc overlap;
65     private String JavaDoc constraint;
66     private String JavaDoc handle;
67     private String JavaDoc hoverclass;
68     
69
70
71     public PanelPositioned() {
72         super();
73         setRendererType(DEFAULT_RENDERER_TYPE);
74         JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
75                                      FacesContext.getCurrentInstance());
76     }
77
78     public String JavaDoc getFamily() {
79         return COMPONENT_FAMILY;
80     }
81
82
83     public String JavaDoc getRendererType() {
84         return DEFAULT_RENDERER_TYPE;
85     }
86
87     public String JavaDoc getStyleClass() {
88         return Util.getQualifiedStyleClass(this,
89                                 styleClass,
90                                 CSS_DEFAULT.POSITIONED_PANEL_DEFAULT_CLASS,
91                                 "styleClass");
92     }
93
94     public void setStyleClass(String JavaDoc styleClass) {
95         this.styleClass = styleClass;
96     }
97
98     public String JavaDoc getStyle() {
99         if (style != null) {
100             return style;
101         }
102         ValueBinding vb = getValueBinding("style");
103         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
104     }
105
106     public void setStyle(String JavaDoc style) {
107         this.style = style;
108     }
109
110     public MethodBinding getListener() {
111         return listener;
112     }
113
114     public void setListener(MethodBinding listener) {
115         this.listener = listener;
116     }
117
118     public String JavaDoc getOverlap() {
119         if (overlap != null) {
120             return overlap;
121         }
122         ValueBinding vb = getValueBinding("overlap");
123         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
124     }
125
126     /**
127      * Either 'vertical' or 'horizontal'. For floating sortables or horizontal
128      * lists, choose 'horizontal'. Vertical lists should use 'vertical'.
129      *
130      * @param overlap
131      */

132     public void setOverlap(String JavaDoc overlap) {
133         this.overlap = overlap;
134     }
135
136     public String JavaDoc getConstraint() {
137         if (constraint != null) {
138             return constraint;
139         }
140         ValueBinding vb = getValueBinding("constraint");
141         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
142     }
143
144     /**
145      * If set to 'horizontal' or 'vertical' the drag will be constrained to take
146      * place only horizontally or vertically.
147      *
148      * @param constraint
149      */

150     public void setConstraint(String JavaDoc constraint) {
151         this.constraint = constraint;
152     }
153
154     public String JavaDoc getHandle() {
155         if (handle != null) {
156             return handle;
157         }
158         ValueBinding vb = getValueBinding("handle");
159         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
160     }
161
162     /**
163      * The handle used to drag. The first child/grandchild/etc. element found
164      * within the element that has this CSS class value will be used as the
165      * handle.
166      *
167      * @param handle
168      */

169     public void setHandle(String JavaDoc handle) {
170         this.handle = handle;
171     }
172
173     public String JavaDoc getHoverclass() {
174         if (hoverclass != null) {
175             return hoverclass;
176         }
177         ValueBinding vb = getValueBinding("hoverclass");
178         return vb != null ? (String JavaDoc) vb.getValue(getFacesContext()) : null;
179     }
180
181     /**
182      * If set, the Droppable will have this additional CSS class when an
183      * accepted Draggable is hovered over it.
184      *
185      * @param hoverclass
186      */

187     public void setHoverclass(String JavaDoc hoverclass) {
188         this.hoverclass = hoverclass;
189     }
190
191
192     public void broadcast(FacesEvent event)
193             throws AbortProcessingException {
194
195
196         if (event instanceof PanelPositionedEvent) {
197             try {
198
199                 PanelPositionedEvent de = (PanelPositionedEvent) event;
200                 de.process(); // Copy over the list values now
201
MethodBinding mb = de.getListener();
202                 Object JavaDoc[] oa = {de};
203                 mb.invoke(FacesContext.getCurrentInstance(), oa);
204             } catch (Exception JavaDoc e) {
205                 e.printStackTrace();
206             }
207         }
208         super.broadcast(event);
209     }
210
211     /* (non-Javadoc)
212      * @see javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
213      */

214     public void queueEvent(FacesEvent event) {
215         if (event instanceof DndEvent) {
216
217             event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
218         }
219         super.queueEvent(event);
220     }
221
222     public Object JavaDoc saveState(FacesContext context) {
223         Object JavaDoc[] values = new Object JavaDoc[4];
224         values[0] = super.saveState(context);
225         values[1] = styleClass;
226         values[2] = style;
227         values[3] = listener;
228         return values;
229     }
230
231     public void restoreState(FacesContext context, Object JavaDoc stateIn) {
232         Object JavaDoc[] state = (Object JavaDoc[]) stateIn;
233         super.restoreState(context, state[0]);
234         styleClass = (String JavaDoc) state[1];
235         style = (String JavaDoc) state[2];
236         listener = (MethodBinding) state[3];
237     }
238
239
240 }
241
Popular Tags