Search in sources :

Example 6 with Listbox

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

the class FindWindow method getColumnName.

/**
     * retrieve the columnName of the Column item selected
     * @param label label
    **/
private String getColumnName(ListItem row) {
    Listbox listColumn = (Listbox) row.getFellow("listColumn" + row.getId());
    String columnName = listColumn.getSelectedItem().getValue().toString();
    return columnName;
}
Also used : Listbox(org.adempiere.webui.component.Listbox)

Example 7 with Listbox

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

the class FindWindow method parseString.

/**
	 * 	Parse String
	 * 	@param field column
	 * 	@param in value
	 * @param to
	 * @param listItem
	 * 	@return data type corected value
	 */
private Component parseString(GridField field, String in, ListItem listItem, boolean to) {
    if (in == null)
        return null;
    int dt = field.getDisplayType();
    try {
        WEditor editor = null;
        if (field.isKey())
            editor = new WNumberEditor(field);
        else
            editor = WebEditorFactory.getEditor(field, true);
        if (editor == null)
            editor = new WStringEditor(field);
        //	Return Integer
        if (dt == DisplayType.Integer || (DisplayType.isID(dt) && field.getColumnName().endsWith("_ID"))) {
            int i = Integer.parseInt(in);
            editor.setValue(new Integer(i));
        } else //	Return BigDecimal
        if (DisplayType.isNumeric(dt)) {
            editor.setValue(DisplayType.getNumberFormat(dt).parse(in));
        } else //	Return Timestamp
        if (DisplayType.isDate(dt)) {
            long time = 0;
            try {
                time = DisplayType.getDateFormat_JDBC().parse(in).getTime();
                editor.setValue(new Timestamp(time));
            } catch (Exception e) {
                log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e);
                time = DisplayType.getDateFormat(dt).parse(in).getTime();
            }
            editor.setValue(new Timestamp(time));
        } else if (dt == DisplayType.YesNo)
            editor.setValue(Boolean.valueOf(in));
        else
            editor.setValue(in);
        editor.addValueChangeListener(this);
        boolean between = false;
        Listbox listOp = (Listbox) listItem.getFellow("listOperator" + listItem.getId());
        String betweenValue = listOp.getSelectedItem().getValue().toString();
        String opValue = MQuery.OPERATORS[MQuery.BETWEEN_INDEX].getValue();
        if (to && betweenValue != null && betweenValue.equals(opValue))
            between = true;
        boolean enabled = !to || (to && between);
        editor.setReadWrite(enabled);
        editor.setVisible(enabled);
        editor.dynamicDisplay();
        return editor.getComponent();
    } catch (Exception ex) {
        log.log(Level.SEVERE, "Object=" + in, ex);
        return null;
    }
}
Also used : WEditor(org.adempiere.webui.editor.WEditor) Listbox(org.adempiere.webui.component.Listbox) Timestamp(java.sql.Timestamp) WNumberEditor(org.adempiere.webui.editor.WNumberEditor) SQLException(java.sql.SQLException) IOException(java.io.IOException) WStringEditor(org.adempiere.webui.editor.WStringEditor)

Example 8 with Listbox

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

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

the class FindWindow method onEvent.

// addSelectionColumn
public void onEvent(Event event) throws Exception {
    if (Events.ON_SELECT.equals(event.getName())) {
        if (event.getTarget() instanceof Listbox) {
            ListItem row = (ListItem) (event.getTarget().getParent().getParent());
            Listbox listbox = (Listbox) event.getTarget();
            advancedPanel.setSelectedItem(row);
            Listbox listColumn = (Listbox) row.getFellow("listColumn" + row.getId());
            Listbox listOperator = (Listbox) row.getFellow("listOperator" + row.getId());
            if (listbox.getId().equals(listColumn.getId()) || listbox.getId().equals(listOperator.getId())) {
                if (listbox.getId().equals(listColumn.getId())) {
                    ListItem column = listColumn.getSelectedItem();
                    if (column != null) {
                        addOperators(column, listOperator);
                    }
                }
                Component componentFrom = getEditorCompQueryFrom(row);
                Component componentTo = getEditorCompQueryTo(row);
                addRowEditor(componentFrom, (ListCell) row.getFellow("cellQueryFrom" + row.getId()));
                addRowEditor(componentTo, (ListCell) row.getFellow("cellQueryTo" + row.getId()));
            }
        } else if (event.getTarget() == fQueryName) {
            int index = fQueryName.getSelectedIndex();
            if (index < 0) {
                if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                    return;
                }
            } else if (index == 0) {
                // no query - wipe and start over.
                List<?> rowList = advancedPanel.getChildren();
                for (int rowIndex = rowList.size() - 1; rowIndex >= 1; rowIndex--) rowList.remove(rowIndex);
                createFields();
                fQueryName.setSelectedIndex(-1);
                fQueryName.setText(m_sTipText);
            } else
                parseUserQuery(userQueries[index - 1]);
        }
    } else //
    if (Events.ON_CLICK.equals(event.getName())) {
        //  Toolbar Buttons actions
        if (event.getTarget() instanceof ToolBarButton) {
            ToolBarButton button = (ToolBarButton) event.getTarget();
            if ("btnNewAdv".equals(button.getAttribute("name").toString())) {
                createFields();
            } else if ("btnDeleteAdv".equals(button.getAttribute("name").toString())) {
                int index = advancedPanel.getSelectedIndex();
                if (index >= 0) {
                    cmd_delete();
                }
            } else if ("btnSaveAdv".equals(button.getAttribute("name").toString())) {
                // Save the query but don't overwrite the Last query
                cmd_save(false);
            }
        } else //  Confirm panel actions
        if (event.getTarget() instanceof Button) {
            Button btn = (Button) event.getTarget();
            if ("btnOkSimple".equals(btn.getName())) {
                cmd_ok_Simple();
                dispose();
            } else if ("btnOkAdv".equals(btn.getName())) {
                cmd_ok_Advanced();
                dispose();
            } else if ("btnCancel".equals(btn.getName())) {
                m_isCancel = true;
                dispose();
            } else if ("btnNew".equals(btn.getName())) {
                m_query = MQuery.getNoRecordQuery(m_tableName, true);
                m_total = 0;
                m_createNew = true;
                dispose();
            }
        }
    } else if (Events.ON_OK.equals(event.getName())) {
        if (winLookupRecord.equals(event.getTarget())) {
            cmd_ok_Simple();
            dispose();
        } else if (winAdvanced.equals(event.getTarget())) {
            cmd_ok_Advanced();
            dispose();
        }
        // Check simple panel fields
        for (WEditor editor : m_sEditors) {
            if (editor.getComponent() == event.getTarget()) {
                cmd_ok_Simple();
                dispose();
            }
        }
        // Check simple panel fields
        for (WEditor editor : m_sEditors2) {
            if (editor != null && editor.getComponent() == event.getTarget()) {
                cmd_ok_Simple();
                dispose();
            }
        }
    } else if (Events.ON_FOCUS.equals(event.getName())) {
        if (event.getTarget() == fQueryName) {
            // fQueryName received the focus - delete the tip text so the user can type without 
            // having to delete the tip.
            int index = fQueryName.getSelectedIndex();
            if (index < 0) {
                if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
                    fQueryName.setSelectedIndex(-1);
                    fQueryName.setText("");
                }
            }
        }
    } else if (Events.ON_BLUR.equals(event.getName())) {
        if (event.getTarget() == fQueryName) {
            // fQueryName lost the focus. If the field is blank, replace the tip text.
            if (fQueryName.getSelectedItem() != null && fQueryName.getSelectedItem().equals("")) {
                fQueryName.setText(m_sTipText);
            }
        }
    }
}
Also used : ToolBarButton(org.adempiere.webui.component.ToolBarButton) Button(org.adempiere.webui.component.Button) ToolBarButton(org.adempiere.webui.component.ToolBarButton) ListItem(org.adempiere.webui.component.ListItem) WEditor(org.adempiere.webui.editor.WEditor) Listbox(org.adempiere.webui.component.Listbox) Component(org.zkoss.zk.ui.Component)

Example 10 with Listbox

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

the class InfoPAttributePanel method dynInit.

//	jbInit
/**
	 * 	Dynamic Init of the Center Panel
	 */
private void dynInit() {
    addAttributes();
    boolean isGuarantee = true;
    boolean isSerial = true;
    boolean isLot = true;
    if (p_M_AttributeSet_ID > 0) {
        MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
        isGuarantee = as.isGuaranteeDate();
        isSerial = as.isSerNo();
        isLot = as.isLot();
    }
    //
    String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
    guaranteeDateSelection = new Listbox();
    guaranteeDateSelection.setRows(0);
    guaranteeDateSelection.setMultiple(false);
    guaranteeDateSelection.setMold("select");
    guaranteeDateSelection.setWidth("150px");
    guaranteeDateSelection.appendItem(s + " <", s + " <");
    guaranteeDateSelection.appendItem(s + " =", s + " =");
    guaranteeDateSelection.appendItem(s + " >", s + " >");
    guaranteeDateSelection.setAttribute("zk_component_ID", "InfoPAttributePanel_guaranteeDateSelection");
    initLotSelection();
    //	Fixed Instance Selection Fields
    Row row;
    Div div;
    if (isSerial) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(serNoLabel);
        row.appendChild(div);
        row.appendChild(serNoField.getComponent());
        serNoField.getComponent().setWidth("150px");
        serNoField.getComponent().setAttribute("zk_component_ID", "InfoPAttributePanel_serNoField");
    }
    if (isLot) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(lotLabel);
        row.appendChild(div);
        row.appendChild(lotField.getComponent());
        lotField.getComponent().setWidth("150px");
        lotField.getComponent().setAttribute("zk_component_ID", "InfoPAttributePanel_lotField");
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(lotLabel2);
        row.appendChild(div);
        row.appendChild(lotSelection);
    }
    if (isGuarantee) {
        row = new Row();
        rows.appendChild(row);
        div = new Div();
        div.setAlign("right");
        div.appendChild(guaranteeDateSelection);
        row.appendChild(div);
        row.appendChild(guaranteeDateField);
        guaranteeDateField.setAttribute("zk_component_ID", "InfoPAttributePanel_guaranteeDateField");
    }
}
Also used : Div(org.zkoss.zul.Div) Row(org.adempiere.webui.component.Row) Listbox(org.adempiere.webui.component.Listbox) MAttributeSet(org.compiere.model.MAttributeSet)

Aggregations

Listbox (org.adempiere.webui.component.Listbox)24 ListItem (org.adempiere.webui.component.ListItem)8 NumberBox (org.adempiere.webui.component.NumberBox)6 KeyNamePair (org.compiere.util.KeyNamePair)6 Label (org.adempiere.webui.component.Label)5 Row (org.adempiere.webui.component.Row)5 ResultSet (java.sql.ResultSet)4 Button (org.adempiere.webui.component.Button)4 MAttributeSet (org.compiere.model.MAttributeSet)4 Component (org.zkoss.zk.ui.Component)4 Div (org.zkoss.zul.Div)4 PreparedStatement (java.sql.PreparedStatement)3 Timestamp (java.sql.Timestamp)3 Textbox (org.adempiere.webui.component.Textbox)3 ToolBarButton (org.adempiere.webui.component.ToolBarButton)3 WEditor (org.adempiere.webui.editor.WEditor)3 WNumberEditor (org.adempiere.webui.editor.WNumberEditor)3 WStringEditor (org.adempiere.webui.editor.WStringEditor)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2