23.12.2012 Views

ZK Developer's Guide

ZK Developer's Guide

ZK Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Is it on the Desktop or on the Web?<br />

}<br />

}<br />

}<br />

@SuppressWarnings("unchecked")<br />

public void onEvent(Event event)<br />

{<br />

Listitem it = (Listitem) ((DropEvent)event).getDragged();<br />

Object[] childs = it.getChildren().toArray();<br />

RememberList remember = (RememberList) Sessions.getCurrent()<br />

.getAttribute(RememberListInitializer.REMEMBER_LIST);<br />

Media media = MediaFactory.create(((Listcell)<br />

childs[4]).getLabel());<br />

media.setTitle(((Listcell)childs[3]).getLabel());<br />

media.setId(((Listcell)childs[2]).getLabel());<br />

remember.add(media);<br />

((RememberMediaListModel)((Listbox)item.getParent())<br />

.getModel()).update();<br />

}<br />

});<br />

One notable line in the code is item.setDroppable("true"). With this line, we<br />

activate the listbox as a possible destination of the drag-and-drop process. To<br />

activate the main listbox as possible source of a drag-and-drop process, we have<br />

to add the line item.setDraggable("true") to com.packtpub.zk.media.view.<br />

MediaListItemRenderer. Additionally we implement our own ListModel for<br />

that window.<br />

public class RememberMediaListModel extends AbstractListModel<br />

implements ListModel<br />

{<br />

/**<br />

* @see org.zkoss.zul.ListModel#getElementAt(int)<br />

*/<br />

public Object getElementAt(final int index)<br />

{<br />

return this.getMedia().toArray()[index];<br />

}<br />

/**<br />

* @see org.zkoss.zul.ListModel#getSize()<br />

*/<br />

public int getSize()<br />

{<br />

return this.getMedia().size();<br />

}<br />

[ 98 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!