org.odlabs.wiquery.ui.droppable
Class DroppableAjaxBehavior<E extends org.apache.wicket.Component>

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.apache.wicket.behavior.AbstractAjaxBehavior
          extended by org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
              extended by org.odlabs.wiquery.core.behavior.WiQueryAbstractAjaxBehavior
                  extended by org.odlabs.wiquery.ui.droppable.DroppableAjaxBehavior<E>
Type Parameters:
E - Type of component to find
All Implemented Interfaces:
Serializable, org.apache.wicket.behavior.IBehaviorListener, org.apache.wicket.IClusterable, org.apache.wicket.IComponentAwareEventSink, org.apache.wicket.IRequestListener, org.apache.wicket.markup.html.IComponentAwareHeaderContributor, IWiQueryPlugin

public abstract class DroppableAjaxBehavior<E extends org.apache.wicket.Component>
extends WiQueryAbstractAjaxBehavior

$Id$

Sets the attached component droppable, e.g. it can accept draggable elements. When the drop is done, onDrop(Component, AjaxRequestTarget) is called by an Ajax request.

Contains a DroppableBehavior which is used to control the options of the droppable, including accept, activeClass, addClasses, greedy, hoverClass, scope, and tolerance. For example:

 DroppableAjaxBehavior droppable = new DroppableAjaxBehavior() {
      public void onDrop(Component droppedComponent,
              AjaxRequestTarget ajaxRequestTarget) {
                      ...
      }
 };
 DroppableBehavior dp = droppable.getDroppableBehavior();
 dp.setAccept(new DroppableAccept(".fruit"));
 dp.setHoverClass("drophover");
 dp.setScope("candy");
 add(droppable);
 

Since:
1.0
Author:
Lionel Armanet
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
 
Fields inherited from interface org.apache.wicket.behavior.IBehaviorListener
INTERFACE
 
Constructor Summary
DroppableAjaxBehavior()
          Default constructor
 
Method Summary
 JsStatement destroy()
          Method to destroy the droppable This will return the element back to its pre-init state.
 void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to destroy the droppable within the ajax request
 JsStatement disable()
          Method to disable the droppable
 void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to disable the droppable within the ajax request
 JsStatement enable()
          Method to enable the droppable
 void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to enable the droppable within the ajax request
 DroppableAccept getAccept()
           
 String getActiveClass()
           
protected  CharSequence getCallbackScript()
          We override super method to add droppedId parameter to the URL.
 DroppableBehavior getDroppableBehavior()
           
 String getHoverClass()
           
 String getScope()
           
 DroppableBehavior.ToleranceEnum getTolerance()
           
 boolean isAddClasses()
           
 boolean isDisabled()
           
 boolean isGreedy()
           
protected  void onBind()
           
 void onDrop(org.apache.wicket.ajax.AjaxRequestTarget target)
          For framework internal use only.
abstract  void onDrop(E droppedComponent, org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          onDrop is called back when the drop event has been fired.
protected  void respond(org.apache.wicket.ajax.AjaxRequestTarget target)
           
 DroppableAjaxBehavior<E> setAccept(DroppableAccept accept)
          All draggables that match the selector will be accepted.
 DroppableAjaxBehavior<E> setActiveClass(String activeClass)
          If specified, the class will be added to the droppable while an acceptable draggable is being dragged.
 DroppableAjaxBehavior<E> setAddClasses(boolean addClasses)
          If true, will prevent event propagation on nested droppables.
 DroppableAjaxBehavior<E> setDisabled(boolean disabled)
          Disables (true) or enables (false) the droppable.
 DroppableAjaxBehavior<E> setGreedy(boolean greedy)
          If true, will prevent event propagation on nested droppables.
 DroppableAjaxBehavior<E> setHoverClass(String hoverClass)
          If specified, the class will be added to the droppable while an acceptable draggable is being hovered.
 DroppableAjaxBehavior<E> setScope(String scope)
          Used to group sets of draggable and droppable items, in addition to droppable's accept option.
 DroppableAjaxBehavior<E> setTolerance(DroppableBehavior.ToleranceEnum tolerance)
          Set's the mode to use for testing whether a draggable is 'over' a droppable.
 JsStatement statement()
          Returns the main JsStatement used to create the plugin.
 JsStatement widget()
          Method to returns the .ui-droppable element
 void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to returns the .ui-droppable element within the ajax request
 
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, generateCallbackScript, getAjaxCallDecorator, getChannel, getChannelName, getFailureScript, getPreconditionScript, getSuccessScript, onRequest, renderHead, throttleScript
 
Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, getStatelessHint, onComponentRendered, onComponentTag, onComponentTag
 
Methods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListenerInterface, canCallListenerInterface, detach, isEnabled, isTemporary, onConfigure, onEvent, onException, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DroppableAjaxBehavior

public DroppableAjaxBehavior()
Default constructor

Method Detail

getCallbackScript

protected CharSequence getCallbackScript()
We override super method to add droppedId parameter to the URL. Otherwise we use standard AbstractDefaultAjaxBehavior machinery to generate script: what way all the logic regarding IAjaxCallDecorator or indicatorId will be added to the generated script. This makes droppable behavior more compatible with standard Wicket's AJAX call-backs.

Overrides:
getCallbackScript in class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
See Also:
AbstractAjaxBehavior.getCallbackUrl()

getDroppableBehavior

public DroppableBehavior getDroppableBehavior()
Returns:
the standard droppable JavaScript behavior

onBind

protected void onBind()
Overrides:
onBind in class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior

onDrop

public final void onDrop(org.apache.wicket.ajax.AjaxRequestTarget target)
For framework internal use only.


onDrop

public abstract void onDrop(E droppedComponent,
                            org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
onDrop is called back when the drop event has been fired.

Parameters:
droppedComponent - the dropped Component
ajaxRequestTarget - the Ajax target

respond

protected void respond(org.apache.wicket.ajax.AjaxRequestTarget target)
Specified by:
respond in class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior

statement

public JsStatement statement()
Description copied from interface: IWiQueryPlugin
Returns the main JsStatement used to create the plugin.

Specified by:
statement in interface IWiQueryPlugin
Specified by:
statement in class WiQueryAbstractAjaxBehavior
Returns:
The JsStatement corresponding to this component.

setAccept

public DroppableAjaxBehavior<E> setAccept(DroppableAccept accept)
All draggables that match the selector will be accepted. If a function is specified, the function will be called for each draggable on the page (passed as the first argument to the function), to provide a custom filter. The function should return true if the draggable should be accepted.

Parameters:
accept -
Returns:
instance of the current behavior

getAccept

public DroppableAccept getAccept()
Returns:
the accept option

setActiveClass

public DroppableAjaxBehavior<E> setActiveClass(String activeClass)
If specified, the class will be added to the droppable while an acceptable draggable is being dragged.

Parameters:
activeClass -
Returns:
instance of the current behavior

getActiveClass

public String getActiveClass()
Returns:
the activeClass option

setAddClasses

public DroppableAjaxBehavior<E> setAddClasses(boolean addClasses)
If true, will prevent event propagation on nested droppables.

Parameters:
addClasses -
Returns:
instance of the current behavior

isAddClasses

public boolean isAddClasses()
Returns:
the addClasses option

setDisabled

public DroppableAjaxBehavior<E> setDisabled(boolean disabled)
Disables (true) or enables (false) the droppable. Can be set when initialising (first creating) the droppable.

Parameters:
disabled -
Returns:
instance of the current behavior

isDisabled

public boolean isDisabled()
Returns:
the disabled option

setGreedy

public DroppableAjaxBehavior<E> setGreedy(boolean greedy)
If true, will prevent event propagation on nested droppables.

Parameters:
greedy -
Returns:
instance of the current behavior

isGreedy

public boolean isGreedy()
Returns:
the greedy option

setHoverClass

public DroppableAjaxBehavior<E> setHoverClass(String hoverClass)
If specified, the class will be added to the droppable while an acceptable draggable is being hovered.

Parameters:
hoverClass -
Returns:
instance of the current behavior

getHoverClass

public String getHoverClass()
Returns:
the hoverClass option

setScope

public DroppableAjaxBehavior<E> setScope(String scope)
Used to group sets of draggable and droppable items, in addition to droppable's accept option. A draggable with the same scope value as a droppable will be accepted.

Parameters:
scope -
Returns:
instance of the current behavior

getScope

public String getScope()
Returns:
the scope option

setTolerance

public DroppableAjaxBehavior<E> setTolerance(DroppableBehavior.ToleranceEnum tolerance)
Set's the mode to use for testing whether a draggable is 'over' a droppable. Possible values: 'fit', 'intersect', 'pointer', 'touch'.

Parameters:
tolerance -
Returns:
instance of the current behavior

getTolerance

public DroppableBehavior.ToleranceEnum getTolerance()
Returns:
the tolerance option enum

destroy

public JsStatement destroy()
Method to destroy the droppable This will return the element back to its pre-init state.

Returns:
the associated JsStatement

destroy

public void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to destroy the droppable within the ajax request

Parameters:
ajaxRequestTarget -

disable

public JsStatement disable()
Method to disable the droppable

Returns:
the associated JsStatement

disable

public void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to disable the droppable within the ajax request

Parameters:
ajaxRequestTarget -

enable

public JsStatement enable()
Method to enable the droppable

Returns:
the associated JsStatement

enable

public void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to enable the droppable within the ajax request

Parameters:
ajaxRequestTarget -

widget

public JsStatement widget()
Method to returns the .ui-droppable element

Returns:
the associated JsStatement

widget

public void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to returns the .ui-droppable element within the ajax request

Parameters:
ajaxRequestTarget -


Copyright © 2012. All Rights Reserved.