Author: abelevich
Date: 2010-11-29 13:25:10 -0500 (Mon, 29 Nov 2010)
New Revision: 20210
Added:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/tag/
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/tag/DropBehaviorRule.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/java/org/richfaces/view/facelets/DropBehaviorHandler.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:
fix attributes names, add provide support for the ajax behavior attributes, implement
DropBehaviorRule,
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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DragBehavior.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -41,7 +41,7 @@
public static final String BEHAVIOR_ID =
"org.richfaces.component.behavior.DragBehavior";
enum PropertyKeys {
- type, indicator, dragValue;
+ type, dragIndicator, dragValue;
}
public void setDragValue(Object dragValue) {
@@ -49,15 +49,15 @@
}
public Object getDragValue() {
- return getStateHelper().get(PropertyKeys.dragValue);
+ return getStateHelper().eval(PropertyKeys.dragValue);
}
- public void setIndicator(String indicator) {
- getStateHelper().put(PropertyKeys.indicator, indicator);
+ public void setDragIndicator(String indicator) {
+ getStateHelper().put(PropertyKeys.dragIndicator, indicator);
}
- public String getIndicator() {
- return (String)getStateHelper().get(PropertyKeys.indicator);
+ public String getDragIndicator() {
+ return (String)getStateHelper().eval(PropertyKeys.dragIndicator);
}
public void setType(String type) {
@@ -72,8 +72,8 @@
public void setLiteralAttribute(String name, Object value) {
if(compare(PropertyKeys.type, name)) {
setType((String)value);
- } else if(compare(PropertyKeys.indicator, name)){
- setIndicator((String)value);
+ } else if(compare(PropertyKeys.dragIndicator, name)){
+ setDragIndicator((String)value);
} else if(compare(PropertyKeys.dragValue, name)) {
setDragValue(value);
}
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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/component/behavior/DropBehavior.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -25,7 +25,8 @@
import java.util.Set;
-import org.ajax4jsf.component.behavior.ClientBehavior;
+
+import org.ajax4jsf.component.behavior.AjaxBehavior;
import org.richfaces.cdk.annotations.JsfBehavior;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
@@ -40,12 +41,12 @@
@JsfBehavior(
id = DropBehavior.BEHAVIOR_ID, tag = @Tag(name = "dropBehavior", handler =
"org.richfaces.view.facelets.DropBehaviorHandler", type = TagType.Facelets)
)
-public class DropBehavior extends ClientBehavior implements ClientDropBehavior {
+public class DropBehavior extends AjaxBehavior implements ClientDropBehavior {
public static final String BEHAVIOR_ID =
"org.richfaces.component.behavior.DropBehavior";
enum PropertyKeys {
- acceptType, dropValue
+ acceptedTypes, dropValue
}
public void setDropValue(Object dropValue) {
@@ -53,15 +54,15 @@
}
public Object getDropValue() {
- return getStateHelper().get(PropertyKeys.dropValue);
+ return getStateHelper().eval(PropertyKeys.dropValue);
}
- public void setAcceptType(Set<String> acceptType) {
- getStateHelper().put(PropertyKeys.acceptType, acceptType);
+ public void setAcceptedTypes(Set<String> acceptType) {
+ getStateHelper().put(PropertyKeys.acceptedTypes, acceptType);
}
- public Set<String> getAcceptType() {
- return (Set<String>)getStateHelper().eval(PropertyKeys.acceptType);
+ public Set<String> getAcceptedTypes() {
+ return (Set<String>)getStateHelper().eval(PropertyKeys.acceptedTypes);
}
public void addDropListener(DropListener listener) {
@@ -71,16 +72,17 @@
public void removeDropListener(DropListener listener) {
removeBehaviorListener(listener);
}
-
+
@Override
public void setLiteralAttribute(String name, Object value) {
- if(compare(PropertyKeys.acceptType, name)) {
- setAcceptType(CoreAjaxRendererUtils.asSimpleSet(value));
+ super.setLiteralAttribute(name, value);
+ if(compare(PropertyKeys.acceptedTypes, name)) {
+ setAcceptedTypes(CoreAjaxRendererUtils.asSimpleSet(value));
} else if(compare(PropertyKeys.dropValue, name)) {
setDropValue(value);
}
}
-
+
@Override
public String getRendererType() {
return BEHAVIOR_ID;
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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -71,7 +71,7 @@
}
public String getDragIndicatorClientId(ClientBehaviorContext clientBehaviorContext,
ClientDragBehavior dragBehavior) {
- String indicatorId = dragBehavior.getIndicator();
+ String indicatorId = dragBehavior.getDragIndicator();
if(indicatorId != null) {
FacesContext facesContext = clientBehaviorContext.getFacesContext();
UIComponent clientBehaviorHolder = clientBehaviorContext.getComponent();
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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -30,12 +30,15 @@
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
+import javax.faces.component.ActionSource;
import javax.faces.component.ContextCallback;
+import javax.faces.component.EditableValueHolder;
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.event.PhaseId;
import javax.faces.render.FacesBehaviorRenderer;
import javax.faces.render.RenderKitFactory;
@@ -55,6 +58,7 @@
@ResourceDependencies({
@ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "jquery.position.js"),
@ResourceDependency(name = "richfaces.js"),
@ResourceDependency(name = "richfaces.js"),
@ResourceDependency(library = "org.richfaces", name =
"jquery-ui-core.js"),
@@ -85,7 +89,7 @@
if(behavior instanceof ClientDropBehavior) {
ClientDropBehavior dropBehavior = (ClientDropBehavior)behavior;
- options.put("acceptType", dropBehavior.getAcceptType());
+ options.put("acceptedTypes", dropBehavior.getAcceptedTypes());
}
return options;
@@ -104,19 +108,52 @@
public void invokeContextCallback(FacesContext context, UIComponent target) {
ClientDragBehavior dragBehavior = getDragBehavior(target,
"mouseover");
-
if(dragBehavior != null) {
DropEvent dropEvent = new DropEvent(dropSource, dropBehavior);
dropEvent.setDragSource(target);
dropEvent.setDragValue(dragBehavior.getDragValue());
dropEvent.setDropValue(dropBehavior.getDropValue());
- dropEvent.setAcceptType(dropBehavior.getAcceptType());
- dropEvent.queue();
+ dropEvent.setAcceptedTypes(dropBehavior.getAcceptedTypes());
+ queueDropEvent(dropEvent);
} else {
//TODO: log
}
}
+ private void queueDropEvent(DropEvent event) {
+ PhaseId phaseId = PhaseId.INVOKE_APPLICATION;
+
+ if (isImmediate()) {
+ phaseId = PhaseId.APPLY_REQUEST_VALUES;
+ } else if (isBypassUpdates()) {
+ phaseId = PhaseId.PROCESS_VALIDATIONS;
+ }
+
+ event.setPhaseId(phaseId);
+ this.dropSource.queueEvent(event);
+ }
+
+ private boolean isImmediate(){
+ boolean immediate = this.dropBehavior.isImmediate();
+ if(!immediate) {
+ if (dropSource instanceof EditableValueHolder) {
+ immediate = ((EditableValueHolder) dropSource).isImmediate();
+ } else if (dropSource instanceof ActionSource) {
+ immediate = ((ActionSource) dropSource).isImmediate();
+ }
+ }
+
+ return immediate;
+ }
+
+ private boolean isBypassUpdates(){
+ boolean bypassUpdates = this.dropBehavior.isBypassUpdates();
+ if (!bypassUpdates) {
+ bypassUpdates = getUtils().isBooleanAttribute(this.dropSource,
"bypassUpdates");
+ }
+ return bypassUpdates;
+ }
+
private ClientDragBehavior getDragBehavior(UIComponent parent, String event) {
if(parent instanceof ClientBehaviorHolder) {
Map<String, List<ClientBehavior>> behaviorsMap =
((ClientBehaviorHolder)parent).getClientBehaviors();
Modified:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java 2010-11-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -23,16 +23,10 @@
package org.richfaces.view.facelets;
import javax.faces.view.facelets.BehaviorConfig;
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.MetaRule;
import javax.faces.view.facelets.MetaRuleset;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-import org.richfaces.component.behavior.ClientDropBehavior;
-import org.richfaces.event.MethodExpressionDropListener;
import org.richfaces.view.facelets.html.CustomBehaviorHandler;
+import org.richfaces.view.facelets.tag.DropBehaviorRule;
/**
* @author abelevich
@@ -40,7 +34,7 @@
*/
public class DropBehaviorHandler extends CustomBehaviorHandler{
- private static final DropBehaviorMetaRule METARULE = new DropBehaviorMetaRule();
+ private static final DropBehaviorRule METARULE = new DropBehaviorRule();
public DropBehaviorHandler(BehaviorConfig config) {
super(config);
@@ -51,29 +45,4 @@
m.addRule(METARULE);
return m;
}
-
- static class DropBehaviorMetaRule extends MetaRule {
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
- if (meta.isTargetInstanceOf(ClientDropBehavior.class) &&
"dropListener".equals(name)) {
- return new DropBehaviorMapper(attribute);
- }
- return null;
- }
- }
-
- static class DropBehaviorMapper extends Metadata {
-
- private static final Class[] SIGNATURE = new Class[] {
org.richfaces.event.DropEvent.class };
-
- private final TagAttribute attribute;
-
- public DropBehaviorMapper(TagAttribute attribute) {
- this.attribute = attribute;
- }
-
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((ClientDropBehavior) instance).addDropListener((new
MethodExpressionDropListener( this.attribute.getMethodExpression(ctx, null,
SIGNATURE))));
- }
- }
-
}
Added:
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/tag/DropBehaviorRule.java
===================================================================
---
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/tag/DropBehaviorRule.java
(rev 0)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/java/org/richfaces/view/facelets/tag/DropBehaviorRule.java 2010-11-29
18:25:10 UTC (rev 20210)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+
+package org.richfaces.view.facelets.tag;
+
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.behavior.ClientDropBehavior;
+import org.richfaces.event.MethodExpressionDropListener;
+
+/**
+ * @author abelevich
+ *
+ */
+public class DropBehaviorRule extends BehaviorRule {
+
+ public static final String EXECUTE = "execute";
+
+ public static final String RENDER = "render";
+
+ public static final String LISTENER = "listener";
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
{
+ if (meta.isTargetInstanceOf(ClientDropBehavior.class)) {
+ if (!attribute.isLiteral()) {
+ if(LISTENER.equals(name)) {
+ return new DropBehaviorMapper(attribute);
+ }
+
+ Class<?> type = meta.getPropertyType(name);
+
+ if (EXECUTE.equals(name) || RENDER.equals(name)) {
+ type = Object.class;
+ }
+
+ if (type == null) {
+ type = Object.class;
+ }
+
+ return new ValueExpressionMetadata(name, type, attribute);
+
+ } else if(meta != null && meta.getWriteMethod(name) != null) {
+ return new LiteralAttributeMetadata(name, attribute.getValue());
+ }
+ }
+ return null;
+ }
+
+ static class DropBehaviorMapper extends Metadata {
+
+ private static final Class[] SIGNATURE = new Class[] {
org.richfaces.event.DropEvent.class };
+
+ private final TagAttribute attribute;
+
+ public DropBehaviorMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((ClientDropBehavior) instance).addDropListener((new
MethodExpressionDropListener( this.attribute.getMethodExpression(ctx, null,
SIGNATURE))));
+ }
+ }
+
+}
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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js 2010-11-29
18:25:10 UTC (rev 20210)
@@ -4,7 +4,7 @@
rf.ui.Draggable = function(id, options) {
this.dragElement = $(document.getElementById(id));
- this.dragElement.draggable({addClasses: false});
+ this.dragElement.draggable({addClasses: false, appendTo: 'body'});
if(options.indicator) {
var element = document.getElementById(options.indicator);
@@ -30,10 +30,13 @@
$.extend(rf.ui.Draggable.prototype, ( function () {
return {
dragStart: function(e, ui) {
- if(ui.helper && this.indicator) {
- ui.helper.show();
+ if(ui.helper) {
+ var element = ui.helper[0];
+ this.parentElement = element.parentNode;
+ ui.helper.detach().appendTo("body");
+ ui.helper.setPosition(e).show();
}
- },
+ },
drag: function(e, ui) {
var helper = ui.helper;
@@ -43,14 +46,14 @@
},
dragStop: function(e, ui){
- if(ui.helper && this.indicator) {
+ if(ui.helper) {
ui.helper.hide();
+ ui.helper.detach().appendTo(this.parentElement);
+ if(ui.helper[0] != this.dragElement[0]) {
+ //fix to prevent remove custom indicator from DOM tree. see jQuery
draggable._clear method for details
+ ui.helper[0] = this.dragElement[0];
+ }
}
-
- if(ui.helper[0] != this.dragElement[0]) {
- //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-29
18:16:44 UTC (rev 20209)
+++
sandbox/trunk/ui/drag-drop/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js 2010-11-29
18:25:10 UTC (rev 20210)
@@ -56,7 +56,7 @@
var accept;
var acceptType = draggable.data("type");
if(acceptType) {
- $.each(this.options.acceptType, function() {
+ $.each(this.options.acceptedTypes, function() {
accept = (acceptType == this); return !(accept);
});
}