* Handles the event processing during sorting.
*/
@Override
protected void respond(final AjaxRequestTarget target) {
Component component = getComponent();
Request request;
if (component != null && (request = component.getRequest()) != null) {
EventType eventType = EventType.stringToType(request.getParameter(EventType.IDENTIFIER));
String draggedItemId = request.getParameter("draggedItemId");
// We need the body of the <li> tag, the component inside it
ChildrenFinder childrenFinder = new ChildrenFinder(draggedItemId);
component.getPage().visitChildren(childrenFinder);
if (childrenFinder.getFoundComponents().size() != 1)
throw new WicketRuntimeException("this should not happen");
Component sortedComponent = childrenFinder.getFoundComponents().get(0);
if (eventType == EventType.STOP) {
int newPosition = 0;
try {
String s = request.getParameter("newPosition");
newPosition = Integer.parseInt(s);
if (sortedComponent instanceof ISortable) {
((ISortable)sortedComponent).onSorted(target, newPosition);
}
onSorted(target, sortedComponent, newPosition);
} catch (Exception e) {
// don't process
}
}
else if (eventType == EventType.RECEIVE) {
String otherSortableId = "";
int newPosition = 0;
try {
String s = request.getParameter("newPosition");
newPosition = Integer.parseInt(s);
otherSortableId = request.getParameter("otherSortableId");
if (sortedComponent instanceof ISortable) {
((ISortable)sortedComponent).onReceived(target, newPosition);
}