Search in sources :

Example 1 with WNumberEditor

use of org.adempiere.webui.editor.WNumberEditor 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 WNumberEditor

use of org.adempiere.webui.editor.WNumberEditor 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 WNumberEditor

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

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

the class WStocktake method dynParameter.

//  jbInit
/**
	 *  Initialize Parameter fields
	 *  @throws Exception if Lookups cannot be initialized
	 */
private void dynParameter() throws Exception {
    Properties ctx = Env.getCtx();
    //  Physical Inventory
    String vcode = "M_Inventory.IsStocktake='Y' ";
    MLookup inventoryLookup = MLookupFactory.get(ctx, m_WindowNo, 3563, DisplayType.TableDir, Env.getLanguage(Env.getCtx()), "M_Inventory_ID", 53249, true, vcode);
    inventoryField = new WTableDirEditor("M_Inventory_ID", false, false, true, inventoryLookup);
    //  Locator
    MLocatorLookup locatorLookup = new MLocatorLookup(ctx, m_WindowNo);
    locatorField = new WLocatorEditor("M_Locator_ID", false, false, true, locatorLookup, m_WindowNo);
    //	locatorField.addVetoableChangeListener(this);
    //  Product
    MLookup productLookup = MLookupFactory.get(ctx, m_WindowNo, 0, 3668, DisplayType.Search);
    productField = new WSearchEditor("M_Product_ID", false, false, true, productLookup);
    productField.addValueChangeListener(this);
    // Aisle(X)
    MLookup aislexLookup = MLookupFactory.get(ctx, m_WindowNo, 1399, DisplayType.Table, Env.getLanguage(Env.getCtx()), "X", 53562, false, null);
    aislexField = new WTableDirEditor("X", false, false, true, aislexLookup);
    //  Dates
    lineFField = new WNumberEditor();
    lineTField = new WNumberEditor();
    //
    confirmPanel.addActionListener(this);
    statusBar.setStatusLine("");
}
Also used : WTableDirEditor(org.adempiere.webui.editor.WTableDirEditor) MLocatorLookup(org.compiere.model.MLocatorLookup) WLocatorEditor(org.adempiere.webui.editor.WLocatorEditor) MLookup(org.compiere.model.MLookup) WSearchEditor(org.adempiere.webui.editor.WSearchEditor) Properties(java.util.Properties) WNumberEditor(org.adempiere.webui.editor.WNumberEditor)

Aggregations

WNumberEditor (org.adempiere.webui.editor.WNumberEditor)4 Listbox (org.adempiere.webui.component.Listbox)3 WStringEditor (org.adempiere.webui.editor.WStringEditor)3 Label (org.adempiere.webui.component.Label)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 Timestamp (java.sql.Timestamp)1 Properties (java.util.Properties)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 WLocatorEditor (org.adempiere.webui.editor.WLocatorEditor)1 WSearchEditor (org.adempiere.webui.editor.WSearchEditor)1 GridField (org.compiere.model.GridField)1 MAttributeSet (org.compiere.model.MAttributeSet)1 MLocatorLookup (org.compiere.model.MLocatorLookup)1 MLookup (org.compiere.model.MLookup)1