KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > dragdrop > DndEvent


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.dragdrop;
35
36 import javax.faces.component.UIComponent;
37 import javax.faces.event.FacesEvent;
38 import javax.faces.event.FacesListener;
39 import javax.faces.event.PhaseId;
40 import java.util.StringTokenizer JavaDoc;
41
42
43 /**
44  * A DnDEvent is passed to Drag and Drop Event listeners. It contains all the
45  * information on the type of event, and the components involved.
46  */

47 public class DndEvent extends FacesEvent {
48
49     private int eventType;
50
51
52     private Object JavaDoc targetDropValue;
53     private Object JavaDoc targetDragValue;
54     private String JavaDoc targetClientId;
55
56     /**
57      * Event type for when a Draggable panel is starting to drag
58      */

59     public static final int DRAG_START = 1;
60     public static final int DRAGGING = 1;
61     /**
62      * Event type for when a Draggable panel has been dropped, but not on a drop
63      * target.
64      */

65     public static final int DRAG_CANCEL = 2;
66     /**
67      * Event type for when a Draggable panel has been dropped on a drop target.
68      * The dndComponent will be set to the drop target for this event
69      */

70     public static final int DROPPED = 3;
71     /**
72      * Event type for when a Draggable panel is being hovered over a drop
73      * target. The dndComponent will be set to the drop target for this event
74      */

75     public static final int HOVER_START = 4;
76     /**
77      * Event type for when a Drgabble panel is no longer hovering over a drop
78      * target.
79      */

80     public static final int HOVER_END = 5;
81
82     private static String JavaDoc[] names = {"none", "dragging", "drag_cancel",
83                                      "dropped", "hover_start", "hover_end",
84                                      "pointerDraw"};
85
86     /**
87      * Mask to cover all DnD Events.
88      */

89     public static final String JavaDoc MASK_ALL = "1,2,3,4,5";
90
91     public static final String JavaDoc MASK_ALL_BUT_DROPS = "1,4,5";
92
93
94     /**
95      * DnDEvent This constructor is called by Drag and Drop components in the
96      * Decode method.
97      *
98      * @param uiComponent
99      * @param eventType
100      * @param targetClentId
101      * @param targetDragValue
102      * @param targetDropValue
103      */

104     public DndEvent(UIComponent uiComponent, int eventType,
105                     String JavaDoc targetClentId, Object JavaDoc targetDragValue,
106                     Object JavaDoc targetDropValue) {
107         super(uiComponent);
108         setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
109         this.eventType = eventType;
110         this.targetClientId = targetClentId;
111         this.targetDragValue = targetDragValue;
112         this.targetDropValue = targetDropValue;
113
114
115     }
116
117     /**
118      * False
119      *
120      * @param facesListener
121      * @return boolean
122      */

123     public boolean isAppropriateListener(FacesListener facesListener) {
124         return false;
125     }
126
127     /**
128      * Not implemented
129      *
130      * @param facesListener
131      */

132     public void processListener(FacesListener facesListener) {
133     }
134
135     /**
136      * Event type for the Event. Possible values are DRAG_START, DRAG_CANCEL,
137      * DROPPED, HOVER_START HOVER_END
138      *
139      * @return int eventType
140      */

141     public int getEventType() {
142         return eventType;
143     }
144
145
146     /**
147      * The drop value assigned to the target PanelGroup Null for DRAG_START,
148      * DRAG_CANCEL, and HOVER_END events
149      *
150      * @return Object targetDropValue
151      */

152     public Object JavaDoc getTargetDropValue() {
153         return targetDropValue;
154     }
155
156     /**
157      * The drag value assigned to the target PanelGroup Null for DRAG_START,
158      * DRAG_CANCEL, and HOVER_END events
159      *
160      * @return Object targetDragValue
161      */

162     public Object JavaDoc getTargetDragValue() {
163         return targetDragValue;
164     }
165
166     /**
167      * The clientId of the target Panel Group. Null for DRAG_START, DRAG_CANCEL,
168      * and HOVER_END events
169      *
170      * @return String targetClientId
171      */

172     public String JavaDoc getTargetClientId() {
173         return targetClientId;
174     }
175
176     public static String JavaDoc getEventName(int i) {
177         return names[i];
178     }
179
180     /**
181      * Parse a mask value to make its valid, Used in rendering.
182      *
183      * @param mask
184      * @return String mask
185      */

186     public static String JavaDoc parseMask(String JavaDoc mask) {
187         if (mask == null) {
188             return null;
189         }
190         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(mask, ",");
191         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
192         while (st.hasMoreTokens()) {
193             String JavaDoc token = st.nextToken();
194             boolean f = false;
195             for (int i = 1; i < names.length; i++) {
196                 token = token.trim();
197                 if (token.length() > 0) {
198                     if (token.equalsIgnoreCase(names[i])) {
199                         sb.append(i);
200                         f = true;
201                     }
202                 }
203             }
204             if (!f) {
205                 String JavaDoc message = "Mask value [" + token + "] in mask [" + mask +
206                                  "] is not valid. Valid values are [";
207                 for (int ie = 1; ie < names.length; ie++) {
208                     message += names[ie];
209                     int next = ie + 1;
210                     if (next < names.length) {
211                         message += ", ";
212                     }
213                     message += "]";
214                 }
215                 throw new IllegalArgumentException JavaDoc(message);
216             }
217             if (st.hasMoreTokens()) {
218                 sb.append(",");
219             }
220         }
221         return sb.toString();
222     }
223 }
224
Popular Tags