![JAR search and dependency download from the Maven repository](/logo.png)
com.extjs.gxt.ui.client.widget.CheckBoxListView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxt Show documentation
Show all versions of gxt Show documentation
Rich Internet Application Framework for GWT
/*
* Ext GWT 2.2.0 - Ext for GWT
* Copyright(c) 2007-2010, Ext JS, LLC.
* [email protected]
*
* http://extjs.com/license
*/
package com.extjs.gxt.ui.client.widget;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.user.client.Element;
public class CheckBoxListView extends ListView {
protected List checkedPreRender;
private String checkBoxSelector = ".x-view-item-checkbox";
public String getCheckBoxSelector() {
return checkBoxSelector;
}
public List getChecked() {
if (rendered) {
List l = new ArrayList();
NodeList nodes = el().select(checkBoxSelector);
for (int i = 0; i < nodes.getLength(); i++) {
if (InputElement.is(nodes.getItem(i))) {
InputElement e = InputElement.as(nodes.getItem(i));
if (e.isChecked()) {
l.add(getStore().getAt(i));
}
}
}
return l;
} else {
return checkedPreRender != null ? new ArrayList(checkedPreRender) : new ArrayList();
}
}
public void setCheckBoxSelector(String checkBoxSelector) {
this.checkBoxSelector = checkBoxSelector;
}
/**
* Selects a specific item in the view
*
* @param m the modeldata that should be checked
* @param checked true to check
*/
public void setChecked(M m, boolean checked) {
if (rendered) {
NodeList nodes = el().select(checkBoxSelector);
int index = store.indexOf(m);
if (index != -1) {
Element e = nodes.getItem(index);
if (e != null) {
((InputElement) e.cast()).setChecked(checked);
}
}
} else {
if (checkedPreRender == null) {
checkedPreRender = new ArrayList();
}
if (checked) {
if (!checkedPreRender.contains(m)) {
checkedPreRender.add(m);
}
} else {
checkedPreRender.remove(m);
}
}
}
@Override
protected void afterRender() {
super.afterRender();
if (checkedPreRender != null) {
for (M m : checkedPreRender) {
setChecked(m, true);
}
checkedPreRender = null;
}
}
@Override
protected void onRender(Element target, int index) {
if (getTemplate() == null) {
String spacing = GXT.isIE ? "0" : "3";
setTemplate(XTemplate.create("{"
+ getDisplayProperty() + "}
"));
}
super.onRender(target, index);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy