1 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 ; 41 42 43 47 public class DndEvent extends FacesEvent { 48 49 private int eventType; 50 51 52 private Object targetDropValue; 53 private Object targetDragValue; 54 private String targetClientId; 55 56 59 public static final int DRAG_START = 1; 60 public static final int DRAGGING = 1; 61 65 public static final int DRAG_CANCEL = 2; 66 70 public static final int DROPPED = 3; 71 75 public static final int HOVER_START = 4; 76 80 public static final int HOVER_END = 5; 81 82 private static String [] names = {"none", "dragging", "drag_cancel", 83 "dropped", "hover_start", "hover_end", 84 "pointerDraw"}; 85 86 89 public static final String MASK_ALL = "1,2,3,4,5"; 90 91 public static final String MASK_ALL_BUT_DROPS = "1,4,5"; 92 93 94 104 public DndEvent(UIComponent uiComponent, int eventType, 105 String targetClentId, Object targetDragValue, 106 Object 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 123 public boolean isAppropriateListener(FacesListener facesListener) { 124 return false; 125 } 126 127 132 public void processListener(FacesListener facesListener) { 133 } 134 135 141 public int getEventType() { 142 return eventType; 143 } 144 145 146 152 public Object getTargetDropValue() { 153 return targetDropValue; 154 } 155 156 162 public Object getTargetDragValue() { 163 return targetDragValue; 164 } 165 166 172 public String getTargetClientId() { 173 return targetClientId; 174 } 175 176 public static String getEventName(int i) { 177 return names[i]; 178 } 179 180 186 public static String parseMask(String mask) { 187 if (mask == null) { 188 return null; 189 } 190 StringTokenizer st = new StringTokenizer (mask, ","); 191 StringBuffer sb = new StringBuffer (); 192 while (st.hasMoreTokens()) { 193 String 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 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 (message); 216 } 217 if (st.hasMoreTokens()) { 218 sb.append(","); 219 } 220 } 221 return sb.toString(); 222 } 223 } 224 | Popular Tags |