Search in sources :

Example 16 with Checkbox

use of org.adempiere.webui.component.Checkbox in project adempiere by adempiere.

the class WBrowserListItemRenderer method getCellComponent.

/**
	 * Generate the cell for the given <code>field</code>.
	 *
	 * @param table 	The table into which the cell will be placed.
	 * @param field		The data field for which the cell is to be created.
	 * @param rowIndex	The row in which the cell is to be placed.
	 * @param columnIndex	The column in which the cell is to be placed.
	 * @return	The list cell component.
	 */
private Listcell getCellComponent(WBrowserTable table, Object field, int rowIndex, int columnIndex) {
    ListCell listcell = new ListCell();
    if (table == null)
        return listcell;
    BrowserRow browserRows = table.getData();
    //	BR [ 257 ]
    MBrowseField browseField = browserRows.getBrowserField(browserRows.getTableIndex(columnIndex));
    if (browseField == null)
        return listcell;
    //	
    GridField gridField = table.getGridFieldAt(rowIndex, columnIndex);
    boolean isColumnVisible = true;
    if (!m_tableColumns.isEmpty())
        isColumnVisible = isColumnVisible(getColumn(columnIndex));
    // are assigned to Table Columns
    if (isColumnVisible && gridField != null) {
        //	Set Read Only
        boolean isCellEditable = table.isCellEditable(rowIndex, columnIndex);
        //	
        if (DisplayType.YesNo == browseField.getAD_Reference_ID()) {
            //	BR [ 347 ]
            boolean selected = false;
            if (field != null) {
                selected = Boolean.valueOf(field.toString());
            }
            listcell.setValue(selected);
            if (columnIndex == 0)
                table.setCheckmark(false);
            Checkbox checkbox = new Checkbox();
            checkbox.setChecked(selected);
            if (isCellEditable) {
                checkbox.setEnabled(true);
                checkbox.addEventListener(Events.ON_CHECK, this);
            } else {
                checkbox.setEnabled(false);
            }
            listcell.appendChild(checkbox);
            ZkCssHelper.appendStyle(listcell, "text-align:center");
        } else if ((DisplayType.isNumeric(browseField.getAD_Reference_ID())) && !browseField.isKey()) {
            DecimalFormat format = field instanceof BigDecimal ? DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx())) : DisplayType.getNumberFormat(DisplayType.Integer, AEnv.getLanguage(Env.getCtx()));
            // set cell value to allow sorting
            listcell.setValue((field == null ? "0" : field.toString()));
            if (isCellEditable) {
                NumberBox numberbox = new NumberBox(false);
                numberbox.setFormat(format);
                numberbox.setValue(field);
                numberbox.setWidth("100px");
                numberbox.setStyle("text-align:right; " + listcell.getStyle());
                numberbox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(numberbox);
                numberbox.setEnabled(true);
            } else {
                listcell.setLabel(format.format(((Number) (field == null ? Env.ZERO : field)).doubleValue()));
                ZkCssHelper.appendStyle(listcell, "text-align:right");
            }
        } else if (DisplayType.Date == browseField.getAD_Reference_ID() || DisplayType.DateTime == browseField.getAD_Reference_ID()) {
            if (field != null) {
                SimpleDateFormat dateFormat = DisplayType.getDateFormat(browseField.getAD_Reference_ID(), AEnv.getLanguage(Env.getCtx()));
                //	BR [ 270 ]
                listcell.setValue(dateFormat.format(field));
                if (isCellEditable) {
                    Datebox datebox = new Datebox();
                    datebox.setFormat(dateFormat.toPattern());
                    //	
                    datebox.setValue((Date) field);
                    datebox.addEventListener(Events.ON_CHANGE, this);
                    listcell.appendChild(datebox);
                } else {
                    listcell.setLabel(dateFormat.format(field));
                }
            }
        } else //	Add support to other String
        if (browseField.getAD_Reference_ID() == DisplayType.String || browseField.getAD_Reference_ID() == DisplayType.PrinterName || browseField.getAD_Reference_ID() == DisplayType.Text || browseField.getAD_Reference_ID() == DisplayType.TextLong) {
            listcell.setValue((field == null ? "" : field.toString()));
            if (isCellEditable) {
                Textbox textbox = new Textbox();
                textbox.setValue((field == null ? "" : field.toString()));
                textbox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(textbox);
            } else {
                listcell.setLabel((field == null ? "" : field.toString()));
            }
        } else if (field instanceof org.adempiere.webui.component.Combobox) {
            listcell.setValue(field);
            if (isCellEditable) {
                Combobox combobox = (Combobox) field;
                combobox.addEventListener(Events.ON_CHANGE, this);
                listcell.appendChild(combobox);
            } else {
                Combobox combobox = (Combobox) field;
                if (combobox != null && combobox.getItemCount() > 0) {
                    if (combobox.getSelectedIndex() >= 0)
                        listcell.setLabel((String) combobox.getItemAtIndex(combobox.getSelectedIndex()).getLabel());
                    else
                        listcell.setLabel("");
                }
            }
        } else if (field instanceof org.adempiere.webui.component.Button) {
            listcell.setValue(field);
            if (isCellEditable) {
                Button button = (Button) field;
                button.addEventListener(Events.ON_CLICK, this);
                listcell.appendChild(button);
            } else {
                Button button = (Button) field;
                if (button != null) {
                    listcell.setLabel("");
                }
            }
        } else // if ID column make it invisible
        if (field instanceof IDColumn && browseField.isKey()) {
            IDColumn id = (IDColumn) field;
            if (id != null && id.getRecord_ID() != null) {
                listcell.setValue(id.getRecord_ID());
                if (!table.isCheckmark()) {
                    table.setCheckmark(true);
                    table.removeEventListener(Events.ON_SELECT, this);
                    table.addEventListener(Events.ON_SELECT, this);
                }
            }
        } else if ((DisplayType.isLookup(browseField.getAD_Reference_ID()) || DisplayType.ID == browseField.getAD_Reference_ID()) && !browseField.isKey()) {
            if (isCellEditable) {
                WEditor editor = WebEditorFactory.getEditor(gridField, true);
                editor.addValueChangeListener(this);
                editor.dynamicDisplay();
                editor.setReadWrite(true);
                editor.fillHorizontal();
                gridField.addPropertyChangeListener(editor);
                listcell.appendChild(editor.getComponent());
            } else {
                Component component;
                if (gridField.getDisplayType() == DisplayType.YesNo) {
                    component = createReadonlyCheckbox(field);
                } else {
                    String text = getDisplayText(field, gridField);
                    Label label = new Label();
                    setLabelText(text, label);
                    component = label;
                }
                listcell.appendChild(component);
            }
        } else {
            listcell.setLabel((field == null ? null : field.toString()));
            listcell.setValue((field == null ? null : field.toString()));
        }
    } else {
        listcell.setLabel("");
        listcell.setValue("");
    }
    listcell.setAttribute("zk_component_ID", "ListItem_Cell_" + rowIndex + "_" + columnIndex);
    return listcell;
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) Datebox(org.adempiere.webui.component.Datebox) Button(org.adempiere.webui.component.Button) Combobox(org.adempiere.webui.component.Combobox) ListCell(org.adempiere.webui.component.ListCell) DecimalFormat(java.text.DecimalFormat) Textbox(org.adempiere.webui.component.Textbox) Label(org.zkoss.zhtml.Label) GridField(org.compiere.model.GridField) NumberBox(org.adempiere.webui.component.NumberBox) WEditor(org.adempiere.webui.editor.WEditor) BigDecimal(java.math.BigDecimal) IDColumn(org.compiere.minigrid.IDColumn) Button(org.adempiere.webui.component.Button) Checkbox(org.adempiere.webui.component.Checkbox) Component(org.zkoss.zk.ui.Component) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with Checkbox

use of org.adempiere.webui.component.Checkbox in project adempiere by adempiere.

the class WBrowserListItemRenderer method createReadonlyCheckbox.

/**
	 * Create a Read Only CheckBox
	 * @param value
	 * @return
	 */
private Component createReadonlyCheckbox(Object value) {
    Checkbox checkBox = new Checkbox();
    if (value != null && "true".equalsIgnoreCase(value.toString()))
        checkBox.setChecked(true);
    else
        checkBox.setChecked(false);
    checkBox.setDisabled(true);
    return checkBox;
}
Also used : Checkbox(org.adempiere.webui.component.Checkbox)

Example 18 with Checkbox

use of org.adempiere.webui.component.Checkbox in project adempiere by adempiere.

the class WBOMDrop method addDisplay.

//	addBOMLine
/**
	 * 	Add Line to Display
	 *	@param parentM_Product_ID parent product
	 *	@param M_Product_ID product
	 *	@param bomType bom type
	 *	@param name name
	 *	@param lineQty qty
	 */
private void addDisplay(int parentM_Product_ID, int M_Product_ID, String bomType, String name, BigDecimal lineQty) {
    log.fine("M_Product_ID=" + M_Product_ID + ",Type=" + bomType + ",Name=" + name + ",Qty=" + lineQty);
    boolean selected = true;
    Hbox boxQty = new Hbox();
    boxQty.setWidth("100%");
    boxQty.setWidths("10%, 40%, 50%");
    if (MProductBOM.BOMTYPE_StandardPart.equals(bomType)) {
        String title = "";
        Checkbox cb = new Checkbox();
        cb.setLabel(title);
        cb.setChecked(true);
        cb.setEnabled(false);
        m_selectionList.add(cb);
        boxQty.appendChild(cb);
    } else if (MProductBOM.BOMTYPE_OptionalPart.equals(bomType)) {
        String title = Msg.getMsg(Env.getCtx(), "Optional");
        Checkbox cb = new Checkbox();
        cb.setLabel(title);
        cb.setChecked(false);
        selected = false;
        cb.addEventListener(Events.ON_CHECK, this);
        m_selectionList.add(cb);
        boxQty.appendChild(cb);
    } else //	Alternative
    {
        String title = Msg.getMsg(Env.getCtx(), "Alternative") + " " + bomType;
        Radio b = new Radio();
        b.setLabel(title);
        String groupName = String.valueOf(parentM_Product_ID) + "_" + bomType;
        Radiogroup group = m_buttonGroups.get(groupName);
        if (group == null) {
            log.fine("ButtonGroup=" + groupName);
            group = new Radiogroup();
            m_buttonGroups.put(groupName, group);
            group.appendChild(b);
            //	select first one
            b.setSelected(true);
        } else {
            group.appendChild(b);
            b.setSelected(false);
            selected = false;
        }
        b.addEventListener(Events.ON_CLICK, this);
        m_selectionList.add(b);
        boxQty.appendChild(b);
    }
    //	Add to List & display
    m_productList.add(new Integer(M_Product_ID));
    Decimalbox qty = new Decimalbox();
    qty.setValue(lineQty);
    qty.setReadonly(!selected);
    m_qtyList.add(qty);
    Label label = new Label(name);
    HtmlBasedComponent c = (HtmlBasedComponent) label.rightAlign();
    c.setStyle(c.getStyle() + ";margin-right: 5px");
    boxQty.appendChild(c);
    boxQty.appendChild(qty);
    grpSelectProd.appendChild(boxQty);
}
Also used : Hbox(org.zkoss.zul.Hbox) Decimalbox(org.zkoss.zul.Decimalbox) Checkbox(org.adempiere.webui.component.Checkbox) Radiogroup(org.zkoss.zul.Radiogroup) Label(org.adempiere.webui.component.Label) Radio(org.zkoss.zul.Radio) HtmlBasedComponent(org.zkoss.zk.ui.HtmlBasedComponent)

Aggregations

Checkbox (org.adempiere.webui.component.Checkbox)18 Textbox (org.adempiere.webui.component.Textbox)8 Component (org.zkoss.zk.ui.Component)7 Label (org.adempiere.webui.component.Label)6 Datebox (org.adempiere.webui.component.Datebox)5 DecimalFormat (java.text.DecimalFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Combobox (org.adempiere.webui.component.Combobox)3 NumberBox (org.adempiere.webui.component.NumberBox)3 Button (org.adempiere.webui.component.Button)2 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)2 IDColumn (org.compiere.minigrid.IDColumn)2 Decimalbox (org.zkoss.zul.Decimalbox)2 Hbox (org.zkoss.zul.Hbox)2 Panelchildren (org.zkoss.zul.Panelchildren)2 Radio (org.zkoss.zul.Radio)2 Radiogroup (org.zkoss.zul.Radiogroup)2 Toolbar (org.zkoss.zul.Toolbar)2 Tree (org.zkoss.zul.Tree)2 BigDecimal (java.math.BigDecimal)1