001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.component.panelpositioned;
035:
036: import com.icesoft.faces.component.CSS_DEFAULT;
037: import com.icesoft.faces.component.dragdrop.DndEvent;
038: import com.icesoft.faces.component.ext.taglib.Util;
039: import com.icesoft.faces.component.panelseries.UISeries;
040: import com.icesoft.faces.context.effects.JavascriptContext;
041:
042: import javax.faces.context.FacesContext;
043: import javax.faces.el.MethodBinding;
044: import javax.faces.el.ValueBinding;
045: import javax.faces.event.AbortProcessingException;
046: import javax.faces.event.FacesEvent;
047: import javax.faces.event.PhaseId;
048:
049: /**
050: * Panel Positioned Componenet class
051: */
052: public class PanelPositioned extends UISeries {
053:
054: public static final String COMPONENET_TYPE = "com.icesoft.faces.dragdrop.PanelPositioned";
055: public static final String DEFAULT_RENDERER_TYPE = "com.icesoft.faces.dragdrop.PanelPositionedRenderer";
056: public static final String COMPONENT_FAMILY = "com.icesoft.faces.dragdrop.PanelPositionedFamily";
057:
058: private String styleClass;
059: private String style;
060: private MethodBinding listener;
061: private String overlap;
062: private String constraint;
063: private String handle;
064: private String hoverclass;
065:
066: public PanelPositioned() {
067: super ();
068: setRendererType(DEFAULT_RENDERER_TYPE);
069: JavascriptContext.includeLib(JavascriptContext.ICE_EXTRAS,
070: FacesContext.getCurrentInstance());
071: }
072:
073: public String getFamily() {
074: return COMPONENT_FAMILY;
075: }
076:
077: public String getRendererType() {
078: return DEFAULT_RENDERER_TYPE;
079: }
080:
081: public String getStyleClass() {
082: return Util.getQualifiedStyleClass(this , styleClass,
083: CSS_DEFAULT.POSITIONED_PANEL_DEFAULT_CLASS,
084: "styleClass");
085: }
086:
087: public void setStyleClass(String styleClass) {
088: this .styleClass = styleClass;
089: }
090:
091: public String getStyle() {
092: if (style != null) {
093: return style;
094: }
095: ValueBinding vb = getValueBinding("style");
096: return vb != null ? (String) vb.getValue(getFacesContext())
097: : null;
098: }
099:
100: public void setStyle(String style) {
101: this .style = style;
102: }
103:
104: public MethodBinding getListener() {
105: return listener;
106: }
107:
108: public void setListener(MethodBinding listener) {
109: this .listener = listener;
110: }
111:
112: public String getOverlap() {
113: if (overlap != null) {
114: return overlap;
115: }
116: ValueBinding vb = getValueBinding("overlap");
117: return vb != null ? (String) vb.getValue(getFacesContext())
118: : null;
119: }
120:
121: /**
122: * Either 'vertical' or 'horizontal'. For floating sortables or horizontal
123: * lists, choose 'horizontal'. Vertical lists should use 'vertical'.
124: *
125: * @param overlap
126: */
127: public void setOverlap(String overlap) {
128: this .overlap = overlap;
129: }
130:
131: public String getConstraint() {
132: if (constraint != null) {
133: return constraint;
134: }
135: ValueBinding vb = getValueBinding("constraint");
136: return vb != null ? (String) vb.getValue(getFacesContext())
137: : null;
138: }
139:
140: /**
141: * If set to 'horizontal' or 'vertical' the drag will be constrained to take
142: * place only horizontally or vertically.
143: *
144: * @param constraint
145: */
146: public void setConstraint(String constraint) {
147: this .constraint = constraint;
148: }
149:
150: public String getHandle() {
151: if (handle != null) {
152: return handle;
153: }
154: ValueBinding vb = getValueBinding("handle");
155: return vb != null ? (String) vb.getValue(getFacesContext())
156: : null;
157: }
158:
159: /**
160: * The handle used to drag. The first child/grandchild/etc. element found
161: * within the element that has this CSS class value will be used as the
162: * handle.
163: *
164: * @param handle
165: */
166: public void setHandle(String handle) {
167: this .handle = handle;
168: }
169:
170: public String getHoverclass() {
171: if (hoverclass != null) {
172: return hoverclass;
173: }
174: ValueBinding vb = getValueBinding("hoverclass");
175: return vb != null ? (String) vb.getValue(getFacesContext())
176: : null;
177: }
178:
179: /**
180: * If set, the Droppable will have this additional CSS class when an
181: * accepted Draggable is hovered over it.
182: *
183: * @param hoverclass
184: */
185: public void setHoverclass(String hoverclass) {
186: this .hoverclass = hoverclass;
187: }
188:
189: public void broadcast(FacesEvent event)
190: throws AbortProcessingException {
191:
192: if (event instanceof PanelPositionedEvent) {
193: try {
194:
195: PanelPositionedEvent de = (PanelPositionedEvent) event;
196: de.process(); // Copy over the list values now
197: MethodBinding mb = de.getListener();
198: Object[] oa = { de };
199: mb.invoke(FacesContext.getCurrentInstance(), oa);
200: } catch (Exception e) {
201: e.printStackTrace();
202: }
203: }
204: super .broadcast(event);
205: }
206:
207: /* (non-Javadoc)
208: * @see javax.faces.component.UIComponent#queueEvent(javax.faces.event.FacesEvent)
209: */
210: public void queueEvent(FacesEvent event) {
211: if (event instanceof DndEvent) {
212:
213: event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
214: }
215: super .queueEvent(event);
216: }
217:
218: public Object saveState(FacesContext context) {
219: Object[] values = new Object[4];
220: values[0] = super .saveState(context);
221: values[1] = styleClass;
222: values[2] = style;
223: values[3] = listener;
224: return values;
225: }
226:
227: public void restoreState(FacesContext context, Object stateIn) {
228: Object[] state = (Object[]) stateIn;
229: super .restoreState(context, state[0]);
230: styleClass = (String) state[1];
231: style = (String) state[2];
232: listener = (MethodBinding) state[3];
233: }
234:
235: }
|