Revision history [back]

click to hide/show revision 1
initial version

answered 2012-09-27 08:43:13 +0800

terrytornado gravatar image terrytornado flag of Germany

http://www.oxitec.de/

Implement an own checkAll mechanism in your ItemRenderer.

image

All code pieces are in the custom ListItemRenderer class.

        Listhead listhead = new Listhead();
        listhead.setParent(lb);

        // Delete marker Checkbox
        lh = new Listheader();
        lh.setWidth("55px");
        lh.setParent(listhead);
        hbox = new Hbox();
        hbox.setParent(lh);
        ckbDeleteAll = new Checkbox();
        ckbDeleteAll.setParent(hbox);
        ckbDeleteAll.setChecked(false);
        ckbDeleteAll.setStyle("padding-left: 2px; padding-right: 3px;");
        ckbDeleteAll.setTooltiptext("select all items for deleting ");
        ckbDeleteAll.addEventListener("onCheck", new CheckAllListener());
        img = new Image();
        img.setSrc(imgTrash);
        img.setParent(hbox);





            @Override
            public void render(Listitem item, Object data) throws Exception {

                MyBean obj = (MyBean) data;

                Listcell lc;
                Image img;
                Label lb;
                Checkbox cb;
                A a;

                // Delete Checkbox
                lc = new Listcell();
                cb = new Checkbox();
                cb.setParent(lc);
                cb.setChecked(false);
                cb.setStyle("padding-left: 3px;");
                cb.setTooltiptext("check it for delete");

         . . .





    /**
     * Inner Listener class.<br>
     * onCheck for the 'mark all for deleting' Checkbox.
     * 
     * @author Stephan Gerth
     */
    private final class CheckAllListener implements SerializableEventListener {
        private static final long serialVersionUID = 1L;

        @Override
        public void onEvent(Event event) throws Exception {

            Checkbox ckb = (Checkbox) event.getTarget();

            if (ckb.isChecked())
                checkAllItems(true);
            else
                checkAllItems(false);
        }
    }






    /**
     * EN: Checks/unchecks all items as marked for deleting.<br>
     * DE: Checked/unChecked alle Datensetze als zum loeschen markiert.<br>
     */
    @SuppressWarnings("unchecked")
    public void checkAllItems(boolean checkAll) {

        List<Listitem> list = lb.getItems();

        if (list.size() > 0) {
            for (Listitem li : list) {
                if (li.getFirstChild().getFirstChild() instanceof Checkbox) {
                    Checkbox cb = (Checkbox) li.getFirstChild().getFirstChild();
                    cb.setChecked(checkAll);
                }
            }
        }
    }





    /**
     * EN: Deletes the records which checkbox is marked for delete.<br>
     * DE: Loescht alle zum loeschen markierten Datensaetze.<br>
     */
    @SuppressWarnings("unchecked")
    public void deleteMarkedItems() {

        List<Listitem> list = lb.getItems();

        if (list.size() > 0) {

            for (Listitem li : list) {
                if (li.getFirstChild().getFirstChild() instanceof Checkbox) {
                    Checkbox cb = (Checkbox) li.getFirstChild().getFirstChild();
                    if (cb.isChecked()) {

                        Call entity = (Call) li.getValue();

                                              // Your delete stuff here
                        getMyDBService().delete(entity);

                    }
                }
            }
        }
    }

best Stephan

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More