org.odlabs.wiquery.ui.sortable
Class SortableAjaxBehavior<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.sortable.SortableAjaxBehavior<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 SortableAjaxBehavior<E extends org.apache.wicket.Component>
extends WiQueryAbstractAjaxBehavior

$Id: SortableAjaxBehavior

Sets the attached component sortable behavior. When the user finished to sort some childs components,onReceive(Component, int, Component, AjaxRequestTarget), or / and onRemove(Component, AjaxRequestTarget) or / and onUpdate(Component, int, AjaxRequestTarget) is / are called via Ajax.

This behavior contains a SortableBehavior which is used to control the options of the sortable, including all the options and event of the behavior. Example:

 SortableAjaxBehavior sortable = new SortableAjaxBehavior(SortedEvent.RECEIVE) {
                public void onReceive(Component sortedComponent, int index, 
                        Component parentSortedComponent, AjaxRequestTarget ajaxRequestTarget) {
                        // Only this method will be called
                        ...
                }
 
                public void onRemove(Component sortedComponent, AjaxRequestTarget ajaxRequestTarget) {
                        ...
                }
 
                public void onUpdate(Component sortedComponent, int index, AjaxRequestTarget ajaxRequestTarget) {
                        ...
                }
 }
 SortableBehavior sb = sortable.getSortableBehavior();
 sb.setConnectWith("#anotherSortableList");
 sb.setRevert(true);
 add(sortable);
 

Since:
1.0
Author:
Julien Roche, Ernesto Reinaldo Barreiro
See Also:
Serialized Form

Nested Class Summary
static class SortableAjaxBehavior.SortedEvent
          Enumeration of sorted ajax callback
 
Field Summary
 
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
 
Fields inherited from interface org.apache.wicket.behavior.IBehaviorListener
INTERFACE
 
Constructor Summary
SortableAjaxBehavior()
          Default constructor
SortableAjaxBehavior(SortableAjaxBehavior.SortedEvent... callbacks)
          Constructor
 
Method Summary
 JsStatement cancel()
          Method to cancel This will return the element back to its pre-init state.
 void cancel(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to cancel within the ajax request
 JsStatement destroy()
          Method to destroy This will return the element back to its pre-init state.
 void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to destroy within the ajax request
 JsStatement disable()
          Method to disable
 void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to disable within the ajax request
 JsStatement enable()
          Method to enable
 void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to enable within the ajax request
 String getAppendTo()
           
 SortableBehavior.AxisEnum getAxis()
           
protected  CharSequence getCallbackScriptReceive()
          We use standard AbstractDefaultAjaxBehavior machinery to generate script: what way all the logic regarding IAjaxCallDecorator or indicatorId will be added to the generated script.
protected  CharSequence getCallbackScriptRemove()
          We use standard AbstractDefaultAjaxBehavior machinery to generate script: what way all the logic regarding IAjaxCallDecorator or indicatorId will be added to the generated script.
protected  CharSequence getCallbackScriptUpdate()
          We use standard AbstractDefaultAjaxBehavior machinery to generate script: what way all the logic regarding IAjaxCallDecorator or indicatorId will be added to the generated script.
 String getCancel()
           
 String getConnectWith()
           
 SortableContainment getContainmentComplex()
           
 String getCursor()
           
 SortableBehavior.CursorAtEnum getCursorAt()
           
 int getDelay()
           
 int getDistance()
           
 ICollectionItemOptions getGrid()
           
 String getHandle()
           
 SortableHelper getHelperComplex()
           
 String getItems()
           
 float getOpacity()
           
 String getPlaceHolder()
           
 SortableRevert getRevert()
           
 int getScrollSensitivity()
           
 int getScrollSpeed()
           
 SortableBehavior getSortableBehavior()
           
 SortableBehavior.ToleranceEnum getTolerance()
           
 int getZIndex()
           
 boolean isDisabled()
           
 boolean isDropOnEmpty()
           
 boolean isForceHelperSize()
           
 boolean isForcePlaceholderSize()
           
 boolean isScroll()
           
protected  void onBind()
           
abstract  void onReceive(E sortedComponent, int index, org.apache.wicket.Component parentSortedComponent, org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          onReceive is called back when a connected sortable list has received an item from another list.
abstract  void onRemove(E sortedComponent, org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          OnRemove is called back when a sortable item has been dragged out from the list and into another.
 void onSort(org.apache.wicket.ajax.AjaxRequestTarget target)
          For framework internal use only.
abstract  void onUpdate(E sortedComponent, int index, org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          onUpdate is called back when the user stopped sorting and the DOM position has changed.
 JsStatement refresh()
          Method to refresh
 void refresh(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to refresh within the ajax request
 JsStatement refreshPositions()
          Method to refresh positions
 void refreshPositions(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to refresh positions within the ajax request
protected  void respond(org.apache.wicket.ajax.AjaxRequestTarget target)
           
 JsStatement serialize()
          Method to serialize (in default mode)
 void serialize(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to serialize (in default mode) within the ajax request
 SortableAjaxBehavior<E> setAppendTo(String appendTo)
          Defines where the helper that moves with the mouse is being appended to during the drag (for example, to resolve overlap/zIndex issues).
 SortableAjaxBehavior<E> setAxis(SortableBehavior.AxisEnum axis)
          If defined, the items can be dragged only horizontally or vertically.
 SortableAjaxBehavior<E> setCancel(String cancel)
          Set's the prevent selecting if you start on elements matching the selector
 SortableAjaxBehavior<E> setConnectWith(String connectWith)
          Set a jQuery selector with items that also have sortables applied.
 SortableAjaxBehavior<E> setContainment(SortableContainment containment)
          Constrains dragging to within the bounds of the specified element - can be a DOM element, 'parent', 'document', 'window', or a jQuery selector.
 SortableAjaxBehavior<E> setCursor(String cursor)
          Set the cursor that is being shown while sorting
 SortableAjaxBehavior<E> setCursorAt(SortableBehavior.CursorAtEnum cusorAt)
          Moves the sorting element or helper so the cursor always appears to drag from the same position.
 SortableAjaxBehavior<E> setDelay(int delay)
          Set's the delay (in milliseconds) to define when the sorting should start
 SortableAjaxBehavior<E> setDisabled(boolean disabled)
          Disables (true) or enables (false) the sortable.
 SortableAjaxBehavior<E> setDistance(int distance)
          Set's the tolerance in pixels
 SortableAjaxBehavior<E> setDropOnEmpty(boolean dropOnEmpty)
          If empty allows for an item to be dropped from a linked selectable.
 SortableAjaxBehavior<E> setForceHelperSize(boolean forceHelperSize)
          If true, forces the helper to have a size.
 SortableAjaxBehavior<E> setForcePlaceholderSize(boolean forcePlaceholderSize)
          If true, forces the placeholder to have a size.
 SortableAjaxBehavior<E> setGrid(int x, int y)
          Snaps the sorting element or helper to a grid, every x and y pixels.
 SortableAjaxBehavior<E> setHandle(String handle)
          Restricts sort start click to the specified element.
 SortableAjaxBehavior<E> setHelper(SortableHelper helper)
          Allows for a helper element to be used for dragging display.
 SortableAjaxBehavior<E> setItems(String items)
          Specifies which items inside the element should be sortable.
 SortableAjaxBehavior<E> setOpacity(float opacity)
          Set the opacity of the helper while sorting.
 SortableAjaxBehavior<E> setPlaceholder(String placeholder)
          Set's the class that gets applied to the otherwise white space.
 SortableAjaxBehavior<E> setRevert(SortableRevert revert)
          If set to true, the item will be reverted to its new DOM position with a smooth animation.
 SortableAjaxBehavior<E> setScroll(boolean scroll)
          If set to true, the page scrolls when coming to an edge.
 SortableAjaxBehavior<E> setScrollSensitivity(int scrollSensitivity)
          Defines how near the mouse must be to an edge to start scrolling.
 SortableAjaxBehavior<E> setScrollSpeed(int scrollSpeed)
          The speed at which the window should scroll once the mouse pointer gets within the scrollSensitivity distance.
 SortableAjaxBehavior<E> setTolerance(SortableBehavior.ToleranceEnum tolerance)
          Set's the tolerance intersect: draggable overlaps the droppable at least 50% pointer: mouse pointer overlaps the droppable
 SortableAjaxBehavior<E> setZIndex(int zIndex)
          Set's Z-index for element/helper while being sorted.
 JsStatement statement()
          Returns the main JsStatement used to create the plugin.
 JsStatement toArray()
          Method to serializes the sortable's item id's into an array of string
 JsStatement widget()
          Method to returns the .ui-sortable element
 void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to returns the .ui-sortable element within the ajax request
 
Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, generateCallbackScript, getAjaxCallDecorator, getCallbackScript, 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

SortableAjaxBehavior

public SortableAjaxBehavior()
Default constructor


SortableAjaxBehavior

public SortableAjaxBehavior(SortableAjaxBehavior.SortedEvent... callbacks)
Constructor

Parameters:
callbacks - Ajax callbacks to enable
Method Detail

getCallbackScriptReceive

protected CharSequence getCallbackScriptReceive()
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 sortable AJAX behavior compatible with standard Wicket's AJAX call-backs.

See Also:
AbstractAjaxBehavior.getCallbackUrl()

getCallbackScriptRemove

protected CharSequence getCallbackScriptRemove()
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 sortable AJAX behavior compatible with standard Wicket's AJAX call-backs.

See Also:
AbstractAjaxBehavior.getCallbackUrl()

getCallbackScriptUpdate

protected CharSequence getCallbackScriptUpdate()
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 sortable AJAX behavior compatible with standard Wicket's AJAX call-backs.

See Also:
AbstractAjaxBehavior.getCallbackUrl()

getSortableBehavior

public SortableBehavior getSortableBehavior()
Returns:
the standard Sortable JavaScript behavior

onBind

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

onReceive

public abstract void onReceive(E sortedComponent,
                               int index,
                               org.apache.wicket.Component parentSortedComponent,
                               org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
onReceive is called back when a connected sortable list has received an item from another list.

Parameters:
sortedComponent - the sorted Component
parentSortedComponent - the parent of the sorted Component
index - Index of the sorted Component
ajaxRequestTarget - the Ajax target

onRemove

public abstract void onRemove(E sortedComponent,
                              org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
OnRemove is called back when a sortable item has been dragged out from the list and into another.

Parameters:
sortedComponent - the sorted Component
ajaxRequestTarget - the Ajax target

onSort

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


onUpdate

public abstract void onUpdate(E sortedComponent,
                              int index,
                              org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
onUpdate is called back when the user stopped sorting and the DOM position has changed.

Parameters:
sortedComponent - the sorted Component
index - Index of the sorted 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.

getAppendTo

public String getAppendTo()
Returns:
the appendTo option value

getAxis

public SortableBehavior.AxisEnum getAxis()
Returns:
the axis option value

getCancel

public String getCancel()
Returns:
the cancel option value

getConnectWith

public String getConnectWith()
Returns:
the connectWith option value

getContainmentComplex

public SortableContainment getContainmentComplex()
Returns:
the containment option value

getCursor

public String getCursor()
Returns:
the cursor option value

getCursorAt

public SortableBehavior.CursorAtEnum getCursorAt()
Returns:
the cursorAt option value

getDelay

public int getDelay()
Returns:
the delay option value

getDistance

public int getDistance()
Returns:
the distance option value

getGrid

public ICollectionItemOptions getGrid()
Returns:
the grid option value

getHandle

public String getHandle()
Returns:
the handle option value

getHelperComplex

public SortableHelper getHelperComplex()
Returns:
the helper option value

getItems

public String getItems()
Returns:
the items option value

getOpacity

public float getOpacity()
Returns:
the opacity option value

getPlaceHolder

public String getPlaceHolder()
Returns:
the placeHolder option value

getRevert

public SortableRevert getRevert()
Returns:
the revert option value

getScrollSensitivity

public int getScrollSensitivity()
Returns:
the scrollSensitivity option value

getScrollSpeed

public int getScrollSpeed()
Returns:
the scrollSpeed option value

getTolerance

public SortableBehavior.ToleranceEnum getTolerance()
Returns:
the tolerance option value

getZIndex

public int getZIndex()
Returns:
the zIndex option value

setDisabled

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

Parameters:
disabled -
Returns:
instance of the current behavior

isDisabled

public boolean isDisabled()
Returns:
the disabled option

isDropOnEmpty

public boolean isDropOnEmpty()
Returns:
the dropOnEmpty option value

isForceHelperSize

public boolean isForceHelperSize()
Returns:
the forceHelperSize option value

isForcePlaceholderSize

public boolean isForcePlaceholderSize()
Returns:
the forcePlaceholderSize option value

isScroll

public boolean isScroll()
Returns:
the scroll option value

setAppendTo

public SortableAjaxBehavior<E> setAppendTo(String appendTo)
Defines where the helper that moves with the mouse is being appended to during the drag (for example, to resolve overlap/zIndex issues).

Parameters:
appendTo -
Returns:
instance of the current behavior

setAxis

public SortableAjaxBehavior<E> setAxis(SortableBehavior.AxisEnum axis)
If defined, the items can be dragged only horizontally or vertically. Possible values:'x', 'y'.

Parameters:
axis -
Returns:
instance of the current behavior

setCancel

public SortableAjaxBehavior<E> setCancel(String cancel)
Set's the prevent selecting if you start on elements matching the selector

Parameters:
cancel - Selector (default : ':input,option')
Returns:
instance of the current behavior

setConnectWith

public SortableAjaxBehavior<E> setConnectWith(String connectWith)
Set a jQuery selector with items that also have sortables applied. If used, the sortable is now connected to the other one-way, so you can drag from this sortable to the other.

Parameters:
connectWith - Selector
Returns:
instance of the current behavior

setContainment

public SortableAjaxBehavior<E> setContainment(SortableContainment containment)
Constrains dragging to within the bounds of the specified element - can be a DOM element, 'parent', 'document', 'window', or a jQuery selector.

Parameters:
containment -
Returns:
instance of the current behavior

setCursor

public SortableAjaxBehavior<E> setCursor(String cursor)
Set the cursor that is being shown while sorting

Parameters:
cursor -
Returns:
instance of the current behavior

setCursorAt

public SortableAjaxBehavior<E> setCursorAt(SortableBehavior.CursorAtEnum cusorAt)
Moves the sorting element or helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys: { top, left, right, bottom }

Parameters:
cusorAt -
Returns:
instance of the current behavior

setDelay

public SortableAjaxBehavior<E> setDelay(int delay)
Set's the delay (in milliseconds) to define when the sorting should start

Parameters:
delay -
Returns:
instance of the current behavior

setDistance

public SortableAjaxBehavior<E> setDistance(int distance)
Set's the tolerance in pixels

Parameters:
distance -
Returns:
instance of the current behavior

setDropOnEmpty

public SortableAjaxBehavior<E> setDropOnEmpty(boolean dropOnEmpty)
If empty allows for an item to be dropped from a linked selectable.

Parameters:
dropOnEmpty -
Returns:
instance of the current behavior

setForceHelperSize

public SortableAjaxBehavior<E> setForceHelperSize(boolean forceHelperSize)
If true, forces the helper to have a size.

Parameters:
forceHelperSize -
Returns:
instance of the current behavior

setForcePlaceholderSize

public SortableAjaxBehavior<E> setForcePlaceholderSize(boolean forcePlaceholderSize)
If true, forces the placeholder to have a size.

Parameters:
forcePlaceholderSize -
Returns:
instance of the current behavior

setGrid

public SortableAjaxBehavior<E> setGrid(int x,
                                       int y)
Snaps the sorting element or helper to a grid, every x and y pixels. Array values: [x, y]

Parameters:
x -
y -
Returns:
instance of the current behavior

setHandle

public SortableAjaxBehavior<E> setHandle(String handle)
Restricts sort start click to the specified element.

Parameters:
handle -
Returns:
instance of the current behavior

setHelper

public SortableAjaxBehavior<E> setHelper(SortableHelper helper)
Allows for a helper element to be used for dragging display. The supplied function receives the event and the element being sorted, and should return a DOMElement to be used as a custom proxy helper. Possible values: 'original', 'clone'

Parameters:
helper -
Returns:
instance of the current behavior

setItems

public SortableAjaxBehavior<E> setItems(String items)
Specifies which items inside the element should be sortable.

Parameters:
items - Cursor (default : '> *')
Returns:
instance of the current behavior

setOpacity

public SortableAjaxBehavior<E> setOpacity(float opacity)
Set the opacity of the helper while sorting. From 0.01 to 1

Parameters:
opacity -
Returns:
instance of the current behavior

setPlaceholder

public SortableAjaxBehavior<E> setPlaceholder(String placeholder)
Set's the class that gets applied to the otherwise white space.

Parameters:
placeholder -
Returns:
instance of the current behavior

setRevert

public SortableAjaxBehavior<E> setRevert(SortableRevert revert)
If set to true, the item will be reverted to its new DOM position with a smooth animation.

Parameters:
revert -
Returns:
instance of the current behavior

setScroll

public SortableAjaxBehavior<E> setScroll(boolean scroll)
If set to true, the page scrolls when coming to an edge.

Parameters:
scroll -
Returns:
instance of the current behavior

setScrollSensitivity

public SortableAjaxBehavior<E> setScrollSensitivity(int scrollSensitivity)
Defines how near the mouse must be to an edge to start scrolling.

Parameters:
scrollSensitivity -
Returns:
instance of the current behavior

setScrollSpeed

public SortableAjaxBehavior<E> setScrollSpeed(int scrollSpeed)
The speed at which the window should scroll once the mouse pointer gets within the scrollSensitivity distance.

Parameters:
scrollSpeed -
Returns:
instance of the current behavior

setTolerance

public SortableAjaxBehavior<E> setTolerance(SortableBehavior.ToleranceEnum tolerance)
Set's the tolerance

Parameters:
tolerance -
Returns:
instance of the current behavior

setZIndex

public SortableAjaxBehavior<E> setZIndex(int zIndex)
Set's Z-index for element/helper while being sorted.

Parameters:
zIndex -
Returns:
instance of the current behavior

cancel

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

Returns:
the associated JsStatement

cancel

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

Parameters:
ajaxRequestTarget -

destroy

public JsStatement destroy()
Method to destroy 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 within the ajax request

Parameters:
ajaxRequestTarget -

disable

public JsStatement disable()
Method to disable

Returns:
the associated JsStatement

disable

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

Parameters:
ajaxRequestTarget -

enable

public JsStatement enable()
Method to enable

Returns:
the associated JsStatement

enable

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

Parameters:
ajaxRequestTarget -

refresh

public JsStatement refresh()
Method to refresh

Returns:
the associated JsStatement

refresh

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

Parameters:
ajaxRequestTarget -

refreshPositions

public JsStatement refreshPositions()
Method to refresh positions

Returns:
the associated JsStatement

refreshPositions

public void refreshPositions(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to refresh positions within the ajax request

Parameters:
ajaxRequestTarget -

serialize

public JsStatement serialize()
Method to serialize (in default mode)

Returns:
the associated JsStatement

serialize

public void serialize(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to serialize (in default mode) within the ajax request

Parameters:
ajaxRequestTarget -

toArray

public JsStatement toArray()
Method to serializes the sortable's item id's into an array of string

Returns:
the associated JsStatement

widget

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

Returns:
the associated JsStatement

widget

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

Parameters:
ajaxRequestTarget -


Copyright © 2012. All Rights Reserved.