Search in sources :

Example 1 with WStringEditor

use of org.adempiere.webui.editor.WStringEditor 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 2 with WStringEditor

use of org.adempiere.webui.editor.WStringEditor 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 3 with WStringEditor

use of org.adempiere.webui.editor.WStringEditor in project adempiere by adempiere.

the class WCreateFromStatementUI method dynInit.

/**
	 *  Dynamic Init
	 *  @throws Exception if Lookups cannot be initialized
	 *  @return true if initialized
	 */
public boolean dynInit() throws Exception {
    log.config("");
    //Refresh button
    Button refreshButton = v_CreateFromPanel.getConfirmPanel().createButton(ConfirmPanel.A_REFRESH);
    refreshButton.addEventListener(Events.ON_CLICK, this);
    v_CreateFromPanel.getConfirmPanel().addButton(refreshButton);
    //  C_BankStatement.C_BankAccount_ID
    int AD_Column_ID = 4917;
    MLookup lookup = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
    bankAccountField = new WTableDirEditor("C_BankAccount_ID", true, true, true, lookup);
    //  Set Default
    bankAccountField.setValue(getC_BankAccount_ID());
    //  initial Loading
    authorizationField = new WStringEditor("authorization", false, false, true, 10, 30, null, null);
    authorizationField.getComponent().addEventListener(Events.ON_CHANGE, this);
    lookup = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir);
    documentTypeField = new WTableDirEditor(MPayment.COLUMNNAME_C_DocType_ID, false, false, true, lookup);
    documentTypeField.getComponent().addEventListener(Events.ON_CHANGE, this);
    lookup = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List);
    tenderTypeField = new WTableDirEditor(MPayment.COLUMNNAME_TenderType, false, false, true, lookup);
    tenderTypeField.getComponent().addEventListener(Events.ON_CHANGE, this);
    lookup = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search);
    bPartnerLookup = new WSearchEditor("C_BPartner_ID", false, false, true, lookup);
    Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate);
    dateToField.setValue(date);
    loadBankAccount();
    return true;
}
Also used : WTableDirEditor(org.adempiere.webui.editor.WTableDirEditor) Button(org.adempiere.webui.component.Button) MLookup(org.compiere.model.MLookup) WSearchEditor(org.adempiere.webui.editor.WSearchEditor) Timestamp(java.sql.Timestamp) WStringEditor(org.adempiere.webui.editor.WStringEditor)

Example 4 with WStringEditor

use of org.adempiere.webui.editor.WStringEditor in project adempiere by adempiere.

the class FindWindow method getEditorComponent.

//  addOperators
/**
     *  Get Editor
     *  @param row row
     *  @return Editor component
    **/
public Component getEditorComponent(ListItem row, boolean to) {
    String columnName = getColumnName(row);
    boolean between = false;
    Listbox listOp = (Listbox) row.getFellow("listOperator" + row.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);
    //  Create Editor
    GridField field = getTargetMField(columnName);
    if (field == null)
        return new Label("");
    WEditor editor = null;
    if (field.isKey())
        editor = new WNumberEditor(field);
    else
        editor = WebEditorFactory.getEditor(field, true);
    if (editor == null)
        editor = new WStringEditor(field);
    field.addPropertyChangeListener(editor);
    editor.addValueChangeListener(this);
    editor.setValue(null);
    editor.setReadWrite(enabled);
    editor.setVisible(enabled);
    editor.dynamicDisplay();
    // So we have to do this after setting the ReadWrite
    if (enabled && editor instanceof WTableDirEditor) {
        ((WTableDirEditor) editor).actionRefresh();
    }
    //
    return editor.getComponent();
}
Also used : WTableDirEditor(org.adempiere.webui.editor.WTableDirEditor) Label(org.adempiere.webui.component.Label) GridField(org.compiere.model.GridField) WEditor(org.adempiere.webui.editor.WEditor) Listbox(org.adempiere.webui.component.Listbox) WNumberEditor(org.adempiere.webui.editor.WNumberEditor) WStringEditor(org.adempiere.webui.editor.WStringEditor)

Example 5 with WStringEditor

use of org.adempiere.webui.editor.WStringEditor in project adempiere by adempiere.

the class WExpressReceiptScanBarUI method createProductPanel.

/**
     * Creates the New Charge panel.
     *
     * The New Charge panel is used to specify the name and key of an account
     * and whether or not the account is a charge account.
     */
private void createProductPanel() {
    //  load Locator
    locatorLabel.setValue(Msg.translate(Env.getCtx(), "M_Locator_ID"));
    locatorLabel.setMandatory(true);
    MLocatorLookup locator = new MLocatorLookup(Env.getCtx(), form.getWindowNo());
    locator.setOnly_Warehouse_ID(getDefaultWarehouseId());
    locatorField = new WLocatorEditor("M_Locator_ID", true, false, true, locator, form.getWindowNo());
    locatorField.setMandatory(true);
    locatorField.setValue(Env.getContextAsInt(Env.getCtx(), form.getWindowNo(), "M_Locator_ID"));
    locatorField.addValueChangeListener(this);
    upcLabel.setText(Msg.getElement(Env.getCtx(), "Value", false));
    upcLabel.setMandatory(true);
    upcField = new WStringEditor("UPC", false, false, true, 10, 30, null, null);
    upcField.getComponent().addEventListener(Events.ON_CHANGE, this);
    qtyCountLabel.setText(Msg.getElement(Env.getCtx(), "QtyCount", false));
    qtyCountField.getComponent().addEventListener(Events.ON_CHANGE, this);
    lotLabel.setText(Msg.getElement(Env.getCtx(), "Lot", false));
    lotField = new WStringEditor("Lot", false, false, true, 10, 30, null, null);
    lotField.getComponent().addEventListener(Events.ON_CHANGE, this);
    serNoLabel.setText(Msg.getElement(Env.getCtx(), "SerNo", false));
    serNoField = new WStringEditor("SerNo", false, false, true, 10, 30, null, null);
    serNoField.getComponent().addEventListener(Events.ON_CHANGE, this);
    productValueLabel.setValue(Msg.translate(Env.getCtx(), "Value"));
    productLabel.setValue(Msg.translate(Env.getCtx(), "Name"));
    UOMLabel.setValue(Msg.translate(Env.getCtx(), "C_UOM_ID"));
    Rows rows = new Rows();
    newGrid.appendChild(rows);
    Row row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.appendChild(locatorLabel);
    row.appendChild(locatorField.getComponent());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.appendChild(upcLabel);
    row.appendChild(upcField.getComponent());
    row.appendChild(qtyCountLabel);
    row.appendChild(qtyCountField.getComponent());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.appendChild(serNoLabel);
    row.appendChild(serNoField.getComponent());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.appendChild(lotLabel);
    row.appendChild(lotField.getComponent());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    //Product Info
    productValueField.setReadonly(true);
    row = new Row();
    rows.appendChild(row);
    row.appendChild(productValueLabel);
    row.appendChild(productValueField);
    productField.setReadonly(true);
    row.appendChild(productLabel);
    row.appendChild(productField);
    UOMField.setReadonly(true);
    row.appendChild(UOMLabel);
    row.appendChild(UOMField);
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    row = new Row();
    rows.appendChild(row);
    row.setSpans("3");
    row.appendChild(new Separator());
    upcField.setVisible(false);
    qtyCountField.setVisible(false);
    lotField.setVisible(false);
    serNoField.setVisible(false);
    return;
}
Also used : MLocatorLookup(org.compiere.model.MLocatorLookup) WLocatorEditor(org.adempiere.webui.editor.WLocatorEditor) Row(org.adempiere.webui.component.Row) Separator(org.zkoss.zul.Separator) WStringEditor(org.adempiere.webui.editor.WStringEditor) Rows(org.adempiere.webui.component.Rows)

Aggregations

WStringEditor (org.adempiere.webui.editor.WStringEditor)7 Listbox (org.adempiere.webui.component.Listbox)3 Row (org.adempiere.webui.component.Row)3 WLocatorEditor (org.adempiere.webui.editor.WLocatorEditor)3 WNumberEditor (org.adempiere.webui.editor.WNumberEditor)3 MLocatorLookup (org.compiere.model.MLocatorLookup)3 Separator (org.zkoss.zul.Separator)3 Timestamp (java.sql.Timestamp)2 Label (org.adempiere.webui.component.Label)2 Rows (org.adempiere.webui.component.Rows)2 WEditor (org.adempiere.webui.editor.WEditor)2 WTableDirEditor (org.adempiere.webui.editor.WTableDirEditor)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Button (org.adempiere.webui.component.Button)1 NumberBox (org.adempiere.webui.component.NumberBox)1 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)1 GridField (org.compiere.model.GridField)1