Author: abelevich
Date: 2010-12-17 14:57:18 -0500 (Fri, 17 Dec 2010)
New Revision: 20669
Added:
trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDragSource.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDropTarget.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/event/
trunk/ui/dnd/ui/src/main/java/org/richfaces/event/MethodExpressionDropListener.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/
trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DnDScript.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DragScript.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DropScript.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDRenderBase.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragSourceRenderer.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropTargetRenderer.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropHandler.java
Removed:
trunk/ui/dnd/ui/src/main/java/org/richfaces/component/behavior/
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDBehaviorRenderBase.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/tag/
Modified:
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js
Log:
redesign dnd behaviors to dnd components
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDragSource.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDragSource.java
(rev 0)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDragSource.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,61 @@
+/*
+ * 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.component;
+
+import javax.faces.component.UIComponentBase;
+
+import org.ajax4jsf.component.AjaxComponent;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author abelevich
+ *
+ */
+
+@JsfComponent(
+ type = AbstractDragSource.COMPONENT_TYPE,
+ family = AbstractDragSource.COMPONENT_FAMILY,
+ generate = "org.richfaces.component.UIDragSource",
+ renderer = @JsfRenderer(type = "org.richfaces.DragSourceRenderer"),
+ tag = @Tag(name="dragSource")
+)
+public abstract class AbstractDragSource extends UIComponentBase implements AjaxComponent
{
+
+ public static final String COMPONENT_TYPE = "org.richfaces.DragSource";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.DragSource";
+
+
+ @Attribute
+ public abstract String getDragIndicator();
+
+ @Attribute
+ public abstract String getType();
+
+ @Attribute
+ public abstract Object getDragValue();
+
+}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDropTarget.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDropTarget.java
(rev 0)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/component/AbstractDropTarget.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,75 @@
+/*
+ * 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.component;
+
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.event.DropEvent;
+import org.richfaces.event.DropListener;
+
+/**
+ * @author abelevich
+ *
+ */
+
+@JsfComponent(
+ type = AbstractDropTarget.COMPONENT_TYPE,
+ family = AbstractDropTarget.COMPONENT_FAMILY,
+ generate = "org.richfaces.component.UIDropTarget",
+ renderer = @JsfRenderer(type = "org.richfaces.DropTargetRenderer"),
+ tag = @Tag(name="dropTarget"
,handler="org.richfaces.view.facelets.DropHandler", type = TagType.Facelets)
+)
+public abstract class AbstractDropTarget extends AbstractActionComponent {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.DropTarget";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.DropTarget";
+
+
+ @Attribute
+ public abstract Object getDropValue();
+
+ public abstract Object getAcceptedTypes();
+
+ public void addDropListener(DropListener listener) {
+ addFacesListener(listener);
+ }
+
+ public void removeDropListener(DropListener listener) {
+ removeFacesListener(listener);
+ }
+
+ @Override
+ public void queueEvent(FacesEvent event) {
+ if(event instanceof DropEvent) {
+ event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ }
+ super.queueEvent(event);
+ }
+}
Added:
trunk/ui/dnd/ui/src/main/java/org/richfaces/event/MethodExpressionDropListener.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/event/MethodExpressionDropListener.java
(rev 0)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/event/MethodExpressionDropListener.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,49 @@
+/*
+ * 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.event;
+
+import javax.el.MethodExpression;
+import javax.faces.context.FacesContext;
+
+
+/**
+ * @author abelevich
+ *
+ */
+public class MethodExpressionDropListener implements DropListener {
+ private MethodExpression methodExpression;
+
+ public MethodExpressionDropListener() {
+ super();
+ }
+
+ public MethodExpressionDropListener(MethodExpression methodExpression) {
+ super();
+ this.methodExpression = methodExpression;
+ }
+
+ public void processDrop(DropEvent event) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ methodExpression.invoke(facesContext.getELContext(), new Object[] { event });
+ }
+}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DnDScript.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DnDScript.java
(rev 0)
+++ trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DnDScript.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,83 @@
+package org.richfaces.javascript;
+
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.ajax4jsf.javascript.ScriptWithDependencies;
+import org.richfaces.resource.ResourceKey;
+
+public abstract class DnDScript implements ScriptWithDependencies {
+
+ private static final Set<ResourceKey> BASE_RESOURCES = new
LinkedHashSet<ResourceKey>();
+
+ static {
+ BASE_RESOURCES.add(new ResourceKey("jquery.js", null));
+ BASE_RESOURCES.add(new ResourceKey("jquery.position.js", null));
+ BASE_RESOURCES.add(new ResourceKey("richfaces.js", null));
+ BASE_RESOURCES.add(new ResourceKey("jquery-ui-core.js",
"org.richfaces"));
+ BASE_RESOURCES.add(new ResourceKey("jquery-dnd.js",
"org.richfaces"));
+ }
+
+ private final String name;
+
+ public DnDScript(String name) {
+ this.name = name;
+ }
+
+ public Set<ResourceKey> getBaseResources() {
+ return BASE_RESOURCES;
+ }
+
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ public String toScript() {
+ return name;
+ }
+
+ public void appendScript(Appendable target) throws IOException {
+ target.append(name);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ DnDScript other = (DnDScript) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DragScript.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DragScript.java
(rev 0)
+++ trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DragScript.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,24 @@
+package org.richfaces.javascript;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.richfaces.resource.ResourceKey;
+
+public final class DragScript extends DnDScript{
+
+ private static final Set<ResourceKey> DRAG_SCRIPT = Collections.singleton(new
ResourceKey("dnd-draggable.js", "org.richfaces"));
+
+ public DragScript(String name) {
+ super(name);
+ }
+
+ public Iterable<ResourceKey> getResources() {
+ Set<ResourceKey> dragResourceKeys = new
LinkedHashSet<ResourceKey>();
+ dragResourceKeys.addAll(getBaseResources());
+ dragResourceKeys.addAll(DRAG_SCRIPT);
+ return dragResourceKeys;
+ }
+
+}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DropScript.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DropScript.java
(rev 0)
+++ trunk/ui/dnd/ui/src/main/java/org/richfaces/javascript/DropScript.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,24 @@
+package org.richfaces.javascript;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.richfaces.resource.ResourceKey;
+
+public final class DropScript extends DnDScript{
+
+ private static final Set<ResourceKey> DRAG_SCRIPT = Collections.singleton(new
ResourceKey("dnd-droppable.js", "org.richfaces"));
+
+ public DropScript(String name) {
+ super(name);
+ }
+
+ public Iterable<ResourceKey> getResources() {
+ Set<ResourceKey> dragResourceKeys = new
LinkedHashSet<ResourceKey>();
+ dragResourceKeys.addAll(getBaseResources());
+ dragResourceKeys.addAll(DRAG_SCRIPT);
+ return dragResourceKeys;
+ }
+
+}
Deleted: trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDBehaviorRenderBase.java
===================================================================
---
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDBehaviorRenderBase.java 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDBehaviorRenderBase.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -1,67 +0,0 @@
-/*
- * 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.renderkit;
-
-import java.util.Map;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.render.ClientBehaviorRenderer;
-
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.JSReference;
-import org.richfaces.renderkit.util.RendererUtils;
-
-/**
- * @author abelevich
- *
- */
-public abstract class DnDBehaviorRenderBase extends ClientBehaviorRenderer {
-
- private static final RendererUtils UTILS = RendererUtils.getInstance();
-
-
- protected abstract Map<String, Object> getOptions(ClientBehaviorContext
behaviorContext, ClientBehavior clientBehavior);
-
- protected abstract String getScriptName();
-
- public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
- UIComponent parent = behaviorContext.getComponent();
- String scriptName = getScriptName();
- String script = null;
- if(!"".equals(scriptName)) {
- JSFunction function = new JSFunction(scriptName);
- function.addParameter(JSReference.EVENT);
-
function.addParameter(parent.getClientId(behaviorContext.getFacesContext()));
- function.addParameter(getOptions(behaviorContext, behavior));
- script = function.toScript();
- }
- return script;
- }
-
- public RendererUtils getUtils() {
- return UTILS;
- }
-
-}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDRenderBase.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDRenderBase.java
(rev 0)
+++ trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DnDRenderBase.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,57 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.javascript.DnDScript;
+import org.richfaces.javascript.JavaScriptService;
+
+
+/**
+ * @author abelevich
+ *
+ */
+public abstract class DnDRenderBase extends RendererBase{
+
+ public void buildAndStoreScript(FacesContext facesContext, UIComponent component) {
+ JavaScriptService javaScriptService =
ServiceTracker.getService(JavaScriptService.class);
+ DnDScript dragScript = buildClientScript(facesContext, component);
+ if(javaScriptService != null && dragScript != null) {
+ javaScriptService.addPageReadyScript(facesContext, dragScript);
+ }
+ }
+
+ public abstract Map<String, Object> getOptions(FacesContext facesContext,
UIComponent component);
+
+ public abstract String getScriptName();
+
+ public abstract DnDScript createScript(String name);
+
+ public String getParentClientId(FacesContext facesContext, UIComponent component) {
+ UIComponent parent = component.getParent();
+ return (parent != null) ? parent.getClientId(facesContext) : "";
+ }
+
+ private DnDScript buildClientScript(FacesContext facesContext, UIComponent component)
{
+ DnDScript script = null;
+ String scriptName = getScriptName();
+ if(!"".equals(scriptName)) {
+ JSFunction function = new JSFunction(scriptName);
+ function.addParameter(component.getClientId(facesContext));
+ function.addParameter(getOptions(facesContext, component));
+ script = createScript(function.toScript());
+ }
+ return script;
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ buildAndStoreScript(context, component);
+ }
+}
Deleted:
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java
===================================================================
---
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragBehaviorRendererBase.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -1,86 +0,0 @@
-/*
- * 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.renderkit;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.component.behavior.ClientBehavior;
-import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.context.FacesContext;
-import javax.faces.render.FacesBehaviorRenderer;
-import javax.faces.render.RenderKitFactory;
-
-import org.richfaces.component.behavior.ClientDragBehavior;
-import org.richfaces.component.behavior.DragBehavior;
-
-/**
- * @author abelevich
- *
- */
-
-
-@FacesBehaviorRenderer(rendererType = DragBehavior.BEHAVIOR_ID, renderKitId =
RenderKitFactory.HTML_BASIC_RENDER_KIT)
-
-@ResourceDependencies({
- @ResourceDependency(name = "jquery.js"),
- @ResourceDependency(name = "richfaces.js"),
- @ResourceDependency(library = "org.richfaces", name =
"jquery-ui-core.js"),
- @ResourceDependency(library = "org.richfaces", name =
"jquery-dnd.js"),
- @ResourceDependency(library = "org.richfaces", name =
"dnd-draggable.js"),
- @ResourceDependency(library = "org.richfaces", name =
"dnd-manager.js")
-})
-public class DragBehaviorRendererBase extends DnDBehaviorRenderBase {
-
- public Map<String, Object> getOptions(ClientBehaviorContext
clientBehaviorContext, ClientBehavior behavior) {
- Map<String, Object> options = new HashMap<String, Object>();
- if(behavior instanceof ClientDragBehavior) {
- ClientDragBehavior dragBehavior = (ClientDragBehavior)behavior;
- options.put("indicator",
getDragIndicatorClientId(clientBehaviorContext, dragBehavior));
- options.put("type", dragBehavior.getType());
- }
- return options;
- }
-
- @Override
- protected String getScriptName() {
- return "RichFaces.ui.DnDManager.draggable";
- }
-
- public String getDragIndicatorClientId(ClientBehaviorContext clientBehaviorContext,
ClientDragBehavior dragBehavior) {
- String indicatorId = dragBehavior.getDragIndicator();
- if(indicatorId != null) {
- FacesContext facesContext = clientBehaviorContext.getFacesContext();
- UIComponent clientBehaviorHolder = clientBehaviorContext.getComponent();
- UIComponent indicator = getUtils().findComponentFor(facesContext,
clientBehaviorHolder, indicatorId);
-
- if(indicator != null) {
- indicatorId = indicator.getClientId(facesContext);
- }
- }
- return indicatorId;
- }
-}
Modified:
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java
===================================================================
---
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragIndicatorRendererBase.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -24,8 +24,12 @@
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import org.richfaces.component.AbstractDragSource;
+
/**
* @author abelevich
*
@@ -39,4 +43,16 @@
@ResourceDependency(library = "org.richfaces", name =
"dnd-indicator.js"),
@ResourceDependency(library = "org.richfaces", name =
"indicator.ecss") })
public class DragIndicatorRendererBase extends RendererBase {
+
+
+ public String getDragIndicatorClientId(FacesContext facesContext, AbstractDragSource
dragSource) {
+ String indicatorId = dragSource.getDragIndicator();
+ if(!"".equals(indicatorId)) {
+ UIComponent indicator = getUtils().findComponentFor(facesContext, dragSource,
indicatorId);
+ if(indicator != null) {
+ indicatorId = indicator.getClientId(facesContext);
+ }
+ }
+ return indicatorId;
+ }
}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragSourceRenderer.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragSourceRenderer.java
(rev 0)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DragSourceRenderer.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,55 @@
+package org.richfaces.renderkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractDragSource;
+import org.richfaces.javascript.DnDScript;
+import org.richfaces.javascript.DragScript;
+
+/**
+ * @author abelevich
+ *
+ */
+
+@JsfRenderer(type = "org.richfaces.DragSourceRenderer", family =
AbstractDragSource.COMPONENT_FAMILY)
+public class DragSourceRenderer extends DnDRenderBase {
+
+ @Override
+ public Map<String, Object> getOptions(FacesContext facesContext, UIComponent
component) {
+ Map<String, Object> options = new HashMap<String, Object>();
+ if(component instanceof AbstractDragSource) {
+ AbstractDragSource dragSource = (AbstractDragSource)component;
+ options.put("indicator", getDragIndicatorClientId(facesContext,
dragSource));
+ options.put("type", dragSource.getType());
+ options.put("parentId", getParentClientId(facesContext,
component));
+ }
+ return options;
+ }
+
+ @Override
+ public String getScriptName() {
+ return "new RichFaces.ui.Draggable";
+ }
+
+ @Override
+ public DnDScript createScript(String name) {
+ return new DragScript(name);
+ }
+
+ public String getDragIndicatorClientId(FacesContext facesContext, AbstractDragSource
dragSource) {
+ String indicatorId = dragSource.getDragIndicator();
+ if(indicatorId != null) {
+ UIComponent indicator = getUtils().findComponentFor(facesContext, dragSource,
indicatorId);
+ if(indicator != null) {
+ indicatorId = indicator.getClientId(facesContext);
+ }
+ }
+ return indicatorId;
+ }
+
+}
Deleted:
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java
===================================================================
---
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropBehaviorRendererBase.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -1,196 +0,0 @@
-/*
- * 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.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.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;
-
-import org.richfaces.component.behavior.ClientDragBehavior;
-import org.richfaces.component.behavior.ClientDropBehavior;
-import org.richfaces.component.behavior.DropBehavior;
-import org.richfaces.event.DropEvent;
-
-
-/**
- * @author abelevich
- *
- */
-
-
-@FacesBehaviorRenderer(rendererType = DropBehavior.BEHAVIOR_ID, renderKitId =
RenderKitFactory.HTML_BASIC_RENDER_KIT)
-
-@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"),
- @ResourceDependency(library = "org.richfaces", name =
"jquery-dnd.js"),
- @ResourceDependency(library = "org.richfaces", name =
"dnd-droppable.js"),
- @ResourceDependency(library = "org.richfaces", name =
"dnd-manager.js")
-})
-public class DropBehaviorRendererBase extends DnDBehaviorRenderBase {
-
- @Override
- public void decode(FacesContext facesContext, UIComponent component, ClientBehavior
behavior) {
- if (null == facesContext || null == component || behavior == null) {
- throw new NullPointerException();
- }
-
- Map<String, String> requestParamMap =
facesContext.getExternalContext().getRequestParameterMap();
- String dragSource = (String) requestParamMap.get("dragSource");
-
- DragBehaviorContextCallBack dragBehaviorContextCallBack = new
DragBehaviorContextCallBack();
- facesContext.getViewRoot().invokeOnComponent(facesContext, dragSource,
dragBehaviorContextCallBack);
-
- if(behavior instanceof ClientDropBehavior) {
- ClientDropBehavior dropBehavior = (ClientDropBehavior)behavior;
- DropEvent dropEvent = new DropEvent(component, dropBehavior);
- dropEvent.setDropValue(dropBehavior.getDropValue());
- dropEvent.setDragComponent(dragBehaviorContextCallBack.getDragComponent());
- dropEvent.setDragBehavior(dragBehaviorContextCallBack.getDragBehavior());
- dropEvent.setDragValue(dragBehaviorContextCallBack.getDragValue());
- queueEvent(dropEvent);
- }
- }
-
- @Override
- protected String getScriptName() {
- return "RichFaces.ui.DnDManager.droppable";
- }
-
- public Map<String, Object> getOptions(ClientBehaviorContext behaviorContext,
ClientBehavior behavior) {
- Map<String, Object> options = new HashMap<String, Object>();
-
- if(behavior instanceof ClientDropBehavior) {
- ClientDropBehavior dropBehavior = (ClientDropBehavior)behavior;
- options.put("acceptedTypes", dropBehavior.getAcceptedTypes());
- }
- return options;
- }
-
- private final class DragBehaviorContextCallBack implements ContextCallback {
-
- private Object dragValue;
-
- private ClientDragBehavior dragBehavior;
-
- private UIComponent dragComponent;
-
- public void invokeContextCallback(FacesContext context, UIComponent target) {
- ClientDragBehavior dragBehavior = getDragBehavior(target,
"mouseover");
- this.dragValue = dragBehavior.getDragValue();
- this.dragBehavior = dragBehavior;
- this.dragComponent = target;
- }
-
- public Object getDragValue() {
- return dragValue;
- }
-
- public ClientDragBehavior getDragBehavior() {
- return dragBehavior;
- }
-
- public UIComponent getDragComponent() {
- return dragComponent;
- }
-
- 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;
- }
-
- }
-
- protected void queueEvent(DropEvent dropEvent){
- UIComponent component = dropEvent.getComponent();
- ClientDropBehavior dropBehavior = dropEvent.getDropBehavior();
-
- if(component != null && dropBehavior != null) {
- PhaseId phaseId = PhaseId.INVOKE_APPLICATION;
-
- if (isImmediate(component, dropBehavior)) {
- phaseId = PhaseId.APPLY_REQUEST_VALUES;
- } else if (isBypassUpdates(component, dropBehavior)) {
- phaseId = PhaseId.PROCESS_VALIDATIONS;
- }
-
- dropEvent.setPhaseId(phaseId);
- component.queueEvent(dropEvent);
- }
- }
-
- private boolean isImmediate(UIComponent component, ClientDropBehavior dropBehavior){
- boolean immediate = dropBehavior.isImmediate();
- if(!immediate) {
- if (component instanceof EditableValueHolder) {
- immediate = ((EditableValueHolder) component).isImmediate();
- } else if (component instanceof ActionSource) {
- immediate = ((ActionSource) component).isImmediate();
- }
- }
- return immediate;
- }
-
- private boolean isBypassUpdates(UIComponent component, ClientDropBehavior
dropBehavior){
- boolean bypassUpdates = dropBehavior.isBypassUpdates();
- if (!bypassUpdates) {
- bypassUpdates = getUtils().isBooleanAttribute(component,
"bypassUpdates");
- }
- return bypassUpdates;
- }
-
-}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropTargetRenderer.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropTargetRenderer.java
(rev 0)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/renderkit/DropTargetRenderer.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,103 @@
+package org.richfaces.renderkit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.component.ContextCallback;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractDragSource;
+import org.richfaces.component.AbstractDropTarget;
+import org.richfaces.event.DropEvent;
+import org.richfaces.javascript.DnDScript;
+import org.richfaces.javascript.DropScript;
+import org.richfaces.renderkit.util.AjaxRendererUtils;
+import org.richfaces.renderkit.util.CoreAjaxRendererUtils;
+
+
+/**
+ * @author abelevich
+ *
+ */
+
+@JsfRenderer(type = "org.richfaces.DropTargetRenderer", family =
AbstractDropTarget.COMPONENT_FAMILY)
+public class DropTargetRenderer extends DnDRenderBase {
+
+ @Override
+ protected void doDecode(FacesContext facesContext, UIComponent component) {
+ if(component instanceof AbstractDropTarget) {
+ Map<String, String> requestParamMap =
facesContext.getExternalContext().getRequestParameterMap();
+ String dragSourceId = (String) requestParamMap.get("dragSource");
+
+ if(!"".equals(dragSourceId)) {
+ DragSourceContextCallBack dragSourceContextCallBack = new
DragSourceContextCallBack();
+ facesContext.getViewRoot().invokeOnComponent(facesContext, dragSourceId,
dragSourceContextCallBack);
+
+ AbstractDropTarget dropTarget = (AbstractDropTarget)component;
+ DropEvent dropEvent = new
DropEvent(dragSourceContextCallBack.getDragSource(), dropTarget);
+ dropEvent.setDragValue(dragSourceContextCallBack.getDragValue());
+ dropEvent.setDropValue(dropTarget.getDropValue());
+ dropEvent.queue();
+ }
+ }
+ }
+
+ private final class DragSourceContextCallBack implements ContextCallback {
+
+ private AbstractDragSource dragSource;
+
+ private Object dragValue;
+
+ public void invokeContextCallback(FacesContext context, UIComponent target) {
+ if(target instanceof AbstractDragSource) {
+ this.dragSource = (AbstractDragSource)target;
+ this.dragValue = this.dragSource.getDragValue();
+ }
+ }
+
+ public AbstractDragSource getDragSource() {
+ return dragSource;
+ }
+
+ public Object getDragValue() {
+ return dragValue;
+ }
+ }
+
+ @Override
+ public DnDScript createScript(String name) {
+ return new DropScript(name);
+ }
+
+ @Override
+ public Map<String, Object> getOptions(FacesContext facesContext, UIComponent
component) {
+ Map<String, Object> options = new HashMap<String, Object>();
+
+ if(component instanceof AbstractDropTarget) {
+ JSReference dragSourceId = new JSReference("dragSourceId");
+ JSFunctionDefinition function = new JSFunctionDefinition(JSReference.EVENT,
dragSourceId);
+
+ AjaxFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(facesContext,
component);
+ ajaxFunction.getOptions().setParameter("dragSource",
dragSourceId);
+ ajaxFunction.setSource(new JSReference("event",
"target"));
+
ajaxFunction.getOptions().setAjaxComponent(component.getClientId(facesContext));
+ function.addToBody(ajaxFunction);
+
+ AbstractDropTarget dropTarget = (AbstractDropTarget)component;
+ options.put("acceptedTypes",
CoreAjaxRendererUtils.asSimpleSet(dropTarget.getAcceptedTypes()));
+ options.put("ajaxFunction", function);
+ options.put("parentId", getParentClientId(facesContext,
component));
+ }
+ return options;
+ }
+
+ @Override
+ public String getScriptName() {
+ return "new RichFaces.ui.Droppable";
+ }
+
+}
Deleted:
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java
===================================================================
---
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropBehaviorHandler.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -1,48 +0,0 @@
-/*
- * 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;
-
-import javax.faces.view.facelets.BehaviorConfig;
-import javax.faces.view.facelets.MetaRuleset;
-
-import org.richfaces.view.facelets.html.CustomBehaviorHandler;
-import org.richfaces.view.facelets.tag.DropBehaviorRule;
-
-/**
- * @author abelevich
- *
- */
-public class DropBehaviorHandler extends CustomBehaviorHandler{
-
- private static final DropBehaviorRule METARULE = new DropBehaviorRule();
-
- public DropBehaviorHandler(BehaviorConfig config) {
- super(config);
- }
-
- protected MetaRuleset createMetaRuleset(Class type) {
- MetaRuleset m = super.createMetaRuleset(type);
- m.addRule(METARULE);
- return m;
- }
-}
Added: trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropHandler.java
===================================================================
--- trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropHandler.java
(rev 0)
+++ trunk/ui/dnd/ui/src/main/java/org/richfaces/view/facelets/DropHandler.java 2010-12-17
19:57:18 UTC (rev 20669)
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+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.AbstractDropTarget;
+import org.richfaces.event.MethodExpressionDropListener;
+
+/**
+ * @author abelevich
+ *
+ */
+public class DropHandler extends ComponentHandler{
+
+
+ private static final DropHandlerMetaRule METARULE = new DropHandlerMetaRule();
+
+ public DropHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset m = super.createMetaRuleset(type);
+ m.addRule(METARULE);
+ return m;
+ }
+
+ static class DropHandlerMetaRule extends MetaRule {
+
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
+ if (meta.isTargetInstanceOf(AbstractDropTarget.class) &&
"dropListener".equals(name)) {
+ return new DropTargetMapper(attribute);
+ }
+ return null;
+ }
+
+ }
+
+ static class DropTargetMapper extends Metadata {
+
+ private static final Class[] SIGNATURE = new Class[] {
org.richfaces.event.DropEvent.class };
+
+ private final TagAttribute attribute;
+
+ public DropTargetMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractDropTarget) instance).addDropListener((new
MethodExpressionDropListener(
+ this.attribute.getMethodExpression(ctx, null, SIGNATURE))));
+ }
+ }
+}
Modified:
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js
===================================================================
---
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-draggable.js 2010-12-17
19:57:18 UTC (rev 20669)
@@ -11,7 +11,10 @@
rf.ui = rf.ui || {};
rf.ui.Draggable = function(id, options) {
- this.dragElement = $(document.getElementById(id));
+ this.id = id;
+ this.options = options;
+
+ this.dragElement = $(document.getElementById(this.options.parentId));
this.dragElement.draggable();
if(options.indicator) {
@@ -25,10 +28,9 @@
this.dragElement.draggable("option", "addClasses", false);
- this.options = options;
-
this.dragElement.data('type', this.options.type);
this.dragElement.data("init", true);
+ this.dragElement.data("id", this.id);
this.dragElement.bind('dragstart', $.proxy(this.dragStart, this));
this.dragElement.bind('drag', $.proxy(this.drag, this));
Modified:
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js
===================================================================
---
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js 2010-12-17
19:39:26 UTC (rev 20668)
+++
trunk/ui/dnd/ui/src/main/resources/META-INF/resources/org.richfaces/dnd-droppable.js 2010-12-17
19:57:18 UTC (rev 20669)
@@ -12,8 +12,9 @@
rf.ui.Droppable = function(id, options) {
this.options = options;
- this.dropElement = $(document.getElementById(id));
+ this.id = id;
+ this.dropElement = $(document.getElementById(this.options.parentId));
this.dropElement.droppable({addClasses: false});
this.dropElement.data("init", true);
this.dropElement.bind('drop', $.proxy(this.drop, this));
@@ -70,13 +71,13 @@
},
__callAjax: function(e, ui){
- var options = {};
- var originalEvent = this.options['event'];
if(ui.draggable) {
- options['dragSource'] = ui.draggable.attr("id");
- options['javax.faces.behavior.event'] = originalEvent.type;
+ var dragSource = ui.draggable.data("id");
+ var ajaxFunc = this.options.ajaxFunction;
+ if(ajaxFunc && typeof ajaxFunc == 'function' ) {
+ ajaxFunc.call(this,e, dragSource);
+ }
}
- rf.ajax(this.dropElement[0], originalEvent, {parameters: options});
}
}
})());