我的任务是设计一个具有多选功能的ComboBox(GXT)大小控件。我尝试使用ComboBox的setView设置CheckBoxListView,但似乎没有工作。任何人都可以指导我,如果有任何方式使用GXT框架我可以实现这个目标吗?
PS:我在sencha论坛(java类,源代码)中找到了一个名为XComboBox的组件,该组件运行良好,但不能用作GNU GPL许可下的
提前致谢!
答案 0 :(得分:5)
感谢@smiletolead的指导,我通过将Dialog与CheckBoxListView和TriggerField类集成来找到了解决方案。
完整的代码清单是..
package com.ui.test.client;
import java.util.List;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.WindowEvent;
import com.extjs.gxt.ui.client.event.WindowListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.CheckBoxListView;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.form.TriggerField;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.google.gwt.user.client.Element;
public class MultiSelectComboBox extends TriggerField {
private Dialog checkBoxListHolder;
private CheckBoxListView listView;
private ListStore store;
private String delimiter = ",";
private boolean readOnly;
public MultiSelectComboBox() {
store = new ListStore();
listView = new CheckBoxListView();
}
@Override
protected void onTriggerClick(ComponentEvent ce) {
super.onTriggerClick(ce);
if(readOnly) {
return;
}
checkBoxListHolder.setSize(getWidth(), 200);
listView.setWidth(getWidth());
checkBoxListHolder.setPosition(getAbsoluteLeft(),
getAbsoluteTop() + getHeight());
if(checkBoxListHolder.isVisible()) {
checkBoxListHolder.hide();
}
else {
checkBoxListHolder.show();
}
}
@Override
protected void onRender(Element target, int index) {
super.onRender(target, index);
checkBoxListHolder = new Dialog();
checkBoxListHolder.setClosable(false);
checkBoxListHolder.setHeaderVisible(false);
checkBoxListHolder.setFooter(false);
checkBoxListHolder.setFrame(false);
checkBoxListHolder.setResizable(false);
checkBoxListHolder.setAutoHide(false);
checkBoxListHolder.getButtonBar().setVisible(false);
checkBoxListHolder.setLayout(new FillLayout());
checkBoxListHolder.add(listView);
listView.setStore(store);
checkBoxListHolder.addWindowListener(new WindowListener(){
@Override
public void windowHide(WindowEvent we) {
setValue(parseCheckedValues(listView));
}
});
}
private String parseCheckedValues(CheckBoxListView checkBoxView) {
StringBuffer buf = new StringBuffer();
if(checkBoxView != null) {
List selected = checkBoxView.getChecked();
int index = 1, len = selected.size();
for(D c : selected) {
buf.append(c.get(listView.getDisplayProperty()));
if(index getListView() {
return listView;
}
public void setListView(CheckBoxListView listView) {
this.listView = listView;
}
public ListStore getStore() {
return store;
}
public void setStore(ListStore store) {
this.store = store;
}
public String getDelimiter() {
return delimiter;
}
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
}
public boolean isReadOnly() {
return readOnly;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
这里已经解释了代码...... http://bhat86.blogspot.com/2012/02/gxt-comobobox-with-multi-select-feature.html
谢谢!
答案 1 :(得分:0)
参考示例listview和advanced list view。在使用多选选项
开发组合框时,它们可能对您有所帮助