Search in sources :

Example 11 with Listbox

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

the class InfoPAttributePanel method addAttributes.

//	dynInit
/**
	 * 	Add Attributes
	 *	@return rows
	 */
private int addAttributes() {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String whereAttributeSet;
    if (p_M_AttributeSet_ID > 0)
        whereAttributeSet = "AND M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID=" + p_M_AttributeSet_ID + ")";
    else
        whereAttributeSet = "";
    String sql = MRole.getDefault().addAccessSQL("SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute " + "FROM M_Attribute " + "WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY IsInstanceAttribute, Name", "M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    boolean instanceLine = false;
    boolean productLine = false;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            int attribute_ID = rs.getInt(1);
            String name = rs.getString(2);
            String description = rs.getString(3);
            String attributeValueType = rs.getString(4);
            boolean isInstanceAttribute = "Y".equals(rs.getString(5));
            // Add label for product attributes if there are any
            if (!productLine && !isInstanceAttribute) {
                Row row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Label group = new Label(Msg.translate(Env.getCtx(), "IsProductAttribute"));
                row.appendChild(group);
                rows.appendChild(row);
                row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Separator separator = new Separator();
                separator.setBar(true);
                row.appendChild(separator);
                rows.appendChild(row);
                productLine = true;
            }
            //	Add label for Instances attributes
            if (!instanceLine && isInstanceAttribute) {
                Row row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
                row.appendChild(group);
                rows.appendChild(row);
                row = new Row();
                rows.appendChild(row);
                row.setSpans("2");
                Separator separator = new Separator();
                separator.setBar(true);
                row.appendChild(separator);
                rows.appendChild(row);
                instanceLine = true;
            }
            //
            Row row = new Row();
            rows.appendChild(row);
            Label label = new Label(name);
            if (description != null && description.length() > 0)
                label.setTooltiptext(description);
            Div div = new Div();
            div.setAlign("right");
            div.appendChild(label);
            row.appendChild(div);
            Component field = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
                field = new Listbox();
                ((Listbox) field).setRows(0);
                ((Listbox) field).setMultiple(false);
                ((Listbox) field).setMold("select");
                ((Listbox) field).setWidth("150px");
                KeyNamePair[] knp = getAttributeList(attribute_ID);
                for (int i = 0; i < knp.length; i++) ((Listbox) field).appendItem(knp[i].getName(), knp[i]);
            } else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
                field = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
                ((NumberBox) field).setWidth("150px");
            } else {
                field = new WStringEditor(name, false, false, true, 10, 40, null, null).getComponent();
                ((Textbox) field).setWidth("150px");
            }
            row.appendChild(field);
            //
            field.setId(String.valueOf(attribute_ID));
            // If name is null, replace it with "_"
            if (name.equals("")) {
                name = "_";
            }
            field.setAttribute("zk_component_ID", "InfoPAttributePanel_field_" + name.replaceAll("[^a-zA-Z0-9_]", "_"));
            //
            if (isInstanceAttribute)
                m_instanceEditors.add(field);
            else
                m_productEditors.add(field);
            //	To (numbers)
            Component fieldTo = null;
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
                fieldTo = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
                ((NumberBox) fieldTo).setWidth("150px");
                row = new Row();
                rows.appendChild(row);
                div = new Div();
                div.setAlign("right");
                div.appendChild(new Label("-"));
                row.appendChild(div);
                row.appendChild(fieldTo);
            }
            if (fieldTo != null)
                fieldTo.setAttribute("zk_component_ID", "InfoPAttributePanel_fieldTo_" + name);
            if (isInstanceAttribute)
                m_instanceEditorsTo.add(fieldTo);
            else
                m_productEditorsTo.add(fieldTo);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    // print instance line if not printed
    if (!instanceLine) {
        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();
        }
        if (isGuarantee || isSerial || isLot) {
            Row row = new Row();
            rows.appendChild(row);
            row.setSpans("2");
            Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
            row.appendChild(group);
            rows.appendChild(row);
            row = new Row();
            rows.appendChild(row);
            row.setSpans("2");
            Separator separator = new Separator();
            separator.setBar(true);
            row.appendChild(separator);
            rows.appendChild(row);
            instanceLine = true;
        }
    }
    return 0;
}
Also used : Label(org.adempiere.webui.component.Label) PreparedStatement(java.sql.PreparedStatement) NumberBox(org.adempiere.webui.component.NumberBox) WStringEditor(org.adempiere.webui.editor.WStringEditor) MAttributeSet(org.compiere.model.MAttributeSet) Div(org.zkoss.zul.Div) ResultSet(java.sql.ResultSet) Row(org.adempiere.webui.component.Row) KeyNamePair(org.compiere.util.KeyNamePair) Component(org.zkoss.zk.ui.Component) Listbox(org.adempiere.webui.component.Listbox) Separator(org.zkoss.zul.Separator) WNumberEditor(org.adempiere.webui.editor.WNumberEditor)

Example 12 with Listbox

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

the class InfoPAttributePanel method initLotSelection.

//	getAttributeList
/**
	 * 	Initialize Lot Selection
	 */
private void initLotSelection() {
    ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
    list.add(new KeyNamePair(-1, ""));
    String whereAttributeSet;
    if (p_M_AttributeSet_ID > 0)
        whereAttributeSet = "AND M_Product_ID IN (SELECT M_Product_ID FROM M_Product WHERE M_AttributeSet_ID=" + p_M_AttributeSet_ID + ")";
    else
        whereAttributeSet = "";
    String sql = MRole.getDefault().addAccessSQL("SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY 2", "M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Create List
    KeyNamePair[] items = new KeyNamePair[list.size()];
    list.toArray(items);
    lotSelection = new Listbox();
    lotSelection.setRows(0);
    lotSelection.setMultiple(false);
    lotSelection.setMold("select");
    lotSelection.setWidth("150px");
    lotSelection.setAttribute("zk_component_ID", "InfoPAttributePanel_lotSelection");
    for (int i = 0; i < items.length; i++) lotSelection.appendItem(items[i].getName(), items[i]);
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) Listbox(org.adempiere.webui.component.Listbox)

Example 13 with Listbox

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

the class WAttributeGrid method initForm.

/**
	 * 	Init
	 *	@param WindowNo
	 *	@param frame
	 */
protected void initForm() {
    m_attributes = MAttribute.getOfClient(Env.getCtx(), true, true);
    KeyNamePair[] vector = new KeyNamePair[m_attributes.length + 1];
    vector[0] = new KeyNamePair(0, "");
    for (int i = 0; i < m_attributes.length; i++) vector[i + 1] = m_attributes[i].getKeyNamePair();
    attributeCombo1 = new Listbox(vector);
    attributeCombo1.setMold("select");
    attributeCombo1.setSelectedIndex(0);
    attributeCombo2 = new Listbox(vector);
    attributeCombo2.setMold("select");
    attributeCombo2.setSelectedIndex(0);
    pickPriceList.setMold("select");
    pickWarehouse.setMold("select");
    fillPicks();
    for (int i = 0; i < MODES.length; i++) modeCombo.appendItem(MODES[i], MODES[i]);
    modeCombo.setMold("select");
    tabbox.setWidth("100%");
    tabbox.setHeight("85%");
    tabbox.appendChild(tabs);
    tabbox.appendChild(tabpanels);
    tabbox.addEventListener(Events.ON_SELECT, this);
    Grid gridSelection = new Grid();
    gridSelection.setWidth("500px");
    gridSelection.setStyle("margin:0; padding:0;");
    gridSelection.makeNoStrip();
    gridSelection.setOddRowSclass("even");
    gridView.setWidth("100%");
    gridView.setHeight("100%");
    gridView.setFixedLayout(true);
    Rows rows = new Rows();
    gridSelection.appendChild(rows);
    Row row = new Row();
    rows.appendChild(row);
    row.setSpans("1, 2");
    Div div = new Div();
    div.setAlign("right");
    div.appendChild(attributeLabel1);
    row.appendChild(div);
    row.appendChild(attributeCombo1);
    attributeCombo1.setWidth("100%");
    row = new Row();
    rows.appendChild(row);
    row.setSpans("1, 2");
    div = new Div();
    div.setAlign("right");
    div.appendChild(attributeLabel2);
    row.appendChild(div);
    row.appendChild(attributeCombo2);
    attributeCombo2.setWidth("100%");
    row = new Row();
    rows.appendChild(row);
    row.setSpans("1, 2");
    div = new Div();
    div.setAlign("right");
    div.appendChild(labelPriceList);
    row.appendChild(div);
    row.appendChild(pickPriceList);
    pickPriceList.setWidth("100%");
    row = new Row();
    rows.appendChild(row);
    row.setSpans("1, 2");
    div = new Div();
    div.setAlign("right");
    div.appendChild(labelWarehouse);
    row.appendChild(div);
    row.appendChild(pickWarehouse);
    pickWarehouse.setWidth("100%");
    div = new Div();
    div.setAlign("center");
    div.appendChild(gridSelection);
    Tabpanel tabSelectionPanel = new Tabpanel();
    tabSelectionPanel.appendChild(div);
    Tab tabSelection = new Tab(Msg.getMsg(Env.getCtx(), "Selection"));
    tabpanels.appendChild(tabSelectionPanel);
    tabs.appendChild(tabSelection);
    div = new Div();
    div.setAlign("center");
    div.appendChild(modeLabel);
    div.appendChild(modeCombo);
    modeCombo.addEventListener(Events.ON_CHANGE, this);
    Vbox vbAttributeGrid = new Vbox();
    vbAttributeGrid.appendChild(div);
    vbAttributeGrid.appendChild(gridView);
    Tabpanel tabAttributeGridPanel = new Tabpanel();
    tabAttributeGridPanel.appendChild(vbAttributeGrid);
    Tab tabAttributeGrid = new Tab(Msg.getMsg(Env.getCtx(), "AttributeGrid"));
    tabpanels.appendChild(tabAttributeGridPanel);
    tabs.appendChild(tabAttributeGrid);
    this.setWidth("100%");
    this.setHeight("100%");
    this.appendChild(tabbox);
    tabbox.addEventListener(Events.ON_SELECT, this);
    this.appendChild(confirmPanel);
    confirmPanel.addActionListener(this);
}
Also used : Div(org.zkoss.zul.Div) Tab(org.adempiere.webui.component.Tab) Grid(org.adempiere.webui.component.Grid) KeyNamePair(org.compiere.util.KeyNamePair) Row(org.adempiere.webui.component.Row) Listbox(org.adempiere.webui.component.Listbox) Tabpanel(org.adempiere.webui.component.Tabpanel) Vbox(org.zkoss.zul.Vbox) Rows(org.adempiere.webui.component.Rows)

Example 14 with Listbox

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

the class ADSortTab method migrateValueAcrossLists.

/**
	 * @param event
	 */
void migrateValueAcrossLists(Event event) {
    Object source = event.getTarget();
    if (source instanceof ListItem) {
        source = ((ListItem) source).getListbox();
    }
    Listbox listFrom = (source == bAdd || source == noList) ? noList : yesList;
    Listbox listTo = (source == bAdd || source == noList) ? yesList : noList;
    SimpleListModel lmFrom = (source == bAdd || source == noList) ? noModel : yesModel;
    SimpleListModel lmTo = (lmFrom == yesModel) ? noModel : yesModel;
    Set selectedItems = listFrom.getSelectedItems();
    List<ListElement> selObjects = new ArrayList<ListElement>();
    for (Object obj : selectedItems) {
        ListItem listItem = (ListItem) obj;
        int index = listFrom.getIndexOfItem(listItem);
        ListElement selObject = (ListElement) lmFrom.getElementAt(index);
        selObjects.add(selObject);
    }
    for (ListElement selObject : selObjects) {
        if (selObject == null || !selObject.isUpdateable())
            continue;
        lmFrom.removeElement(selObject);
        lmTo.addElement(selObject);
        //  Enable explicit Save
        setIsChanged(true);
    }
    for (ListElement selObject : selObjects) {
        int index = lmTo.indexOf(selObject);
        listTo.setSelectedIndex(index);
    }
    if (listTo.getSelectedItem() != null) {
        AuFocus focus = new AuFocus(listTo.getSelectedItem());
        Clients.response(focus);
    }
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) SimpleListModel(org.adempiere.webui.component.SimpleListModel) ArrayList(java.util.ArrayList) ListItem(org.adempiere.webui.component.ListItem) Listbox(org.adempiere.webui.component.Listbox) AuFocus(org.zkoss.zk.au.out.AuFocus)

Example 15 with Listbox

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

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