Source Viewer : WEB-INF/classes/org/apache/click/examples/control/html/list/HtmlList.java
package org.apache.click.examples.control.html.list;
import java.util.List;
import org.apache.click.Control;
import org.apache.click.control.AbstractContainer;
/**
* This control provides HTML ordered and unordered lists.
*/
public class HtmlList extends AbstractContainer {
private static final long serialVersionUID = 1L;
public static final int UNORDERED_LIST = 0;
public static final int ORDERED_LIST = 1;
private int listMode = UNORDERED_LIST;
public HtmlList() {
}
public HtmlList(int listMode) {
this.listMode = listMode;
}
public HtmlList(String name) {
super(name);
}
public HtmlList(String name, int listMode) {
this(name);
this.listMode = listMode;
}
public Control add(Control control) {
if (!(control instanceof ListItem)) {
throw new IllegalArgumentException("Only list items can be added.");
}
return super.add(control);
}
public String getTag() {
if (isUnorderedList()) {
return "ul";
} else {
return "ol";
}
}
public int getListMode() {
return listMode;
}
public void setListMode(int listMode) {
this.listMode = listMode;
}
public boolean isUnorderedList() {
return listMode == UNORDERED_LIST;
}
public ListItem getLast() {
List<Control> items = getControls();
if (items.size() == 0) {
throw new IllegalStateException("HtmlList is empty and contains no ListItems.");
}
return (ListItem) items.get(items.size() - 1);
}
}