Search in sources :

Example 6 with GridField

use of org.compiere.model.GridField 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 7 with GridField

use of org.compiere.model.GridField in project adempiere by adempiere.

the class WBrowserTable method tableValueChange.

/**
	 *
	 * @param event    The event that has occurred
	 */
public void tableValueChange(TableValueChangeEvent event) {
    // column of table field which caused the event
    int col = event.getColumn();
    // row of table field which caused the event
    int row = event.getRow();
    boolean newBoolean;
    IDColumn idColumn;
    // then set the IDColumn's select field
    if (col >= 0 && row >= 0) {
        if (this.getValueAt(row, col) instanceof IDColumn && event.getNewValue() instanceof Boolean) {
            newBoolean = ((Boolean) event.getNewValue()).booleanValue();
            idColumn = (IDColumn) this.getValueAt(row, col);
            idColumn.setSelected(newBoolean);
            this.setValueAt(idColumn, row, col);
        } else // otherwise just set the value in the model to the new value
        {
            GridField gridField = getGridFieldAt(row, col);
            gridField.setValue(event.getNewValue(), true);
            setValueAt(row, col, gridField);
            if (gridField.getCallout() != null) {
                processCallOut(gridField, event.getNewValue(), event.getOldValue(), row, col);
            }
        }
    }
    return;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) GridField(org.compiere.model.GridField)

Example 8 with GridField

use of org.compiere.model.GridField in project adempiere by adempiere.

the class MBrowseField method createGridFieldVO.

/**
	 *
	 * @param field
	 * @param windowNo
	 */
public static GridField createGridFieldVO(MBrowseField field, int windowNo) {
    GridFieldVO valueObject = GridFieldVO.createStdField(field.getCtx(), windowNo, 0, 0, 0, false, false, false);
    //	
    String uniqueName = field.getAD_View_Column().getColumnName();
    valueObject.isProcess = true;
    valueObject.IsDisplayed = field.isDisplayed();
    valueObject.IsReadOnly = field.isReadOnly();
    valueObject.IsUpdateable = true;
    valueObject.WindowNo = windowNo;
    //	BR [ 318 ]
    if (field.getAD_View_Column().getAD_Column_ID() > 0) {
        valueObject.ColumnName = field.getAD_View_Column().getAD_Column().getColumnName();
        valueObject.AD_Column_ID = field.getAD_View_Column().getAD_Column_ID();
        valueObject.AD_Table_ID = field.getAD_View_Column().getAD_Column().getAD_Table_ID();
    } else {
        valueObject.ColumnName = field.getAD_View_Column().getColumnSQL();
    }
    //	Add Alias
    //	BR [ 340 ]
    valueObject.ColumnNameAlias = CONTEXT_TABLE_PREFIX + uniqueName;
    //	
    valueObject.displayType = field.getAD_Reference_ID();
    valueObject.AD_Reference_Value_ID = field.getAD_Reference_Value_ID();
    valueObject.IsMandatory = field.isMandatory();
    valueObject.IsAlwaysUpdateable = false;
    valueObject.IsKey = field.isKey();
    valueObject.DefaultValue = field.getDefaultValue();
    valueObject.DefaultValue2 = field.getDefaultValue2();
    valueObject.InfoFactoryClass = field.getInfoFactoryClass();
    valueObject.FieldLength = field.getFieldLength();
    valueObject.ReadOnlyLogic = field.getReadOnlyLogic();
    valueObject.DisplayLogic = field.getDisplayLogic();
    valueObject.VFormat = field.getVFormat();
    valueObject.ValueMin = field.getValueMin();
    valueObject.ValueMax = field.getValueMax();
    valueObject.ValidationCode = field.getAD_Val_Rule().getCode();
    valueObject.IsRange = field.isRange();
    try {
        valueObject.Description = field.getDescription();
    } catch (IllegalArgumentException e) {
        valueObject.Description = (String) field.get_Value("Description");
    }
    if (field.getAD_View_Column().getAD_Column_ID() <= 0 && field.isReadOnly())
        valueObject.ColumnSQL = uniqueName;
    valueObject.Help = uniqueName;
    try {
        valueObject.Header = field.getName();
    } catch (IllegalArgumentException e) {
        valueObject.Header = (String) field.get_Value("Name");
        ;
    }
    valueObject.Callout = field.getCallout();
    valueObject.initFinish();
    GridField gridField = new GridField(valueObject);
    if (gridField.isLookup())
        gridField.lookupLoadComplete();
    if (!gridField.isReadOnly()) {
        Object defaultObject = gridField.getDefault();
        gridField.setValue(defaultObject, true);
    }
    return gridField;
}
Also used : GridFieldVO(org.compiere.model.GridFieldVO) GridField(org.compiere.model.GridField)

Example 9 with GridField

use of org.compiere.model.GridField in project adempiere by adempiere.

the class GridTabWrapper method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String methodName = method.getName();
    if (methodName.startsWith("set") && args.length == 1) {
        final Class<?> paramType = method.getParameterTypes()[0];
        final String propertyName;
        final Object value;
        if (isModelInterface(paramType)) {
            // Model setter - me00_03374
            propertyName = methodName.substring(3) + "_ID";
            value = InterfaceWrapperHelper.getId(args[0]);
        } else {
            propertyName = methodName.substring(3);
            value = POWrapper.checkZeroIdValue(propertyName, args[0]);
        }
        final String errorMsg = m_gridTab.setValue(propertyName, value);
        if (!Util.isEmpty(errorMsg)) {
            final String msg = "Attempt to set field " + propertyName + " of grid tab " + m_gridTab + " to value '" + value + " (original: " + args[0] + ")" + "' returned an error message: " + errorMsg;
            if (failOnColumnNotFound) {
                throw new AdempiereException(msg);
            } else {
                log.severe(msg);
            }
        }
        return null;
    } else if (methodName.startsWith("get") && (args == null || args.length == 0) && // metas: GridTab direct calls should be forwarded to GridTab directly
    !methodName.startsWith("get_")) {
        String propertyName = methodName.substring(3);
        Object value = m_gridTab.getValue(propertyName);
        if (value != null) {
            return value;
        }
        //
        if (method.getReturnType() == int.class) {
            value = Integer.valueOf(0);
        } else if (method.getReturnType() == BigDecimal.class) {
            value = BigDecimal.ZERO;
        } else if (isModelInterface(method.getReturnType())) {
            value = getReferencedObject(propertyName, method);
        } else if (PO.class.isAssignableFrom(method.getReturnType())) {
            throw new IllegalArgumentException("Method not supported - " + methodName);
        }
        return value;
    } else if (methodName.startsWith("is") && (args == null || args.length == 0)) {
        String propertyName = methodName.substring(2);
        GridField field = m_gridTab.getField(propertyName);
        if (field != null) {
            final Object value = field.getValue();
            return value instanceof Boolean ? value : "Y".equals(value);
        }
        //
        field = m_gridTab.getField("Is" + propertyName);
        if (field != null) {
            final Object value = field.getValue();
            return value instanceof Boolean ? value : "Y".equals(value);
        }
        //
        throw new IllegalArgumentException("Method not supported - " + methodName);
    } else if (method.getName().equals("get_TableName")) {
        return m_gridTab.get_TableName();
    } else {
        // TODO: this is not working; we need to find the similar method in m_gridTab.getClass() class
        return method.invoke(m_gridTab, args);
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) GridField(org.compiere.model.GridField)

Example 10 with GridField

use of org.compiere.model.GridField in project adempiere by adempiere.

the class InterfaceWrapperHelper method getValue.

private static <T> T getValue(final Object model, final String columnName, final boolean throwExIfColumnNotFound) {
    Check.assumeNotNull(model, "model is not null");
    Check.assumeNotNull(columnName, "columnName is not null");
    if (GridTabWrapper.isHandled(model)) {
        final GridTab gridTab = GridTabWrapper.getGridTab(model);
        final GridField gridField = gridTab.getField(columnName);
        if (gridField == null) {
            if (throwExIfColumnNotFound) {
                throw new AdempiereException("No field with ColumnName=" + columnName + " found in " + gridTab + " for " + model);
            } else {
                return null;
            }
        }
        @SuppressWarnings("unchecked") final T value = (T) gridField.getValue();
        return value;
    } else if (POWrapper.isHandled(model)) {
        PO po = POWrapper.getPO(model, false);
        final int idx = po.get_ColumnIndex(columnName);
        if (idx < 0) {
            if (throwExIfColumnNotFound) {
                throw new AdempiereException("No columnName " + columnName + " found for " + model);
            } else {
                return null;
            }
        }
        @SuppressWarnings("unchecked") T value = (T) po.get_Value(idx);
        return value;
    } else {
        throw new AdempiereException("Model wrapping is not supported for " + model + " (class:" + model.getClass() + ")");
    }
}
Also used : GridTab(org.compiere.model.GridTab) AdempiereException(org.adempiere.exceptions.AdempiereException) GridField(org.compiere.model.GridField) PO(org.compiere.model.PO)

Aggregations

GridField (org.compiere.model.GridField)114 MQuery (org.compiere.model.MQuery)15 WEditor (org.adempiere.webui.editor.WEditor)11 GridFieldVO (org.compiere.model.GridFieldVO)10 GridTab (org.compiere.model.GridTab)10 Lookup (org.compiere.model.Lookup)9 org.apache.ecs.xhtml.tr (org.apache.ecs.xhtml.tr)8 MLookup (org.compiere.model.MLookup)8 Component (java.awt.Component)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)7 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)7 ValueNamePair (org.compiere.util.ValueNamePair)7 SQLException (java.sql.SQLException)6 MBrowseField (org.adempiere.model.MBrowseField)6 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)6 VEditor (org.compiere.grid.ed.VEditor)6 Point (java.awt.Point)5 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)5 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)5