Author: abelevich
Date: 2010-11-25 11:13:23 -0500 (Thu, 25 Nov 2010)
New Revision: 20173
Added:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/AbstractDragIndicator.java
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DragBehavior.java
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DropBehavior.java
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js
Log:
add indicator, implement drop server decode and dropEvent creation
Added:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/AbstractDragIndicator.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/AbstractDragIndicator.java
(rev 0)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/AbstractDragIndicator.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -0,0 +1,35 @@
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+
+@JsfComponent(
+ type = AbstractDragIndicator.COMPONENT_TYPE,
+ family = AbstractDragIndicator.COMPONENT_FAMILY,
+ generate = "org.richfaces.component.UIDragIndicator",
+ renderer = @JsfRenderer(type = "org.richfaces.DragIndicatorRenderer"),
+ tag = @Tag(name="dragIndicator")
+)
+public abstract class AbstractDragIndicator extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.DragIndicator";
+
+ public static final String COMPONENT_FAMILY =
"org.richfaces.DragIndicator";
+
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Attribute
+ public abstract String getAcceptClass();
+
+ @Attribute
+ public abstract String getRejectClass();
+
+ @Attribute
+ public abstract String getDraggingClass();
+}
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DragBehavior.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DragBehavior.java 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DragBehavior.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -36,15 +36,22 @@
@JsfBehavior(
id = DragBehavior.BEHAVIOR_ID, tag = @Tag(name = "dragBehavior", handler =
"org.richfaces.view.facelets.html.CustomBehaviorHandler", type =
TagType.Facelets)
)
-public class DragBehavior extends ClientBehavior {
+public class DragBehavior extends ClientBehavior implements ClientDragBehavior {
public static final String BEHAVIOR_ID =
"org.richfaces.component.behavior.DragBehavior";
enum PropertyKeys {
- type, indicator;
+ type, indicator, dragValue;
}
+ public void setDragValue(Object dragValue) {
+ getStateHelper().put(PropertyKeys.dragValue, dragValue);
+ }
+ public Object getDragValue() {
+ return getStateHelper().get(PropertyKeys.dragValue);
+ }
+
public void setIndicator(String indicator) {
getStateHelper().put(PropertyKeys.indicator, indicator);
}
@@ -67,6 +74,8 @@
setType((String)value);
} else if(compare(PropertyKeys.indicator, name)){
setIndicator((String)value);
+ } else if(compare(PropertyKeys.dragValue, name)) {
+ setDragValue(value);
}
}
@@ -78,5 +87,4 @@
public String getRendererType() {
return BEHAVIOR_ID;
}
-
}
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DropBehavior.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DropBehavior.java 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DropBehavior.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -39,14 +39,22 @@
@JsfBehavior(
id = DropBehavior.BEHAVIOR_ID, tag = @Tag(name = "dropBehavior", handler =
"org.richfaces.view.facelets.html.CustomBehaviorHandler", type =
TagType.Facelets)
)
-public class DropBehavior extends ClientBehavior {
+public class DropBehavior extends ClientBehavior implements ClientDropBehavior {
public static final String BEHAVIOR_ID =
"org.richfaces.component.behavior.DropBehavior";
enum PropertyKeys {
- acceptType
+ acceptType, dropValue
}
+ public void setDropValue(Object dropValue) {
+ getStateHelper().put(PropertyKeys.dropValue, dropValue);
+ }
+
+ public Object getDropValue() {
+ return getStateHelper().get(PropertyKeys.dropValue);
+ }
+
public void setAcceptType(Set<String> acceptType) {
getStateHelper().put(PropertyKeys.acceptType, acceptType);
}
@@ -59,7 +67,9 @@
public void setLiteralAttribute(String name, Object value) {
if(compare(PropertyKeys.acceptType, name)) {
setAcceptType(CoreAjaxRendererUtils.asSimpleSet(value));
- }
+ } else if(compare(PropertyKeys.dropValue, name)) {
+ setDropValue(value);
+ }
}
@Override
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -37,6 +37,7 @@
import org.ajax4jsf.javascript.JSFunction;
import org.richfaces.component.behavior.DragBehavior;
+import org.richfaces.component.behavior.ClientDragBehavior;
import org.richfaces.renderkit.util.RendererUtils;
/**
@@ -70,19 +71,16 @@
public Map<String, Object> getOptions(ClientBehaviorContext
clientBehaviorContext, ClientBehavior behavior) {
Map<String, Object> options = new HashMap<String, Object>();
-
- if(behavior instanceof DragBehavior) {
- DragBehavior dragBehavior = (DragBehavior)behavior;
+ if(behavior instanceof ClientDragBehavior) {
+ ClientDragBehavior dragBehavior = (ClientDragBehavior)behavior;
options.put("indicator",
getDragIndicatorClientId(clientBehaviorContext, dragBehavior));
options.put("type", dragBehavior.getType());
}
-
return options;
}
- public String getDragIndicatorClientId(ClientBehaviorContext clientBehaviorContext,
DragBehavior dragBehavior) {
+ public String getDragIndicatorClientId(ClientBehaviorContext clientBehaviorContext,
ClientDragBehavior dragBehavior) {
String indicatorId = dragBehavior.getIndicator();
-
if(indicatorId != null) {
FacesContext facesContext = clientBehaviorContext.getFacesContext();
UIComponent clientBehaviorHolder = clientBehaviorContext.getComponent();
@@ -91,9 +89,7 @@
if(indicator != null) {
indicatorId = indicator.getClientId(facesContext);
}
-
}
-
return indicatorId;
}
Added:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
(rev 0)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -0,0 +1,15 @@
+package org.richfaces.renderkit;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+
+
+@ResourceDependencies({
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "richfaces-base-component.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"dnd-indicator.js"),
+ @ResourceDependency(library = "org.richfaces", name =
"indicator.ecss") })
+public class DragIndicatorRendererBase extends RendererBase {
+}
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java 2010-11-25
16:13:23 UTC (rev 20173)
@@ -23,20 +23,30 @@
package org.richfaces.renderkit;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
+import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.faces.context.FacesContext;
import javax.faces.render.ClientBehaviorRenderer;
import javax.faces.render.FacesBehaviorRenderer;
import javax.faces.render.RenderKitFactory;
import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.component.behavior.ClientDragBehavior;
+import org.richfaces.component.behavior.ClientDropBehavior;
import org.richfaces.component.behavior.DropBehavior;
+import org.richfaces.event.DropBehaviorEvent;
+
/**
* @author abelevich
*
@@ -57,6 +67,20 @@
public class DropBehaviorRendererBase extends ClientBehaviorRenderer {
@Override
+ public void decode(FacesContext facesContext, UIComponent component, ClientBehavior
behavior) {
+ if (null == facesContext || null == component || behavior == null) {
+ throw new NullPointerException();
+ }
+
+ String clientId = component.getClientId(facesContext);
+ Map<String, String> requestParamMap =
facesContext.getExternalContext().getRequestParameterMap();
+ if(clientId.equals(requestParamMap.containsKey("dropSource"))) {
+ String dragSource = (String) requestParamMap.get("dragSource");
+ facesContext.getViewRoot().invokeOnComponent(facesContext, dragSource, new
DropBehaviorContextCallBack(component, (ClientDropBehavior)behavior));
+ }
+ }
+
+ @Override
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
UIComponent parent = behaviorContext.getComponent();
JSFunction function = new
JSFunction("RichFaces.ui.DnDManager.droppable");
@@ -68,12 +92,59 @@
public Map<String, Object> getOptions(ClientBehaviorContext behaviorContext,
ClientBehavior behavior) {
Map<String, Object> options = new HashMap<String, Object>();
- if(behavior instanceof DropBehavior) {
- DropBehavior dropBehavior = (DropBehavior)behavior;
+ if(behavior instanceof ClientDropBehavior) {
+ ClientDropBehavior dropBehavior = (ClientDropBehavior)behavior;
options.put("acceptType", dropBehavior.getAcceptType());
}
return options;
}
-
+
+ private final class DropBehaviorContextCallBack implements ContextCallback {
+
+ private ClientDropBehavior dropBehavior;
+
+ private UIComponent dropSource;
+
+ public DropBehaviorContextCallBack(UIComponent dropSource, ClientDropBehavior
dropBehavior) {
+ this.dropSource = dropSource;
+ this.dropBehavior = dropBehavior;
+ }
+
+ public void invokeContextCallback(FacesContext context, UIComponent target) {
+ ClientDragBehavior dragBehavior = getDragBehavior(target,
"mouseover");
+
+ if(dragBehavior != null) {
+ DropBehaviorEvent dropEvent = new DropBehaviorEvent(dropSource,
dropBehavior);
+ dropEvent.setDragSource(target);
+ dropEvent.setDragValue(dragBehavior.getDragValue());
+ dropEvent.setDropValue(dropBehavior.getDropValue());
+ dropEvent.queue();
+ } else {
+ //TODO: log
+ }
+ }
+
+ private ClientDragBehavior getDragBehavior(UIComponent parent, String event) {
+ if(parent instanceof ClientBehaviorHolder) {
+ Map<String, List<ClientBehavior>> behaviorsMap =
((ClientBehaviorHolder)parent).getClientBehaviors();
+ Set<Map.Entry<String, List<ClientBehavior>>> entries =
behaviorsMap.entrySet();
+
+ for(Entry<String, List<ClientBehavior>> entry: entries) {
+ if(event.equals(entry.getKey())){
+ List<ClientBehavior> behaviors = entry.getValue();
+ for(ClientBehavior behavior: behaviors) {
+ if(behavior instanceof ClientDragBehavior) {
+ return (ClientDragBehavior)behavior;
+ }
+ }
+ }
+ }
+
+ }
+ return null;
+ }
+
+ }
+
}
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js 2010-11-25
16:13:23 UTC (rev 20173)
@@ -15,9 +15,8 @@
}
this.options = options;
-
+
this.dragElement.data('type', this.options.type);
- this.dragElement.data('indicator', this.indicator);
this.dragElement.data("init", true);
this.dragElement.bind('dragstart', $.proxy(this.dragStart, this));
@@ -49,7 +48,7 @@
}
if(ui.helper[0] != this.dragElement[0]) {
- //ugly fix to prevent remove custom indicator from DOM tree. see jQuery
draggable._clear method for details
+ //fix to prevent remove custom indicator from DOM tree. see jQuery draggable._clear
method for details
ui.helper[0] = this.dragElement[0];
}
}
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js 2010-11-25
16:11:55 UTC (rev 20172)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js 2010-11-25
16:13:23 UTC (rev 20173)
@@ -18,13 +18,13 @@
$.extend(rf.ui.Droppable.prototype, ( function () {
return {
drop: function(e, ui) {
- var dragElement = ui.draggable;
var helper = ui.helper;
var indicator = rf.$(helper.attr("id"));
if(indicator) {
helper.removeClass(indicator.acceptClass());
helper.removeClass(indicator.rejectClass());
}
+ this.__callAjax(e, ui);
},
dropover: function(event, ui) {
@@ -60,8 +60,16 @@
accept = (acceptType == this); return !(accept);
});
}
-
return accept;
+ },
+
+ __callAjax: function(e, ui){
+ var options = {};
+ if(ui.draggable) {
+ options['dragSource'] = ui.draggable.attr("id");
+ options['dropSource'] = this.dropElement.attr("id");
+ }
+ rf.ajax(this.dropElement[0], e, {parameters: options});
}
}
})());