Sortable: connect with
- item #1
- item #2
- item #3
- item #4
- item #5
- item #6
- item #7
- item #8
- item #9
- item #10
- item #11
- item #12
Components / Samples
Description
Sample of usage of the connectWith option
Since
wicket-jquery-ui-6.12.0Sources
package com.googlecode.wicket.jquery.ui.samples.jqueryui.sortable; import java.util.List; import org.apache.wicket.AttributeModifier; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.panel.EmptyPanel; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.IModel; import org.apache.wicket.util.lang.Generics; import com.googlecode.wicket.jquery.core.resource.StyleSheetPackageHeaderItem; import com.googlecode.wicket.jquery.ui.JQueryIcon; import com.googlecode.wicket.jquery.ui.interaction.sortable.Sortable; import com.googlecode.wicket.jquery.ui.interaction.sortable.Sortable.HashListView; import com.googlecode.wicket.jquery.ui.panel.JQueryFeedbackPanel; public class ConnectSortablePage extends AbstractSortablePage { private static final long serialVersionUID = 1L; private final FeedbackPanel feedback; public ConnectSortablePage() { List<String> list1 = newList("item #1", "item #2", "item #3", "item #4", "item #5", "item #6"); List<String> list2 = newList("item #7", "item #8", "item #9", "item #10", "item #11", "item #12"); // FeedbackPanel // this.feedback = new JQueryFeedbackPanel("feedback"); this.add(this.feedback.setOutputMarkupId(true)); // Sortables // final Sortable<String> sortable1 = this.newSortable("sortable1", list1); this.add(sortable1); final Sortable<String> sortable2 = this.newSortable("sortable2", list2); this.add(sortable2); // Dual connect the sortables sortable1.connectWith(sortable2); sortable2.connectWith(sortable1); } // Methods // @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); response.render(new StyleSheetPackageHeaderItem(ConnectSortablePage.class)); } // Factories // private Sortable<String> newSortable(final String id, final List<String> list) { return new Sortable<String>(id, list) { private static final long serialVersionUID = 1L; @Override protected HashListView<String> newListView(IModel<List<String>> model) { return ConnectSortablePage.newListView("items", model); } @Override public void onUpdate(AjaxRequestTarget target, String item, int index) { // Will update the model object with the new order // Remove the call to super if you do not want your model to be updated (is read-only or you use a LDM) super.onUpdate(target, item, index); this.info(String.format("%s updated %s to position %d", id, item, index + 1)); this.info(String.format("%s list is now: %s", id, this.getModelObject())); // Update is always the last event to be thrown target.add(feedback); } @Override public void onReceive(AjaxRequestTarget target, String item, int index) { // Will update the model object with the new received item // Remove the call to super if you do not want your model to be updated super.onReceive(target, item, index); this.info(String.format("%s received %s at position %d", id, item, index + 1)); } @Override public void onRemove(AjaxRequestTarget target, String item) { // Will removes the item from the model object // Remove the call to super if you do not want your model to be updated super.onRemove(target, item); this.info(String.format("%s has removed %s", id, item)); this.info(String.format("%s list is now: %s", id, this.getModelObject())); } }; } protected static HashListView<String> newListView(String id, IModel<List<String>> model) { return new HashListView<String>(id, model) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<String> item) { item.add(new EmptyPanel("icon").add(AttributeModifier.append("class", "ui-icon " + JQueryIcon.ARROW_2_N_S))); item.add(new Label("item", item.getModelObject())); item.add(AttributeModifier.append("class", "ui-state-default")); } }; } /** * Gets a new <i>modifiable</i> list */ private static List<String> newList(String... items) { List<String> list = Generics.newArrayList(); for (String item : items) { list.add(item); } return list; } }
<!DOCTYPE html> <html xmlns:wicket="http://wicket.apache.org"> <head> <wicket:head> <title>Wicket jQuery UI: sortable (connect with)</title> </wicket:head> </head> <body> <wicket:extend> <div> <ul wicket:id="sortable1" class="sortable sortable1"> <li wicket:id="items"> <span wicket:id="icon">[icon]</span> <span wicket:id="item" class="item">[label]</span> </li> </ul> <ul wicket:id="sortable2" class="sortable sortable2"> <li wicket:id="items"> <span wicket:id="icon">[icon]</span> <span wicket:id="item" class="item">[label]</span> </li> </ul> <br class="clear-both"/> <div wicket:id="feedback"></div> </div> </wicket:extend> </body> </html>
.sortable { list-style-type: none; margin: 0; padding: 0; width: 40%; } .sortable li { margin: 0.3em; padding: 0.3em; x-padding-left: 1.5em; font-size: 1.1em; background-color: #fff; } .sortable1 { float: left; } .sortable2 { float: right; }