b30-1819318.zul
来自「ZK是一个Ajax Java Web框架」· ZUL 代码 · 共 115 行
ZUL
115 行
<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
<html><![CDATA[
1. Select randomly an item from the 1st listbox.<br/>
2. The selected item should appear in the 2nd listbox.<br/>
3. Repeat 1 and 2 in RANDOM order, the 2nd listbox should list items in order no matter the added sequence.<br/>
4. Press the parentModel button and check the real order of the 2nd listbox. It should be in order.<br/>
5. Press the parents button and check the real order of the inner TreeSet. It should be in order.<br/>
6. If everything ok. Now start to check "remove" item from 2nd listbox.<br/>
7. DoubleClick randomly on the item of the 2nd listbox and check if it is removed properly and kept the order.<br/>
8. Now repeate 4 and 5 to see if the inner data structure is in the same order as shown on the 2nd listbox.<br/>
]]></html>
<window closable="true" id="testArticoloWind"
width="200px" title="Test"
xmlns="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd ">
<zscript><![CDATA[
public class BlahComparator implements Comparator {
public int compare(Object o1, Object o2) {
int p1 = ((Blah)o1).getNumber();
int p2 = ((Blah)o2).getNumber();
int res = 0;
if(p1 > p2) res = 1;
else if(p1 < p2) res = -1;
return res;
}
}
class Person {
TreeSet parents = new TreeSet(new BlahComparator());
public TreeSet getParents(){
return parents;
}
public void addParent(Object o){
parents.add(o);
}
}
class Blah implements Comparable{
int number = 0;
private String name ;
private static int counter = 1;
public Blah(){
name = "Blah " + Integer.toString((number = counter++));
}
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public String toString(){
return name;
}
public int getNumber(){
return number;
}
public int compareTo(Object o){
int n = ((Blah)o).getNumber();
if(number > n) return 1;
if(number < n) return -1;
return 0;
}
}
Person person = new Person();
int actionCounter = 1;
ArrayList l = new ArrayList(20);
for(int i = 0; i < 20; i++)
l.add(new Blah());
]]></zscript>
<groupbox>
<caption label="1st listbox"/>
<listbox model="@{l}" mold="select" >
<attribute name="onSelect">
Blah p = l.get(self.selectedIndex);
((ListModelSet)parentsList.getModel()).add(p);
</attribute>
</listbox>
</groupbox>
<groupbox>
<caption label="2nd listbox"/>
<listbox id="parentsList" model="@{person.parents}">
<listhead>
<listheader label="Parent"/>
</listhead>
<listitem self="@{each=obj}" value="@{obj}">
<attribute name="onDoubleClick">
Blah b = (Blah)self.value;
((ListModelSet)parentsList.getModel()).remove(b);
</attribute>
<listcell label="@{obj}"/>
</listitem>
</listbox>
</groupbox>
<button label="parentModel" onClick='alert(""+parentsList.getModel())'/>
<button label="parents" onClick='alert(""+person.getParents())'/>
</window>
</zk>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?