Search in sources :

Example 1 with ListCell

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

the class FindWindow method createFields.

/**
     * create respective fields in the advanced window tab
     *
    **/
private void createFields(String[] fields, int row) {
    ListItem listItem = new ListItem();
    listItem.setWidth("100%");
    Listbox listColumn = new Listbox();
    listColumn.setId("listColumn" + listItem.getId());
    listColumn.setName("listColumn");
    listColumn.setMold("select");
    listColumn.setRows(0);
    listColumn.addEventListener(Events.ON_SELECT, this);
    Listbox listOperator = new Listbox();
    listOperator.setId("listOperator" + listItem.getId());
    listOperator.setName("listOperator");
    listOperator.setMold("select");
    listOperator.setRows(0);
    listOperator.addEventListener(Events.ON_SELECT, this);
    Listbox listAndOr = new Listbox();
    listAndOr.setId("listAndOr" + listItem.getId());
    listAndOr.setName("listAndOr");
    listAndOr.setMold("select");
    listAndOr.setRows(0);
    listAndOr.addEventListener(Events.ON_SELECT, this);
    Listbox listLeftBracket = new Listbox();
    listLeftBracket.setId("listLeftBracket" + listItem.getId());
    listLeftBracket.setName("listLeftBracket");
    listLeftBracket.setMold("select");
    listLeftBracket.setRows(0);
    listLeftBracket.addEventListener(Events.ON_SELECT, this);
    Listbox listRightBracket = new Listbox();
    listRightBracket.setId("listRightBracket" + listItem.getId());
    listRightBracket.setName("listRightBracket");
    listRightBracket.setMold("select");
    listRightBracket.setRows(0);
    listRightBracket.addEventListener(Events.ON_SELECT, this);
    setValues(listColumn, listOperator, fields);
    // And Or
    ValueNamePair[] andOr = new ValueNamePair[] { new ValueNamePair("", ""), new ValueNamePair("AND", Msg.getMsg(Env.getCtx(), "AND")), new ValueNamePair("OR", Msg.getMsg(Env.getCtx(), "OR")) };
    for (ValueNamePair item : andOr) listAndOr.appendItem(item.getName(), item.getValue());
    if (row <= 0) {
        // don't show item on the first row.
        listAndOr.setSelectedIndex(0);
        listAndOr.setVisible(false);
    } else {
        //And - default
        listAndOr.setSelectedIndex(1);
        listAndOr.setVisible(true);
    }
    // Left Bracket
    ValueNamePair[] leftBracket = new ValueNamePair[] { new ValueNamePair("", ""), new ValueNamePair("(", "("), new ValueNamePair("((", "(("), new ValueNamePair("(((", "(((") };
    for (ValueNamePair item : leftBracket) listLeftBracket.appendItem(item.getName(), item.getValue());
    listLeftBracket.setSelectedIndex(0);
    // Right Bracket
    ValueNamePair[] rightBracket = new ValueNamePair[] { new ValueNamePair("", ""), new ValueNamePair(")", ")"), new ValueNamePair("))", "))"), new ValueNamePair(")))", ")))") };
    for (ValueNamePair item : rightBracket) listRightBracket.appendItem(item.getName(), item.getValue());
    listRightBracket.setSelectedIndex(0);
    ListCell cellColumn = new ListCell();
    cellColumn.appendChild(listColumn);
    cellColumn.setId("cellColumn" + listItem.getId());
    ListCell cellOperator = new ListCell();
    cellOperator.appendChild(listOperator);
    cellOperator.setId("cellOperator" + listItem.getId());
    ListCell cellQueryFrom = new ListCell();
    cellQueryFrom.setId("cellQueryFrom" + listItem.getId());
    ListCell cellQueryTo = new ListCell();
    cellQueryTo.setId("cellQueryTo" + listItem.getId());
    ListCell cellAndOr = new ListCell();
    cellAndOr.appendChild(listAndOr);
    cellAndOr.setId("cellAndOr" + listItem.getId());
    ListCell cellLeftBracket = new ListCell();
    cellLeftBracket.appendChild(listLeftBracket);
    cellLeftBracket.setId("cellLeftBracket" + listItem.getId());
    ListCell cellRightBracket = new ListCell();
    cellRightBracket.appendChild(listRightBracket);
    cellRightBracket.setId("cellRightBracket" + listItem.getId());
    listItem.appendChild(cellAndOr);
    listItem.appendChild(cellLeftBracket);
    listItem.appendChild(cellColumn);
    listItem.appendChild(cellOperator);
    listItem.appendChild(cellQueryFrom);
    listItem.appendChild(cellQueryTo);
    listItem.appendChild(cellRightBracket);
    advancedPanel.appendChild(listItem);
    advancedPanel.setSelectedItem(listItem);
    if (fields != null) {
        // QueryFrom
        String columnName = listColumn.getSelectedItem().getValue().toString();
        if (columnName == null || columnName == "")
            return;
        String value = fields.length > INDEX_VALUE ? fields[INDEX_VALUE] : "";
        if (value.length() > 0) {
            // Elaine 2009/03/16 - set attribute value
            cellQueryFrom.setAttribute("value", value);
            cellQueryFrom.appendChild(parseString(getTargetMField(columnName), value, listItem, false));
        }
        // QueryTo
        String value2 = fields.length > INDEX_VALUE2 ? fields[INDEX_VALUE2] : "";
        if (value2.length() > 0) {
            // Elaine 2009/03/16 - set attribute value
            cellQueryTo.setAttribute("value", value);
            cellQueryTo.appendChild(parseString(getTargetMField(columnName), value2, listItem, true));
        }
        // AndOr
        String sandOr = fields.length > INDEX_ANDOR ? fields[INDEX_ANDOR] : "";
        if (sandOr.length() > 0) {
            for (int i = 0; i < listAndOr.getItems().size(); i++) {
                if (listAndOr.getItemAtIndex(i).getValue().equals(sandOr)) {
                    listAndOr.setSelectedIndex(i);
                    break;
                }
            }
        }
        // Left Bracket
        String sLeftBracket = fields.length > INDEX_LEFTBRACKET ? fields[INDEX_LEFTBRACKET] : "";
        if (sLeftBracket.length() > 0) {
            for (int i = 0; i < listLeftBracket.getItems().size(); i++) {
                if (listLeftBracket.getItemAtIndex(i).getValue().equals(sLeftBracket)) {
                    listLeftBracket.setSelectedIndex(i);
                    break;
                }
            }
        }
        // Right Bracket
        String sRightBracket = fields.length > INDEX_RIGHTBRACKET ? fields[INDEX_RIGHTBRACKET] : "";
        if (sRightBracket.length() > 0) {
            for (int i = 0; i < listRightBracket.getItems().size(); i++) {
                if (listRightBracket.getItemAtIndex(i).getValue().equals(sRightBracket)) {
                    listRightBracket.setSelectedIndex(i);
                    break;
                }
            }
        }
    }
}
Also used : ListCell(org.adempiere.webui.component.ListCell) ListItem(org.adempiere.webui.component.ListItem) ValueNamePair(org.compiere.util.ValueNamePair) Listbox(org.adempiere.webui.component.Listbox)

Example 2 with ListCell

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

the class FindWindow method codeUserQuery.

//	cmd_save
/**
     * Code the query parameters entered in the table into a string that can be saved in the database.
     * This is the counterpart to {@link #parseUserQuery()}. Also updates the {@link #m_query} variable with 
     * the current query information.
     * @return a StringBuffer containing the coded query information.
     */
private StringBuffer codeUserQuery() {
    m_query = new MQuery(m_tableName);
    StringBuffer code = new StringBuffer();
    int openBrackets = 0;
    List<?> rowList = advancedPanel.getChildren();
    for (int rowIndex = 1; rowIndex < rowList.size(); rowIndex++) {
        //  Column
        ListItem row = (ListItem) rowList.get(rowIndex);
        Listbox column = (Listbox) row.getFellow("listColumn" + row.getId());
        if (column == null)
            continue;
        String ColumnName = column.getSelectedItem().getValue().toString();
        String infoName = column.toString();
        //
        GridField field = getTargetMField(ColumnName);
        if (field == null)
            // Elaine 2008/07/29
            continue;
        boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
        String ColumnSQL = field.getColumnSQL(false);
        // Left brackets
        Listbox listLeftBracket = (Listbox) row.getFellow("listLeftBracket" + row.getId());
        String lBrackets = listLeftBracket.getSelectedItem().getValue().toString();
        if (lBrackets != null)
            openBrackets += lBrackets.length();
        // Right brackets
        Listbox listRightBracket = (Listbox) row.getFellow("listRightBracket" + row.getId());
        String rBrackets = listRightBracket.getSelectedItem().getValue().toString();
        if (rBrackets != null)
            openBrackets -= rBrackets.length();
        // And Or
        Listbox listAndOr = (Listbox) row.getFellow("listAndOr" + row.getId());
        String andOr = listAndOr.getSelectedItem().getValue().toString();
        boolean and = true;
        if (rowIndex > 1) {
            and = !"OR".equals(andOr);
        }
        //  Op
        Listbox op = (Listbox) row.getFellow("listOperator" + row.getId());
        if (op == null)
            continue;
        String Operator = op.getSelectedItem().getValue().toString();
        //  Value   ******
        ListCell cellQueryFrom = (ListCell) row.getFellow("cellQueryFrom" + row.getId());
        Object value = cellQueryFrom.getAttribute("value");
        ListCell cellQueryTo = (ListCell) row.getFellow("cellQueryTo" + row.getId());
        Object value2 = cellQueryTo.getAttribute("value");
        if (value == null) {
            // Capture the case "is null" ?
            if (MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op)) {
                m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets);
            } else {
                continue;
            }
        } else {
            // Value has a value - check for range too.
            Object parsedValue = parseValue(field, value);
            if (parsedValue == null)
                continue;
            //TODO - verify compatibility with find.java
            if (field.isEncryptedColumn()) {
                value = SecureEngine.encrypt(value);
            }
            String infoDisplay = value.toString();
            if (field.isLookup())
                infoDisplay = field.getLookup().getDisplay(value);
            else if (field.getDisplayType() == DisplayType.YesNo)
                infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay);
            //  Value2  ******
            if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op.getSelectedItem().toValueNamePair())) {
                if (value2 == null)
                    continue;
                Object parsedValue2 = parseValue(field, value2);
                String infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                //encrypt the value if we are searching an encrypted column.
                if (field.isEncryptedColumn()) {
                    value2 = SecureEngine.encrypt(value2);
                }
                m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, infoName, infoDisplay, infoDisplay_to, and, openBrackets);
            } else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
                if (!(parsedValue instanceof Integer)) {
                    continue;
                }
                m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
            } else
                m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets);
        }
        if (code.length() > 0)
            code.append(SEGMENT_SEPARATOR);
        code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append(value.toString()).append(FIELD_SEPARATOR).append(value2 != null ? value2.toString() : "").append(FIELD_SEPARATOR).append(andOr).append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
    }
    return code;
}
Also used : ListCell(org.adempiere.webui.component.ListCell) MQuery(org.compiere.model.MQuery) ListItem(org.adempiere.webui.component.ListItem) GridField(org.compiere.model.GridField) Listbox(org.adempiere.webui.component.Listbox)

Example 3 with ListCell

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

the class FindWindow method valueChange.

//  getTotalRecords
public void valueChange(ValueChangeEvent evt) {
    if (evt != null && evt.getSource() instanceof WEditor) {
        WEditor editor = (WEditor) evt.getSource();
        // Editor component
        Component component = editor.getComponent();
        ListCell listcell = (ListCell) component.getParent();
        listcell.setAttribute("value", evt.getNewValue());
    }
}
Also used : ListCell(org.adempiere.webui.component.ListCell) WEditor(org.adempiere.webui.editor.WEditor) Component(org.zkoss.zk.ui.Component)

Example 4 with ListCell

use of org.adempiere.webui.component.ListCell 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 5 with ListCell

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

the class WBrowserListItemRenderer method newListcell.

/* (non-Javadoc)
	 * @see org.zkoss.zul.ListitemRendererExt#newListcell(org.zkoss.zul.Listitem)
	 */
public Listcell newListcell(Listitem item) {
    ListCell cell = new ListCell();
    cell.applyProperties();
    return cell;
}
Also used : ListCell(org.adempiere.webui.component.ListCell)

Aggregations

ListCell (org.adempiere.webui.component.ListCell)5 ListItem (org.adempiere.webui.component.ListItem)2 Listbox (org.adempiere.webui.component.Listbox)2 WEditor (org.adempiere.webui.editor.WEditor)2 GridField (org.compiere.model.GridField)2 Component (org.zkoss.zk.ui.Component)2 BigDecimal (java.math.BigDecimal)1 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 MBrowseField (org.adempiere.model.MBrowseField)1 Button (org.adempiere.webui.component.Button)1 Checkbox (org.adempiere.webui.component.Checkbox)1 Combobox (org.adempiere.webui.component.Combobox)1 Datebox (org.adempiere.webui.component.Datebox)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Textbox (org.adempiere.webui.component.Textbox)1 IDColumn (org.compiere.minigrid.IDColumn)1 MQuery (org.compiere.model.MQuery)1 ValueNamePair (org.compiere.util.ValueNamePair)1 Label (org.zkoss.zhtml.Label)1