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.dragdrop;
035:
036: import javax.faces.component.UIComponent;
037: import javax.faces.event.FacesEvent;
038: import javax.faces.event.FacesListener;
039: import javax.faces.event.PhaseId;
040: import java.util.StringTokenizer;
041:
042: /**
043: * A DnDEvent is passed to Drag and Drop Event listeners. It contains all the
044: * information on the type of event, and the components involved.
045: */
046: public class DndEvent extends FacesEvent {
047:
048: private int eventType;
049:
050: private Object targetDropValue;
051: private Object targetDragValue;
052: private String targetClientId;
053:
054: /**
055: * Event type for when a Draggable panel is starting to drag
056: */
057: public static final int DRAG_START = 1;
058: public static final int DRAGGING = 1;
059: /**
060: * Event type for when a Draggable panel has been dropped, but not on a drop
061: * target.
062: */
063: public static final int DRAG_CANCEL = 2;
064: /**
065: * Event type for when a Draggable panel has been dropped on a drop target.
066: * The dndComponent will be set to the drop target for this event
067: */
068: public static final int DROPPED = 3;
069: /**
070: * Event type for when a Draggable panel is being hovered over a drop
071: * target. The dndComponent will be set to the drop target for this event
072: */
073: public static final int HOVER_START = 4;
074: /**
075: * Event type for when a Drgabble panel is no longer hovering over a drop
076: * target.
077: */
078: public static final int HOVER_END = 5;
079:
080: private static String[] names = { "none", "dragging",
081: "drag_cancel", "dropped", "hover_start", "hover_end",
082: "pointerDraw" };
083:
084: /**
085: * Mask to cover all DnD Events.
086: */
087: public static final String MASK_ALL = "1,2,3,4,5";
088:
089: public static final String MASK_ALL_BUT_DROPS = "1,4,5";
090:
091: /**
092: * DnDEvent This constructor is called by Drag and Drop components in the
093: * Decode method.
094: *
095: * @param uiComponent
096: * @param eventType
097: * @param targetClentId
098: * @param targetDragValue
099: * @param targetDropValue
100: */
101: public DndEvent(UIComponent uiComponent, int eventType,
102: String targetClentId, Object targetDragValue,
103: Object targetDropValue) {
104: super (uiComponent);
105: setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
106: this .eventType = eventType;
107: this .targetClientId = targetClentId;
108: this .targetDragValue = targetDragValue;
109: this .targetDropValue = targetDropValue;
110:
111: }
112:
113: /**
114: * False
115: *
116: * @param facesListener
117: * @return boolean
118: */
119: public boolean isAppropriateListener(FacesListener facesListener) {
120: return false;
121: }
122:
123: /**
124: * Not implemented
125: *
126: * @param facesListener
127: */
128: public void processListener(FacesListener facesListener) {
129: }
130:
131: /**
132: * Event type for the Event. Possible values are DRAG_START, DRAG_CANCEL,
133: * DROPPED, HOVER_START HOVER_END
134: *
135: * @return int eventType
136: */
137: public int getEventType() {
138: return eventType;
139: }
140:
141: /**
142: * The drop value assigned to the target PanelGroup Null for DRAG_START,
143: * DRAG_CANCEL, and HOVER_END events
144: *
145: * @return Object targetDropValue
146: */
147: public Object getTargetDropValue() {
148: return targetDropValue;
149: }
150:
151: /**
152: * The drag value assigned to the target PanelGroup Null for DRAG_START,
153: * DRAG_CANCEL, and HOVER_END events
154: *
155: * @return Object targetDragValue
156: */
157: public Object getTargetDragValue() {
158: return targetDragValue;
159: }
160:
161: /**
162: * The clientId of the target Panel Group. Null for DRAG_START, DRAG_CANCEL,
163: * and HOVER_END events
164: *
165: * @return String targetClientId
166: */
167: public String getTargetClientId() {
168: return targetClientId;
169: }
170:
171: public static String getEventName(int i) {
172: return names[i];
173: }
174:
175: /**
176: * Parse a mask value to make its valid, Used in rendering.
177: *
178: * @param mask
179: * @return String mask
180: */
181: public static String parseMask(String mask) {
182: if (mask == null) {
183: return null;
184: }
185: StringTokenizer st = new StringTokenizer(mask, ",");
186: StringBuffer sb = new StringBuffer();
187: while (st.hasMoreTokens()) {
188: String token = st.nextToken();
189: boolean f = false;
190: for (int i = 1; i < names.length; i++) {
191: token = token.trim();
192: if (token.length() > 0) {
193: if (token.equalsIgnoreCase(names[i])) {
194: sb.append(i);
195: f = true;
196: }
197: }
198: }
199: if (!f) {
200: String message = "Mask value [" + token + "] in mask ["
201: + mask + "] is not valid. Valid values are [";
202: for (int ie = 1; ie < names.length; ie++) {
203: message += names[ie];
204: int next = ie + 1;
205: if (next < names.length) {
206: message += ", ";
207: }
208: message += "]";
209: }
210: throw new IllegalArgumentException(message);
211: }
212: if (st.hasMoreTokens()) {
213: sb.append(",");
214: }
215: }
216: return sb.toString();
217: }
218: }
|