GXT - 具有多选功能的 ComoboBox

发布于 2025-01-06 08:54:09 字数 217 浏览 1 评论 0原文

我的任务是设计一个具有多选功能的大小组合框(GXT)控件。我尝试使用 ComboBox 的 setView 设置 CheckBoxListView 但似乎不起作用。如果有什么方法可以使用 GXT 框架来实现这一目标,有人可以指导我吗?

PS:我在sencha论坛(java类,源代码)中找到了一个名为XComboBox的组件,它运行良好,但不能在GNU GPL许可下用作它,

提前致谢!

I have a task to design a control of size ComboBox (GXT) with Multi-select feature. I tried to set CheckBoxListView using setView of ComboBox but did not seemed to work. Can anybody please guide me if there is any way using the GXT framework I can achieve this?

PS: I found a component called XComboBox in sencha forum (java class, source code) which works good, but cant be used as its under GNU GPL License

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春庭雪 2025-01-13 08:54:09

感谢@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

谢谢!

Thanks @smiletolead for your guidance, I found a solution by integrating Dialog with CheckBoxListView and TriggerField class.

The complete code listing is..



    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;
        }


    }

The code has been explained here...
http://bhat86.blogspot.com/2012/02/gxt-comobobox-with-multi-select-feature.html

Thank you!

陌路终见情 2025-01-13 08:54:09

请参阅示例 listview高级列表视图。它们可能对您开发具有多选选项的组合框有一些帮助

Refer the examples listview and advanced list view. They may be of some help to you in developing combobox with multi select option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文