Search in sources :

Example 56 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WListItemRenderer method onEvent.

/* (non-Javadoc)
	 * @see org.zkoss.zk.ui.event.EventListener#onEvent(org.zkoss.zk.ui.event.Event)
	 */
public void onEvent(Event event) throws Exception {
    int col = -1;
    int row = -1;
    Object value = null;
    TableValueChangeEvent vcEvent = null;
    WTableColumn tableColumn;
    Component source = event.getTarget();
    if (isWithinListCell(source)) {
        row = getRowPosition(source);
        col = getColumnPosition(source);
        tableColumn = m_tableColumns.get(col);
        if (source instanceof Checkbox) {
            value = Boolean.valueOf(((Checkbox) source).isChecked());
        } else if (source instanceof Decimalbox) {
            value = ((Decimalbox) source).getValue();
        } else if (source instanceof Datebox) {
            value = ((Datebox) source).getValue();
        } else if (source instanceof Textbox) {
            value = ((Textbox) source).getValue();
        }
        if (value != null) {
            vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), row, col, value, value);
            fireTableValueChange(vcEvent);
        }
    } else if (event.getTarget() instanceof WListbox && Events.ON_SELECT.equals(event.getName())) {
        WListbox table = (WListbox) event.getTarget();
        if (table.isCheckmark()) {
            int cnt = table.getRowCount();
            if (cnt == 0 || !(table.getValueAt(0, 0) instanceof IDColumn))
                return;
            //update IDColumn
            tableColumn = m_tableColumns.get(0);
            for (int i = 0; i < cnt; i++) {
                IDColumn idcolumn = (IDColumn) table.getValueAt(i, 0);
                if (idcolumn != null) {
                    Listitem item = table.getItemAtIndex(i);
                    value = item.isSelected();
                    Boolean old = idcolumn.isSelected();
                    if (!old.equals(value)) {
                        vcEvent = new TableValueChangeEvent(source, tableColumn.getHeaderValue().toString(), i, 0, old, value);
                        fireTableValueChange(vcEvent);
                    }
                }
            }
        }
    }
    return;
}
Also used : Listitem(org.zkoss.zul.Listitem) IDColumn(org.compiere.minigrid.IDColumn) Decimalbox(org.zkoss.zul.Decimalbox) Component(org.zkoss.zk.ui.Component) TableValueChangeEvent(org.adempiere.webui.event.TableValueChangeEvent)

Example 57 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoProductPanel method statInit.

//	initComponents
private void statInit() {
    //  Fill the grid, setup the center data table & add the tabs
    initComponents();
    Rows rows = new Rows();
    Row row = new Row();
    rows.appendChild(row);
    row.appendCellChild(lblValue.rightAlign());
    row.appendCellChild(fieldValue);
    row.appendCellChild(lblWarehouse.rightAlign());
    row.appendCellChild(fWarehouse_ID.getComponent());
    row.appendCellChild(lblBlank.rightAlign());
    row.appendCellChild(checkOnlyStock);
    row = new Row();
    rows.appendChild(row);
    row.appendCellChild(lblName.rightAlign());
    row.appendCellChild(fieldName);
    row.appendCellChild(lblPriceList.rightAlign());
    row.appendCellChild(fPriceList_ID.getComponent());
    row.appendCellChild(lblAS.rightAlign());
    row.appendCellChild(fAS_ID.getComponent());
    //
    row = new Row();
    rows.appendChild(row);
    row.appendCellChild(lblUPC.rightAlign());
    row.appendCellChild(fieldUPC);
    row.appendCellChild(lblProductCategory.rightAlign());
    row.appendCellChild(fProductCategory_ID.getComponent());
    row.appendCellChild(lblASI.rightAlign());
    row.appendCellChild(fASI_ID.getComponent());
    row = new Row();
    rows.appendChild(row);
    row.appendCellChild(lblSKU.rightAlign());
    row.appendCellChild(fieldSKU);
    row.appendCellChild(lblVendor.rightAlign());
    row.appendCellChild(fVendor_ID.getComponent());
    row.appendCellChild(lblBlank.rightAlign());
    row.appendCellChild(checkAND);
    //
    ColumnInfo[] s_layoutWarehouse = new ColumnInfo[] { new ColumnInfo(" ", "M_Warehouse_ID", IDColumn.class), new ColumnInfo(Msg.translate(Env.getCtx(), "WarehouseName"), "WarehouseName", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "sum(QtyAvailable)", Double.class, true, true, null), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "sum(QtyOnHand)", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "sum(QtyReserved)", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOrdered"), "sum(QtyOrdered)", Double.class) };
    //        		new ColumnInfo(Msg.translate(Env.getCtx(), "DocumentNote"), "DocumentNote", String.class)};
    /**	From Clause							*/
    String s_sqlFrom = " M_PRODUCT_STOCK_V ";
    /** Where Clause						*/
    String s_sqlWhere = "(QtyOnHand <> 0 OR QtyAvailable <> 0 OR QtyReserved <> 0 OR QtyOrdered <> 0) AND M_Product_ID = ?";
    //      String s_sqlWhere = "M_Product_ID = ?";
    m_sqlWarehouse = warehouseTbl.prepareTable(s_layoutWarehouse, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_STOCK_V");
    m_sqlWarehouse += " Group By M_Warehouse_ID, WarehouseName ";
    m_sqlWarehouse += " Order By sum(QtyOnHand) DESC, WarehouseName ";
    warehouseTbl.setMultiSelection(false);
    warehouseTbl.setSizedByContent(false);
    //warehouseTbl.autoSize();
    warehouseTbl.setShowTotals(true);
    //warehouseTbl.getModel().addTableModelListener(this);
    warehouseTbl.setAttribute("zk_component_ID", "Lookup_Data_Warehouse");
    ColumnInfo[] s_layoutSubstitute = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Description"), "description", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Value"), "value", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class, true, true, null), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class) };
    s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V";
    s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'S'";
    m_sqlSubstitute = substituteTbl.prepareTable(s_layoutSubstitute, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V");
    substituteTbl.setMultiSelection(false);
    substituteTbl.autoSize();
    substituteTbl.getModel().addTableModelListener(this);
    substituteTbl.setAttribute("zk_component_ID", "Lookup_Data_Substitute");
    ColumnInfo[] s_layoutRelated = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Description"), "description", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Value"), "value", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class, true, true, null), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class) };
    s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V";
    s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'R'";
    m_sqlRelated = relatedTbl.prepareTable(s_layoutRelated, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V");
    relatedTbl.setMultiSelection(false);
    relatedTbl.autoSize();
    relatedTbl.getModel().addTableModelListener(this);
    relatedTbl.setAttribute("zk_component_ID", "Lookup_Data_Related");
    //Available to Promise Tab
    m_tableAtp.setMultiSelection(false);
    m_tableAtp.autoSize();
    m_tableAtp.setShowTotals(true);
    m_tableAtp.setAttribute("zk_component_ID", "Lookup_Data_ATP");
    //Vendor tab
    ColumnInfo[] s_layoutVendor = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "Vendor"), "(SELECT bp.Name FROM C_BPartner bp WHERE bp.C_BPartner_ID = M_PRODUCT_PO.C_BPartner_ID)", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "IsCurrentVendor"), "IsCurrentVendor", Boolean.class), new ColumnInfo(Msg.translate(Env.getCtx(), "C_UOM_ID"), "(SELECT Name FROM C_UOM WHERE C_UOM_ID = M_PRODUCT_PO.C_UOM_ID)", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "C_Currency_ID"), "(SELECT iso_code FROM C_Currency WHERE C_Currency_ID = M_PRODUCT_PO.C_Currency_ID)", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PriceList"), "PriceList", BigDecimal.class), new ColumnInfo(Msg.translate(Env.getCtx(), "PricePO"), "PricePO", BigDecimal.class), new ColumnInfo(Msg.translate(Env.getCtx(), "VendorProductNo"), "VendorProductNo", String.class), new ColumnInfo(Msg.translate(Env.getCtx(), "Order_Min"), "Order_Min", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "DeliveryTime_Promised"), "DeliveryTime_Promised", Double.class), new ColumnInfo(Msg.translate(Env.getCtx(), "DeliveryTime_Actual"), "DeliveryTime_Actual", Double.class) };
    s_sqlFrom = "M_PRODUCT_PO";
    s_sqlWhere = "M_Product_ID = ?";
    m_sqlVendor = vendorTbl.prepareTable(s_layoutVendor, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_PO");
    vendorTbl.setMultiSelection(false);
    vendorTbl.autoSize();
    vendorTbl.setAttribute("zk_component_ID", "Lookup_Data_Vendor");
    detailTabBox.setHeight("100%");
    Tabpanels tabPanels = new Tabpanels();
    detailTabBox.appendChild(tabPanels);
    Tabs tabs = new Tabs();
    detailTabBox.appendChild(tabs);
    Tab tab = new Tab(Util.cleanAmp(Msg.translate(Env.getCtx(), "Warehouse")));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    Tabpanel desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    desktopTabPanel.appendChild(warehouseTbl);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Msg.translate(Env.getCtx(), "Description"));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    fieldDescription.setWidth("99%");
    fieldDescription.setHeight("99%");
    desktopTabPanel.appendChild(fieldDescription);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Msg.translate(Env.getCtx(), "ProductAttribute"));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    fieldPAttributes.setWidth("99%");
    fieldPAttributes.setHeight("99%");
    desktopTabPanel.appendChild(fieldPAttributes);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Msg.translate(Env.getCtx(), "Substitute_ID"));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    desktopTabPanel.appendChild(substituteTbl);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Msg.translate(Env.getCtx(), "RelatedProduct_ID"));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    desktopTabPanel.appendChild(relatedTbl);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Msg.getMsg(Env.getCtx(), "ATP"));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    desktopTabPanel.appendChild(m_tableAtp);
    tabPanels.appendChild(desktopTabPanel);
    tab = new Tab(Util.cleanAmp(Msg.translate(Env.getCtx(), "Vendor")));
    tab.addEventListener(Events.ON_SELECT, this);
    tabs.appendChild(tab);
    desktopTabPanel = new Tabpanel();
    desktopTabPanel.setHeight("100%");
    desktopTabPanel.appendChild(vendorTbl);
    tabPanels.appendChild(desktopTabPanel);
    tabs.setAttribute("zk_component_ID", "Subordinate_Tabs");
    //  Add the tabs to the center south layout
    Borderlayout tabLayout = new Borderlayout();
    //  
    North north = new North();
    tabLayout.appendChild(north);
    north.appendChild(checkShowDetail);
    //
    Center center = new Center();
    tabLayout.appendChild(center);
    center.appendChild(detailTabBox);
    //  Set main panel elements.  The other elements are handled by the info.java class
    p_criteriaGrid.appendChild(rows);
    p_centerSouth.appendChild(tabLayout);
    p_centerSouth.setTitle(Msg.translate(Env.getCtx(), "WarehouseStock"));
    p_centerSouth.setTooltiptext(Msg.translate(Env.getCtx(), "WarehouseStock"));
    super.setSizes();
    warehouseTbl.addActionListener(new EventListener<Event>() {

        public void onEvent(Event event) throws Exception {
            if (warehouseTbl.getRowCount() > 0) {
                int selectedRow = warehouseTbl.getSelectedRow();
                if (selectedRow < 0)
                    selectedRow = 0;
                Object wh_data = warehouseTbl.getValueAt(selectedRow, warehouseTbl.getKeyColumnIndex());
                if (wh_data != null && wh_data instanceof IDColumn) {
                    IDColumn dataColumn = (IDColumn) wh_data;
                    m_ATP_M_Warehouse_ID = dataColumn.getRecord_ID();
                } else {
                    m_ATP_M_Warehouse_ID = m_M_Warehouse_ID;
                }
            } else {
                m_ATP_M_Warehouse_ID = m_M_Warehouse_ID;
            }
        }
    });
}
Also used : Center(org.zkoss.zul.Center) ColumnInfo(org.compiere.minigrid.ColumnInfo) Borderlayout(org.zkoss.zul.Borderlayout) SQLException(java.sql.SQLException) IDColumn(org.compiere.minigrid.IDColumn) Tab(org.adempiere.webui.component.Tab) Tabpanels(org.adempiere.webui.component.Tabpanels) Tabs(org.adempiere.webui.component.Tabs) Event(org.zkoss.zk.ui.event.Event) North(org.zkoss.zul.North) Row(org.adempiere.webui.component.Row) Tabpanel(org.adempiere.webui.component.Tabpanel) Rows(org.adempiere.webui.component.Rows)

Example 58 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoProductPanel method refresh.

/**
	 * 	Refresh Query
	 */
protected void refresh() {
    //  Invoke later to not delay events.
    //SwingUtilities.invokeLater(new Runnable(){public void run()
    //{
    int M_PriceList_Version_ID = 0;
    if (fPriceList_ID.getValue() != null)
        M_PriceList_Version_ID = ((Integer) fPriceList_ID.getValue()).intValue();
    String sql;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String eol = System.getProperty("line.separator");
    Boolean queryWarehouse = false;
    int leadRowKey = 0;
    if (p_table != null || p_table.getRowCount() > 0)
        leadRowKey = p_table.getLeadRowKey();
    if (m_M_Product_ID != leadRowKey) {
        //  From the main table
        m_M_Product_ID = leadRowKey;
        //  The product has changed, change the warehouse table
        queryWarehouse = true;
    }
    if (m_M_Product_ID <= 0) {
        p_centerLayout.getSouth().setOpen(false);
        return;
    } else {
        p_centerLayout.getSouth().setOpen(true);
        if (// Product has changed and is valid
        queryWarehouse) {
            //  Find the ASI used by the product on the lead row
            MProduct mp = MProduct.get(Env.getCtx(), m_M_Product_ID);
            m_M_AttributeSetInstance_ID = mp.getM_AttributeSetInstance_ID();
        }
    }
    if (detailTabBox.getSelectedIndex() == 0 || detailTabBox.getSelectedIndex() == 5) {
        if (queryWarehouse) {
            //  Warehouse tab
            sql = m_sqlWarehouse;
            log.finest(sql);
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, m_M_Product_ID);
                rs = pstmt.executeQuery();
                warehouseTbl.loadTable(rs);
                rs.close();
            } catch (Exception e) {
                log.log(Level.WARNING, sql, e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
        }
        if (warehouseTbl.getRowCount() > 0) {
            int selectedRow = warehouseTbl.getSelectedRow();
            if (selectedRow < 0) {
                warehouseTbl.setSelectedIndex(0);
                selectedRow = 0;
            }
            Object wh_data = warehouseTbl.getValueAt(selectedRow, warehouseTbl.getKeyColumnIndex());
            if (wh_data != null && wh_data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) wh_data;
                m_ATP_M_Warehouse_ID = dataColumn.getRecord_ID();
            } else {
                m_ATP_M_Warehouse_ID = m_M_Warehouse_ID;
            }
        } else {
            m_ATP_M_Warehouse_ID = m_M_Warehouse_ID;
        }
    }
    if (detailTabBox.getSelectedIndex() == 1) {
        fieldDescription.setText("");
        //  Description tab
        if (m_M_Product_ID != 0) {
            MProduct p = MProduct.get(Env.getCtx(), m_M_Product_ID);
            if (p.getDescription() != null && p.getDescription().length() > 0)
                fieldDescription.setText(p.getDescription());
            if (p.getDocumentNote() != null && p.getDocumentNote().length() > 0) {
                if (fieldDescription.getText().length() > 0)
                    fieldDescription.setText(fieldDescription.getText() + eol + eol + p.getDocumentNote());
                else
                    fieldDescription.setText(fieldDescription.getText() + p.getDocumentNote());
            }
        } else
            fieldDescription.setText("");
    }
    if (detailTabBox.getSelectedIndex() == 2) {
        fieldPAttributes.setText("");
        StringBuffer paText = new StringBuffer();
        //  Product Attributes tab
        if (m_M_Product_ID != 0) {
            MProduct p = MProduct.get(Env.getCtx(), m_M_Product_ID);
            if (p.getM_AttributeSet_ID() == 0 || p.getM_AttributeSetInstance_ID() == 0) {
                // There is no attribute set or attribute set instance associated with the product
                return;
            }
            int M_AttributeSet_ID = p.getM_AttributeSetInstance_ID();
            sql = "SELECT asi.Lot, asi.SerNo, asi.GuaranteeDate," + " COALESCE(a.SerNoCharSOverwrite, '#'::CHAR(1))," + " COALESCE(a.SerNoCharEOverwrite, ''::CHAR(1))," + " COALESCE(a.LotCharSOverwrite, '«'::CHAR(1))," + " COALESCE(a.LotCharEOverwrite, '»'::CHAR(1))" + " FROM M_AttributeSetInstance asi" + " INNER JOIN M_AttributeSet a ON (asi.M_AttributeSet_ID=a.M_AttributeSet_ID)" + " WHERE asi.M_AttributeSetInstance_ID=?";
            log.finest(sql);
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, M_AttributeSet_ID);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    if (rs.getString(1) != null && rs.getString(1).length() > 0)
                        paText.append(Msg.translate(Env.getCtx(), "Lot")).append(": ").append(rs.getString(6)).append(rs.getString(1)).append(rs.getString(7)).append(eol);
                    if (rs.getString(2) != null && rs.getString(2).length() > 0)
                        paText.append(Msg.translate(Env.getCtx(), "SerialNumber")).append(": ").append(rs.getString(4)).append(rs.getString(2)).append(rs.getString(5)).append(eol);
                    if (rs.getDate(3) != null)
                        paText.append(Msg.translate(Env.getCtx(), "GuaranteeDate")).append(": ").append(rs.getDate(3)).append(eol);
                }
            } catch (Exception e) {
                log.log(Level.WARNING, sql, e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
            //  Instance Attributes - if any
            sql = "SELECT ai.Value, a.Name" + " FROM M_AttributeInstance ai" + " INNER JOIN M_Attribute a ON (ai.M_Attribute_ID=a.M_Attribute_ID AND a.IsInstanceAttribute='Y')" + " WHERE ai.M_AttributeSetInstance_ID=?";
            log.finest(sql);
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, M_AttributeSet_ID);
                rs = pstmt.executeQuery();
                Boolean labeled = false;
                while (rs.next()) {
                    if (!labeled) {
                        paText.append("***  ").append(Msg.translate(Env.getCtx(), "InstanceAttribute")).append("  ***").append(eol);
                        labeled = true;
                    }
                    paText.append("  ").append(rs.getString(2)).append(": ").append(rs.getString(1)).append(eol);
                }
                rs.close();
            } catch (Exception e) {
                log.log(Level.WARNING, sql, e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
            //  Product attributes - if any
            sql = "SELECT ai.Value, a.Name" + " FROM M_AttributeInstance ai" + " INNER JOIN M_Attribute a ON (ai.M_Attribute_ID=a.M_Attribute_ID AND a.IsInstanceAttribute='N')" + " WHERE ai.M_AttributeSetInstance_ID=?";
            log.finest(sql);
            try {
                pstmt = DB.prepareStatement(sql, null);
                pstmt.setInt(1, M_AttributeSet_ID);
                rs = pstmt.executeQuery();
                Boolean labeled = false;
                while (rs.next()) {
                    if (!labeled) {
                        paText.append("***  ").append(Msg.translate(Env.getCtx(), "ProductAttribute")).append("  ***").append(eol);
                        labeled = true;
                    }
                    paText.append("  ").append(rs.getString(2)).append(": ").append(rs.getString(1)).append(eol);
                }
                rs.close();
            } catch (Exception e) {
                log.log(Level.WARNING, sql, e);
            } finally {
                DB.close(rs, pstmt);
                rs = null;
                pstmt = null;
            }
            if (paText.length() > 0)
                fieldPAttributes.setText(paText.toString());
        }
    }
    if (detailTabBox.getSelectedIndex() == 3) {
        //  Substitute tab
        sql = m_sqlSubstitute;
        log.finest(sql);
        try {
            pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, m_M_Product_ID);
            pstmt.setInt(2, M_PriceList_Version_ID);
            rs = pstmt.executeQuery();
            substituteTbl.loadTable(rs);
            rs.close();
        } catch (Exception e) {
            log.log(Level.WARNING, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
    if (detailTabBox.getSelectedIndex() == 4) {
        //  Related tab
        sql = m_sqlRelated;
        log.finest(sql);
        try {
            pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, m_M_Product_ID);
            pstmt.setInt(2, M_PriceList_Version_ID);
            rs = pstmt.executeQuery();
            relatedTbl.loadTable(rs);
            rs.close();
        } catch (Exception e) {
            log.log(Level.WARNING, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
    if (detailTabBox.getSelectedIndex() == 5) {
        if (warehouseTbl.getRowCount() > 0)
            refreshAtpTab();
        else {
            clearAtpTab();
        }
    }
    if (detailTabBox.getSelectedIndex() == 6) {
        //  Vendor tab
        sql = m_sqlVendor;
        log.finest(sql);
        try {
            pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, m_M_Product_ID);
            rs = pstmt.executeQuery();
            vendorTbl.loadTable(rs);
            rs.close();
        } catch (Exception e) {
            log.log(Level.WARNING, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
//}});
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) MProduct(org.compiere.model.MProduct) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 59 with IDColumn

use of org.compiere.minigrid.IDColumn 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 60 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class WBrowserTable method loadTable.

@Override
public int loadTable(ResultSet rs) {
    int no = 0;
    int row = 0;
    //	
    clearTable();
    try {
        while (rs.next()) {
            no++;
            setRowCount(row + 1);
            int colOffset = 1;
            int col = 0;
            //	BR [ 257 ]
            for (MBrowseField field : getFields()) {
                Object value = null;
                if (field.isKey() && DisplayType.isID(field.getAD_Reference_ID()) && !field.getAD_View_Column().getColumnSQL().equals("'Row' AS \"Row\""))
                    value = new IDColumn(rs.getInt(col + colOffset));
                else if (field.isKey() && DisplayType.isNumeric(field.getAD_Reference_ID()) && field.getAD_View_Column().getColumnSQL().equals("'Row' AS \"Row\""))
                    value = new IDColumn(no);
                else if (DisplayType.isID(field.getAD_Reference_ID()) || field.getAD_Reference_ID() == DisplayType.Integer) {
                    Integer id = rs.getInt(col + colOffset);
                    value = id != 0 ? id : null;
                } else if (DisplayType.isNumeric(field.getAD_Reference_ID()))
                    value = rs.getBigDecimal(col + colOffset);
                else if (DisplayType.isDate(field.getAD_Reference_ID()))
                    value = rs.getTimestamp(col + colOffset);
                else if (DisplayType.YesNo == field.getAD_Reference_ID()) {
                    value = rs.getString(col + colOffset);
                    if (value != null)
                        value = value.equals("Y");
                } else
                    value = rs.getObject(col + colOffset);
                GridField gridField = MBrowseField.createGridFieldVO(field, browser.getWindowNo());
                gridField.setValue(value, true);
                //	Set Value
                setValueAnyColumn(row, col, gridField);
                col++;
            }
            row++;
        }
    } catch (SQLException exception) {
        logger.log(Level.SEVERE, "", exception);
    }
    autoSize();
    if (isShowTotals())
        addTotals();
    // repaint the table
    this.repaint();
    logger.config("Row(rs)=" + getRowCount());
    //	Return Row No
    return no;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) MBrowseField(org.adempiere.model.MBrowseField) SQLException(java.sql.SQLException) GridField(org.compiere.model.GridField)

Aggregations

IDColumn (org.compiere.minigrid.IDColumn)79 SQLException (java.sql.SQLException)25 BigDecimal (java.math.BigDecimal)20 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 ArrayList (java.util.ArrayList)16 KeyNamePair (org.compiere.util.KeyNamePair)13 Timestamp (java.sql.Timestamp)8 Vector (java.util.Vector)5 GridField (org.compiere.model.GridField)5 MBrowseField (org.adempiere.model.MBrowseField)4 ApplicationException (org.adempiere.webui.exception.ApplicationException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 PO (org.compiere.model.PO)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 ChangeEvent (javax.swing.event.ChangeEvent)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2