Search in sources :

Example 1 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class WBrowserTable method addTotals.

/**
	 *  Adding a new row with the totals
	 */
public void addTotals() {
    if (getRowCount() == 0 || this.browserRows.getNoViewColumns() == 0)
        return;
    Object[] total = new Object[this.browserRows.getNoViewColumns()];
    for (int row = 0; row < getRowCount(); row++) {
        for (int col = 0; col < this.browserRows.getNoViewColumns(); col++) {
            Object data = getModel().getValueAt(row, col);
            //Class<?> c = layout[col].getColClass();
            int ReferenceType = this.browserRows.getBrowserField(this.browserRows.getTableIndex(col)).getAD_Reference_ID();
            //if (c == BigDecimal.class)
            if (DisplayType.isNumeric(ReferenceType)) {
                BigDecimal subtotal = Env.ZERO;
                if (total[col] != null) {
                    if (total[col] instanceof BigDecimal)
                        subtotal = (BigDecimal) (total[col]);
                    if (total[col] instanceof Integer)
                        subtotal = new BigDecimal((Integer) total[col]);
                }
                BigDecimal amt = Env.ZERO;
                if (data == null)
                    amt = Env.ZERO;
                if (data instanceof BigDecimal)
                    amt = (BigDecimal) data;
                if (data instanceof Integer)
                    amt = new BigDecimal((Integer) data);
                if (subtotal == null)
                    subtotal = Env.ZERO;
                total[col] = subtotal.add(amt);
            }
        }
    }
    //adding total row
    int row = getRowCount() + 1;
    boolean markerSet = false;
    setRowCount(row);
    for (int col = 0; col < this.browserRows.getNoViewColumns(); col++) {
        MBrowseField field = this.browserRows.getBrowserField(this.browserRows.getTableIndex(col));
        GridField gridField = MBrowseField.createGridFieldVO(field, browser.getWindowNo());
        if (DisplayType.isNumeric(field.getAD_Reference_ID())) {
            gridField.setValue(total[col], true);
            setValueAt(row - 1, col, gridField);
        } else {
            if (DisplayType.isText(field.getAD_Reference_ID()) && !markerSet) {
                gridField.setValue(" Σ ", true);
                setValueAt(row - 1, col, gridField);
                markerSet = true;
            } else {
                gridField.setValue(null, true);
                setValueAt(row - 1, col, gridField);
            }
        }
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) GridField(org.compiere.model.GridField) BigDecimal(java.math.BigDecimal)

Example 2 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class VBrowserTable method prepareTable.

//  setColumnReadOnly
@Override
public String prepareTable(List<MBrowseField> fields, boolean multiSelection) {
    StringBuffer sql = new StringBuffer("");
    m_multiSelection = multiSelection;
    browserFields = fields;
    int col = 0;
    //  Add columns & sql
    for (MBrowseField field : fields) {
        MViewColumn columnView = field.getAD_View_Column();
        //  create sql
        if (col > 0 && columnView.getColumnSQL().length() > 0)
            sql.append(", ");
        if (field.isKey()) {
            setKey(col);
            field.setName("#");
        }
        sql.append(columnView.getColumnSQL()).append(" ").append("AS").append(" ").append(columnView.getColumnName());
        browserRows.addBrowserField(field, col);
        if (field.isDisplayed()) {
            addColumn(field.get_ValueAsString(I_AD_Browse_Field.COLUMNNAME_Name));
        }
        //	BR [ 257 ]
        col++;
    }
    //	Set Column Class
    col = 0;
    for (MBrowseField field : fields) {
        if (field.isDisplayed()) {
            setColumnClass(col, MBrowseField.createGridFieldVO(field, browser.getWindowNo()), field.getAD_Reference_ID(), field.isReadOnly(), //	#845 Bad translation for table column
            field.get_Translation(I_AD_Browse_Field.COLUMNNAME_Name));
            col++;
        }
    }
    //	
    return sql.toString();
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) MViewColumn(org.adempiere.model.MViewColumn)

Example 3 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class VBrowserTable method loadTable.

@Override
public int loadTable(ResultSet rs) {
    long start = System.currentTimeMillis();
    //	Row
    int row = 0;
    int no = 0;
    //	Delete Row
    setRowCount(row);
    try {
        log.fine("Start load - " + (System.currentTimeMillis() - start) + "ms");
        while (rs.next()) {
            no++;
            setRowCount(row + 1);
            // columns start with 1
            int colOffset = 1;
            int column = 0;
            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(column + 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(column + colOffset);
                    value = id != 0 ? id : null;
                } else if (DisplayType.isNumeric(field.getAD_Reference_ID()))
                    value = rs.getBigDecimal(column + colOffset);
                else if (DisplayType.isDate(field.getAD_Reference_ID()))
                    value = rs.getTimestamp(column + colOffset);
                else if (DisplayType.YesNo == field.getAD_Reference_ID()) {
                    value = rs.getString(column + colOffset);
                    if (value != null)
                        value = value.equals("Y");
                } else
                    value = rs.getObject(column + colOffset);
                GridField gridField = MBrowseField.createGridFieldVO(field, browser.getWindowNo());
                gridField.setValue(value, true);
                //	Set Value
                setValueAnyColumn(row, column, gridField);
                column++;
            }
            //	Increment Row
            row++;
        }
        log.fine("End load - " + (System.currentTimeMillis() - start) + "ms");
    } catch (SQLException e) {
        log.log(Level.SEVERE, "", e);
    }
    //no = detail.getRowCount();
    log.fine("#" + no + " - " + (System.currentTimeMillis() - start) + "ms");
    if (isShowTotals())
        addTotals();
    //	
    autoSize();
    //
    return no;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) MBrowseField(org.adempiere.model.MBrowseField) SQLException(java.sql.SQLException) GridField(org.compiere.model.GridField)

Example 4 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class Browser method saveResultSelection.

/**
	 * FR [ 245 ]
	 * save result values
	 * @param browserTable
	 */
protected void saveResultSelection(IBrowserTable browserTable) {
    if (m_keyColumnIndex == -1) {
        return;
    }
    //	Verify if is Multi-Selection
    if (p_multiSelection) {
        int rows = browserTable.getRowCount();
        BrowserRow browserRows = browserTable.getData();
        m_values = new LinkedHashMap<Integer, LinkedHashMap<String, Object>>();
        //	BR [ 257 ]
        List<MBrowseField> fields = m_Browse.getFields();
        for (int row = 0; row < rows; row++) {
            //Find the IDColumn Key
            GridField selectedGridField = (GridField) browserRows.getValue(row, m_keyColumnIndex);
            //	Get Value
            Object data = selectedGridField.getValue();
            //	
            if (data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) data;
                if (dataColumn.isSelected()) {
                    LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
                    for (MBrowseField field : fields) {
                        if (!field.isReadOnly() || field.isIdentifier() || field.isKey()) {
                            GridField gridField = (GridField) browserRows.getValueOfColumn(row, field.getAD_View_Column().getColumnName());
                            if (gridField != null) {
                                Object value = gridField.getValue();
                                //	Parse value to standard values
                                if (value instanceof IDColumn) {
                                    IDColumn id = (IDColumn) value;
                                    value = id.getRecord_ID();
                                } else if (value instanceof Double) {
                                    value = BigDecimal.valueOf((Double) value);
                                } else if (value instanceof Date) {
                                    value = new Timestamp(((Date) value).getTime());
                                }
                                //	Set
                                values.put(field.getAD_View_Column().getColumnName(), value);
                            }
                        }
                    }
                    //	
                    if (values.size() > 0)
                        m_values.put(dataColumn.getRecord_ID(), values);
                }
            }
        }
    }
}
Also used : MBrowseField(org.adempiere.model.MBrowseField) GridField(org.compiere.model.GridField) Timestamp(java.sql.Timestamp) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) IDColumn(org.compiere.minigrid.IDColumn)

Example 5 with MBrowseField

use of org.adempiere.model.MBrowseField in project adempiere by adempiere.

the class Browser method getSQLOrderBy.

/*public String getSQLOrderBy() {
		StringBuilder sqlOrderBy = new StringBuilder();
		for (MBrowseField fi
		eld : m_Browse.getOrderByFields()) {
			if (sqlOrderBy.length() > 0 && field.isOrderBy())
				sqlOrderBy.append(",");

			if (field.isOrderBy()) {
				int orderByPosition = getOrderByPosition(field
						.getAD_View_Column().getColumnName());
				if (orderByPosition > 0)
					sqlOrderBy.append(orderByPosition);
			}
		}
		return sqlOrderBy.length() > 0 ? " ORDER BY " + sqlOrderBy.toString()
				: "";
	}*/
/*private int getOrderByPosition(String name)
	{
		int colOffset = 1; // columns start with 1
		for (int col = 0; col < p_layout.length; col++) {
			Info_Column column = p_layout[col];
			String columnName = column.getColSQL().substring(
					column.getColSQL().indexOf("AS ") + 3);

			Class<?> c = column.getColClass();
			int sortBySqlNo = col + colOffset;
			if (c == KeyNamePair.class)
				colOffset++;
			if(name.equals(columnName))
				return sortBySqlNo;
		}
		return 0;
	}*/
public String getSQLOrderBy() {
    StringBuilder sqlOrderBy = new StringBuilder();
    for (MBrowseField field : m_Browse.getOrderByFields()) {
        if (field.isOrderBy()) {
            int orderByPosition = getOrderByPosition(field);
            if (orderByPosition <= 0)
                continue;
            if (sqlOrderBy.length() > 0)
                sqlOrderBy.append(",");
            sqlOrderBy.append(orderByPosition);
        }
    }
    return sqlOrderBy.length() > 0 ? " ORDER BY " + sqlOrderBy.toString() : "";
}
Also used : MBrowseField(org.adempiere.model.MBrowseField)

Aggregations

MBrowseField (org.adempiere.model.MBrowseField)21 MBrowse (org.adempiere.model.MBrowse)6 MViewColumn (org.adempiere.model.MViewColumn)6 GridField (org.compiere.model.GridField)6 IDColumn (org.compiere.minigrid.IDColumn)4 BigDecimal (java.math.BigDecimal)3 SQLException (java.sql.SQLException)3 I_AD_View_Column (org.adempiere.model.I_AD_View_Column)2 PackOut (org.adempiere.pipo.PackOut)2 MColumn (org.compiere.model.MColumn)2 MQuery (org.compiere.model.MQuery)2 MTable (org.compiere.model.MTable)2 Query (org.compiere.model.Query)2 AttributesImpl (org.xml.sax.helpers.AttributesImpl)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1