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);
}
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations