Author: nbelaevski
Date: 2008-12-04 13:52:08 -0500 (Thu, 04 Dec 2008)
New Revision: 11567
Removed:
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDEventsExchangeMailer.java
Modified:
trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java
trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDropSupport.java
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDValidator.java
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
Log:
https://jira.jboss.org/jira/browse/RF-961
Modified: trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java
===================================================================
--- trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java 2008-12-04
18:47:19 UTC (rev 11566)
+++ trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDragSupport.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -59,15 +59,13 @@
super.broadcast(event);
if (event instanceof DragEvent) {
DragEvent dragEvent = (DragEvent) event;
- if (dragEvent.isValid()) {
- MethodBinding binding = getDragListener();
- if (binding != null) {
- binding.invoke(getFacesContext(), new Object[] {event});
- }
-
- new AjaxEvent(this).queue();
- new ActionEvent(this).queue();
+ MethodBinding binding = getDragListener();
+ if (binding != null) {
+ binding.invoke(getFacesContext(), new Object[] {event});
}
+
+ new AjaxEvent(this).queue();
+ new ActionEvent(this).queue();
}
}
Modified: trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDropSupport.java
===================================================================
--- trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDropSupport.java 2008-12-04
18:47:19 UTC (rev 11566)
+++ trunk/ui/drag-drop/src/main/java/org/richfaces/component/UIDropSupport.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -57,15 +57,13 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
if (event instanceof DropEvent) {
- if (((DropEvent) event).isValid()) {
- MethodBinding binding = getDropListener();
- if (binding != null) {
- binding.invoke(getFacesContext(), new Object[] {event});
- }
-
- new AjaxEvent(this).queue();
- new ActionEvent(this).queue();
+ MethodBinding binding = getDropListener();
+ if (binding != null) {
+ binding.invoke(getFacesContext(), new Object[] {event});
}
+
+ new AjaxEvent(this).queue();
+ new ActionEvent(this).queue();
}
}
Deleted:
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDEventsExchangeMailer.java
===================================================================
---
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDEventsExchangeMailer.java 2008-12-04
18:47:19 UTC (rev 11566)
+++
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDEventsExchangeMailer.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -1,183 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.renderkit;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.component.ContextCallback;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.apache.commons.collections.MultiHashMap;
-import org.richfaces.component.Draggable;
-import org.richfaces.component.Dropzone;
-import org.richfaces.event.DnDEvent;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 27.12.2006
- *
- */
-final class DnDEventsExchangeMailer {
- private DnDEventsExchangeMailer() {
-
- }
-
- private static class EventInfoStructure {
- private DnDEvent dndEvent;
- private EventCallback eventCallback;
-
- private Object type;
- private Object value;
-
- public EventInfoStructure(DnDEvent dndEvent,
- EventCallback eventCallback, Object type, Object value) {
- super();
- this.dndEvent = dndEvent;
- this.eventCallback = eventCallback;
- this.type = type;
- this.value = value;
- }
-
- }
-
- static abstract class EventCallback {
- abstract void processEvent(DnDEvent dndEvent, UIComponent source, FacesContext
facesContext, Object type, Object value);
- }
-
- static DnDEventsExchangeMailer getInstance(FacesContext facesContext) {
- synchronized (facesContext) {
- Map requestMap = facesContext.getExternalContext().getRequestMap();
-
- String attrName = DnDEventsExchangeMailer.class.getName();
- DnDEventsExchangeMailer instance;
- if ((instance = (DnDEventsExchangeMailer) requestMap.get(attrName)) == null) {
- instance = new DnDEventsExchangeMailer();
-
- requestMap.put(attrName, instance);
- }
-
- return instance;
- }
- }
-
- private Map<String, EventInfoStructure> queuedMap = new HashMap<String,
EventInfoStructure>();
-
- private Map<String, UIComponent> components = new HashMap<String,
UIComponent>();
-
- private void processEvent(UIComponent source, FacesContext facesContext, DnDEvent
dndEvent, EventCallback callback, Object type, Object value) {
- if (callback != null) {
- callback.processEvent(dndEvent, source, facesContext, type, value);
- }
- }
-
- /**
- * Decode drag & drop events. Collect pairs of correspondent drag & drop events
and send them
- * together where OnDrag becomes always before OnDrop.
- *
- * @param sourceId Id of element event come from
- * @param target component that receive event
- * @param facesContext Faces context
- * @param dndEvent drag & drop event descriptor
- * @param callback call back method
- * @param type type of dragged/dropped value
- * @param value dragged/dropped value
- * @param isDraggable whether the event related draggable component or dropzone one.
- */
- public void mailEvent(String sourceId, UIComponent target, FacesContext facesContext,
final DnDEvent dndEvent,
- final EventCallback callback, final Object type, final Object value, boolean
isDraggable) {
-
- final UIComponent component = components.get(sourceId);
- String targetId = target.getClientId(facesContext);
-
- if (component == null) {
- //component with that sourceId have never mailed anything before - wait
- if (queuedMap.containsKey(sourceId)) {
- throw new IllegalStateException("Drag source with id '" + sourceId +
"' already specified.");
- }
- queuedMap.put(sourceId, new EventInfoStructure(dndEvent, callback, type, value));
- components.put(targetId, target);
- } else {
- //check queued mail lists for current component
- final EventInfoStructure eventInfo = (EventInfoStructure) queuedMap.get(targetId);
- if (eventInfo != null) {
- Draggable draggable;
- Dropzone dropzone;
-
- final EventInfoStructure dragEventInfo = isDraggable ? eventInfo : new
EventInfoStructure(dndEvent, callback, type, value);
- final EventInfoStructure dropEventInfo = isDraggable ? new
EventInfoStructure(dndEvent, callback, type, value) : eventInfo;
-
- Object acceptedTypes;
- Object dragType;
-
- if (isDraggable) {
- draggable = (Draggable) target;
- dropzone = (Dropzone) component;
-
- acceptedTypes = eventInfo.type;
- dragType = type;
- } else {
- draggable = (Draggable) component;
- dropzone = (Dropzone) target;
-
- acceptedTypes = type;
- dragType = eventInfo.type;
- }
-
- if (DnDValidator.validateAcceptTypes(facesContext,
- draggable, dropzone,
- dragType, acceptedTypes)) {
-
- // Make sure that we will have OnDrag event occur first
- facesContext.getViewRoot().invokeOnComponent(facesContext, isDraggable ? targetId :
sourceId, new ContextCallback() {
- public void invokeContextCallback(FacesContext fc,
- UIComponent targetComponent) {
-
- processEvent(targetComponent, fc, dragEventInfo.dndEvent,
dragEventInfo.eventCallback,
- dropEventInfo.type, dropEventInfo.value);
-
- dropEventInfo.dndEvent.queue();
- }
- });
-
- facesContext.getViewRoot().invokeOnComponent(facesContext, isDraggable ? sourceId :
targetId, new ContextCallback() {
- public void invokeContextCallback(FacesContext fc,
- UIComponent targetComponent) {
-
- processEvent(targetComponent, fc, dropEventInfo.dndEvent,
dropEventInfo.eventCallback,
- dragEventInfo.type, dragEventInfo.value);
-
- dragEventInfo.dndEvent.queue();
- }
- });
- }
-
- queuedMap.remove(targetId);
- }
- }
- }
-
-}
-
Modified: trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDValidator.java
===================================================================
--- trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDValidator.java 2008-12-04
18:47:19 UTC (rev 11566)
+++ trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DnDValidator.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -41,8 +41,8 @@
class DnDValidator {
private final static String MESSAGE_FORMAT = "Dropzone [{0}] with accepted types
{1} cannot accept Draggable [{2}] with dragType [{3}]";
- static boolean validateAcceptTypes(FacesContext context, Draggable draggable, Dropzone
dropzone, Object dragType, Object acceptedTypes) {
- Set set = AjaxRendererUtils.asSet(acceptedTypes);
+ static boolean validateAcceptTypes(FacesContext context, Draggable draggable, Dropzone
dropzone, String dragType, Object acceptedTypes) {
+ Set<String> set = AjaxRendererUtils.asSet(acceptedTypes);
if (set == null || !set.contains(dragType)) {
UIComponent component = (UIComponent) dropzone;
String text = MessageFormat.format(
Modified:
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java
===================================================================
---
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2008-12-04
18:47:19 UTC (rev 11566)
+++
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DraggableRendererContributor.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -32,10 +32,6 @@
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
import org.richfaces.component.Draggable;
-import org.richfaces.component.Dropzone;
-import org.richfaces.event.DnDEvent;
-import org.richfaces.event.DragEvent;
-import org.richfaces.renderkit.DnDEventsExchangeMailer.EventCallback;
/**
* @author shura
@@ -45,18 +41,6 @@
public final static String DRAG_SOURCE_ID = "dragSourceId";
- private static final EventCallback dragEventsCallback = new EventCallback() {
-
- void processEvent(DnDEvent dndEvent, UIComponent source,
- FacesContext facesContext, Object type, Object value) {
-
- DragEvent dragEvent = (DragEvent) dndEvent;
- dragEvent.setDropTarget((Dropzone) source);
- dragEvent.setDropValue(value);
- dragEvent.setAcceptedTypes(type);
- }
- };
-
private static DraggableRendererContributor instance;
private DraggableRendererContributor() {
@@ -96,23 +80,7 @@
}
public void decode(FacesContext context, UIComponent component, CompositeRenderer
compositeRenderer) {
- DnDEventsExchangeMailer eventsExchanger =
DnDEventsExchangeMailer.getInstance(context);
- String clientId = component.getClientId(context);
- Map paramMap = context.getExternalContext().getRequestParameterMap();
-
- if(clientId.equals(paramMap.get(DRAG_SOURCE_ID))){
- String dropTargetId = (String)
paramMap.get(DropzoneRendererContributor.DROP_TARGET_ID);
-
- if (compositeRenderer != null) {
- compositeRenderer.contributorDecodeCallback(component, context, this, dropTargetId);
- }
-
- Draggable draggable = (Draggable) component;
-
- eventsExchanger.mailEvent(dropTargetId, component,
- context, new DragEvent(component), dragEventsCallback, draggable.getDragType(),
- draggable.getDragValue(), true);
- }
+ //decoding is done solely by dropzone
}
public String[] getStyleDependencies() {
Modified:
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java
===================================================================
---
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2008-12-04
18:47:19 UTC (rev 11566)
+++
trunk/ui/drag-drop/src/main/java/org/richfaces/renderkit/DropzoneRendererContributor.java 2008-12-04
18:52:08 UTC (rev 11567)
@@ -24,9 +24,11 @@
import java.util.Map;
import javax.faces.FacesException;
+import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import org.ajax4jsf.component.ContextCallbackWrapper;
import org.ajax4jsf.javascript.DnDScript;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
@@ -36,12 +38,11 @@
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.richfaces.component.Draggable;
import org.richfaces.component.Dropzone;
-import org.richfaces.event.DnDEvent;
+import org.richfaces.event.DragEvent;
import org.richfaces.event.DropEvent;
import org.richfaces.json.JSONCollection;
import org.richfaces.json.JSONException;
import org.richfaces.json.JSONMap;
-import org.richfaces.renderkit.DnDEventsExchangeMailer.EventCallback;
/**
* @author shura
@@ -51,21 +52,6 @@
public static final String DROP_TARGET_ID = "dropTargetId";
- private static final EventCallback dropEventsCallback = new EventCallback() {
-
- void processEvent(DnDEvent dndEvent, UIComponent source,
- FacesContext facesContext, Object type, Object value) {
-
- DropEvent dropEvent = (DropEvent) dndEvent;
- Draggable draggable = (Draggable) source;
- dropEvent.setDraggableSource(draggable);
-
- dropEvent.setDragType((String) type);
- dropEvent.setDragValue(value);
-
- }
- };
-
private DropzoneRendererContributor() {
super();
}
@@ -153,26 +139,58 @@
return null;
}
+ private static final class DraggableDecoderContextCallback implements ContextCallback {
+
+ private Dropzone dropzone;
+
+ public DraggableDecoderContextCallback(Dropzone dropzone) {
+ super();
+
+ this.dropzone = dropzone;
+ }
+
+ public void invokeContextCallback(FacesContext context,
+ UIComponent target) {
+
+ Draggable draggable = (Draggable) target;
+
+ String dragType = draggable.getDragType();
+ Object acceptedTypes = dropzone.getAcceptedTypes();
+
+ if (DnDValidator.validateAcceptTypes(context,
+ draggable, dropzone,
+ dragType, acceptedTypes)) {
+
+ DragEvent dragEvent = new DragEvent((UIComponent) draggable);
+ dragEvent.setDropTarget(dropzone);
+ dragEvent.setAcceptedTypes(acceptedTypes);
+ dragEvent.setDropValue(dropzone.getDropValue());
+
+ DropEvent dropEvent = new DropEvent((UIComponent) dropzone);
+ dropEvent.setDraggableSource(draggable);
+ dropEvent.setDragType(dragType);
+ dropEvent.setDragValue(draggable.getDragValue());
+
+ dragEvent.queue();
+ dropEvent.queue();
+ }
+ }
+ }
+
public void decode(FacesContext context, UIComponent component, CompositeRenderer
compositeRenderer) {
- DnDEventsExchangeMailer eventsExchanger =
DnDEventsExchangeMailer.getInstance(context);
-
String clientId = component.getClientId(context);
- Map paramMap = context.getExternalContext().getRequestParameterMap();
+ Map<String, String> paramMap =
context.getExternalContext().getRequestParameterMap();
if(clientId.equals(paramMap.get(DROP_TARGET_ID))){
String dragSourceId = (String)
paramMap.get(DraggableRendererContributor.DRAG_SOURCE_ID);
-
- if (compositeRenderer != null) {
- compositeRenderer.contributorDecodeCallback(component, context, this, dragSourceId);
+
+ if (dragSourceId != null && dragSourceId.length() != 0) {
+ DraggableDecoderContextCallback draggableDecoderContextCallback =
+ new DraggableDecoderContextCallback((Dropzone) component);
+
+ context.getViewRoot().invokeOnComponent(context, dragSourceId,
+ new ContextCallbackWrapper(draggableDecoderContextCallback));
}
-
- Dropzone dropzone = (Dropzone) component;
-
- eventsExchanger.mailEvent(dragSourceId, component,
- context, new DropEvent(component), dropEventsCallback,
- dropzone.getAcceptedTypes(),
- dropzone.getDropValue(), false
- );
}
}
@@ -189,7 +207,7 @@
definition.addToBody("var options =
").addToBody(ScriptUtils.toScript(requestOpts)).addToBody(";");
definition.addToBody("options.parameters['" + DROP_TARGET_ID +
"'] = '" + component.getClientId(context) + "';");
//TODO nick - remove as legacy
- definition.addToBody("Object.extend(options.parameters,drag.getParameters());");
+ definition.addToBody("Richfaces.mergeObjects(options.parameters,
drag.getParameters());");
definition.addToBody("var dzOptions = this.getDropzoneOptions(); if
(dzOptions.ondrop) { if (!dzOptions.ondrop.call(this, event)) return; };");
JSFunction dropFunction = AjaxRendererUtils.buildAjaxFunction(component, context);