Search in sources :

Example 51 with GridField

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

the class SmallViewController method vetoableChange.

/**
	 *	Swing Editor Listener. Swing editors fire VetoableChange events when the user makes
	 *  a change.  The controller has the option of accepting the change and setting the 
	 *  field value accordingly or vetoing the change by throwing a PropertyVetoException.<br>
	 *  <br>
	 *  For ZK editors, see the equivalent {@link #valueChange(ValueChangeEvent)}
	 *	@param evt Event
	 * 	@exception PropertyVetoException if the controller wishes to roll back.
	 * 
	 */
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    log.fine(evt.getPropertyName() + "=" + evt.getNewValue() + " (" + evt.getOldValue() + ") " + (evt.getOldValue() == null ? "" : evt.getOldValue().getClass().getName()));
    //	Which GridField needs to know about this change?
    GridField changedField = null;
    if (evt.getSource() instanceof CEditor) {
        changedField = ((CEditor) evt.getSource()).getField();
    } else
        return;
    //  Deal with new null values. Some editors return "" instead of null
    if ((evt.getNewValue() == null || evt.getNewValue().toString().isEmpty()) && evt.getOldValue() != null && evt.getOldValue().toString().length() > 0) {
        //  #283 Set value to null - veto if the field is mandatory
        if (!changedField.getVO().IsMandatory)
            //	-> PropertyChanged -> dynamicDisplay
            changedField.setValue(null, false);
        else
            throw new PropertyVetoException("FillMandatory", evt);
    } else {
        // is different than the old value or ignore the change
        if (evt.getNewValue() != null && !evt.getNewValue().equals(evt.getOldValue()))
            //	-> PropertyChanged -> dynamicDisplay
            changedField.setValue(evt.getNewValue(), false);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) CEditor(org.compiere.swing.CEditor) GridField(org.compiere.model.GridField)

Example 52 with GridField

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

the class SmallViewController method validateFields.

/**
	 * Validate all fields for values and mandatory
	 * @return null if nothing happens
	 */
public String validateFields() {
    log.config("");
    StringBuffer sb = new StringBuffer();
    int size = fields.size();
    for (int i = 0; i < size; i++) {
        GridField field = fields.get(i);
        //	FR [ 566 ] Only Information
        if (field == null || field.isInfoOnly())
            continue;
        // if there is an error, the field's error flag will be set
        if (!field.validateValue()) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(field.getHeader());
            CEditor editor = editors.get(i);
            if (editor != null)
                editor.setBackground(field.isError());
        }
        //  Check for Range
        GridField fieldTo = fieldsTo.get(i);
        //	Validate
        if (fieldTo != null && !fieldTo.validateValue()) {
            if (sb.length() > 0)
                sb.append(", ");
            sb.append(fieldTo.getHeader());
            CEditor editor = editorsTo.get(i);
            if (editor != null)
                editor.setBackground(fieldTo.isError());
        }
    //  range field
    }
    //	Valid if exists a error
    if (sb.length() != 0) {
        return sb.toString();
    }
    //	Nothing happened
    return null;
}
Also used : CEditor(org.compiere.swing.CEditor) GridField(org.compiere.model.GridField)

Example 53 with GridField

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

the class GridTabWrapper method getReferencedObject.

/**
	 * Load object that is referenced by given property. Example: getReferencedObject("M_Product", method) should load the M_Product record with ID given by M_Product_ID property name;
	 * 
	 * @param propertyName
	 * @param method
	 * @return
	 */
private final Object getReferencedObject(String propertyName, Method method) {
    final GridField idField = m_gridTab.getField(propertyName + "_ID");
    if (idField == null)
        return null;
    // Fetch Record_ID
    final Integer record_id = (Integer) m_gridTab.getValue(idField);
    if (record_id == null || record_id <= 0)
        return null;
    // Fetch TableName from returning class
    Class<?> cl = method.getReturnType();
    String tableName;
    try {
        tableName = (String) cl.getField("Table_Name").get(null);
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        return null;
    }
    // Load Persistent Object
    PO po = MTable.get(getCtx(), tableName).getPO(record_id, getTrxName());
    return po;
}
Also used : GridField(org.compiere.model.GridField) AdempiereException(org.adempiere.exceptions.AdempiereException) PO(org.compiere.model.PO)

Example 54 with GridField

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

the class GridTabExcelExporter method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    GridField f = m_tab.getField(col);
    Object key = m_tab.getValue(row, f.getColumnName());
    Object value = key;
    Lookup lookup = f.getLookup();
    if (lookup != null) {
        ;
    } else if (f.getDisplayType() == DisplayType.Button) {
        lookup = getButtonLookup(f);
    }
    //
    if (lookup != null) {
        value = lookup.getDisplay(key);
    }
    return value;
}
Also used : Lookup(org.compiere.model.Lookup) MLookup(org.compiere.model.MLookup) GridField(org.compiere.model.GridField)

Example 55 with GridField

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

the class BrowserRow method setValue.

/**
	 * BR[ 268 ]
	 * Set value to a column and row
	 * @param p_Row
	 * @param p_ColumnName
	 * @param p_Value
	 */
public void setValue(int p_Row, String p_ColumnName, Object p_Value) {
    //	Valid Table
    if (m_Table == null)
        return;
    Integer columnIndex = columnNamesIndex.get(p_ColumnName);
    //	Valid Index
    if (columnIndex == null)
        return;
    //	Get current Value
    GridField gridField = getValue(p_Row, columnIndex);
    gridField.setValue(p_Value, true);
    if (gridField.isDisplayed()) {
        m_Table.setValueAt(p_Row, getDisplayIndex(columnIndex), gridField);
    } else {
        setValue(p_Row, columnIndex, gridField);
    }
}
Also used : GridField(org.compiere.model.GridField)

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