use of org.compiere.model.GridField in project adempiere by adempiere.
the class Browser method getSQLWhere.
/**
* FR [ 245 ]
* FR [ 344 ] Add ColumnSQL like columns
* Get Where Clause
* @param refresh
* @return
*/
public String getSQLWhere(boolean refresh) {
if (!refresh)
return m_whereClause;
StringBuilder sql = new StringBuilder(p_whereClause);
// Valid null
LinkedHashMap<String, GridField> panelParameters = getPanelParameters();
if (panelParameters == null || panelParameters.size() == 0) {
m_whereClause = sql.toString();
return m_whereClause;
}
//
parametersValues = new ArrayList<Object>();
parameters = new ArrayList<Object>();
boolean onRange = false;
for (Entry<String, GridField> entry : panelParameters.entrySet()) {
GridField editor = (GridField) entry.getValue();
GridFieldVO field = editor.getVO();
if (!onRange) {
if (editor.getValue() != null && !editor.getValue().toString().isEmpty() && !field.IsRange) {
sql.append(" AND ");
if (DisplayType.String == field.displayType) {
if (field.ColumnName.equals("Value") || field.ColumnName.equals("DocumentNo")) {
String value = (String) editor.getValue();
if (value.contains(",")) {
value = value.replace(" ", "");
String inStr = new String(value);
StringBuffer outStr = new StringBuffer("(");
int i = inStr.indexOf(',');
while (i != -1) {
outStr.append("'" + inStr.substring(0, i) + "',");
inStr = inStr.substring(i + 1, inStr.length());
i = inStr.indexOf(',');
}
outStr.append("'" + inStr + "')");
// BR [ 342 ]
sql.append(field.ColumnSQL).append(" IN ").append(outStr);
}
} else {
sql.append(field.ColumnSQL).append(" LIKE ? ");
parameters.add(field.ColumnSQL);
parametersValues.add("%" + editor.getValue() + "%");
}
} else {
sql.append(field.ColumnSQL).append("=? ");
parameters.add(field.ColumnSQL);
parametersValues.add(editor.getValue());
}
} else if (editor.getValue() != null && !editor.getValue().toString().isEmpty() && field.IsRange) {
sql.append(" AND ");
//sql.append(field.Help).append(" BETWEEN ?");
sql.append(field.ColumnSQL).append(" >= ? ");
parameters.add(field.ColumnSQL);
parametersValues.add(editor.getValue());
onRange = true;
} else if (editor.getValue() == null && field.IsRange) {
onRange = true;
} else
continue;
} else if (editor.getValue() != null && !editor.getValue().toString().isEmpty()) {
//sql.append(" AND ? ");
sql.append(" AND ").append(field.ColumnSQL).append(" <= ? ");
parameters.add(field.ColumnSQL);
parametersValues.add(editor.getValue());
onRange = false;
} else
onRange = false;
}
m_whereClause = sql.toString();
return sql.toString();
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class VBrowserTable 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);
setValueAt(row - 1, col, gridField);
markerSet = true;
} else {
gridField.setValue(null, true);
setValueAt(row - 1, col, gridField);
}
}
}
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class WWindow method updateFields.
// executeSave
/**
* Update Field Values from Parameter
* @param request request
* @param wsc session context
* @param ws window status
* @return true if error
*/
private boolean updateFields(HttpServletRequest request, MobileSessionCtx wsc, WWindowStatus ws) {
boolean error = false;
try {
String enc = request.getCharacterEncoding();
if (enc == null)
request.setCharacterEncoding(MobileEnv.ENCODING);
} catch (Exception e) {
log.log(Level.SEVERE, "Set CharacterEncoding=" + MobileEnv.ENCODING, e);
}
// loop through parameters
Enumeration en = request.getParameterNames();
while (en.hasMoreElements()) {
String key = (String) en.nextElement();
// ignore hidden commands
if (key.equals(P_Command) || key.equals(P_ChangedColumn) || key.equals(P_MR_RowNo) || key.equals(P_Tab))
continue;
GridField mField = ws.curTab.getField(key);
// we found a writable field
if (mField != null && mField.isEditable(true)) {
String oldValue = MobileUtil.getParameter(request, key);
String newValue = MobileUtil.getParameter(request, key + "F");
String value = null;
if (newValue != null) {
Object val = lookupValue(newValue, mField.getLookup());
if (val != null)
value = val.toString();
}
if (value == null)
value = oldValue;
Object dbValue = mField.getValue();
boolean fieldError = false;
String columnName = mField.getColumnName();
log.finest(columnName + ": " + (dbValue == null ? "null" : dbValue.toString()) + " -> " + (value == null ? "null" : value.toString()));
// same = both null
if (dbValue == null && value == null)
continue;
else // new value null
if (dbValue != null && value == null)
ws.curTab.setValue(mField, null);
else // from null to new value
if (dbValue == null && value != null)
fieldError = !setFieldValue(wsc, ws, mField, value);
else // same
if (dbValue.equals(value))
continue;
else
fieldError = !setFieldValue(wsc, ws, mField, value);
//
if (!error && fieldError) {
log.info("Error: " + mField.getColumnName());
error = true;
}
}
}
/*String columnName = WebUtil.getParameter (request, P_ChangedColumn);
if (columnName != null && columnName.length() > 0)
{
GridField mField = ws.curTab.getField(columnName);
if (mField != null)
{
String value = WebUtil.getParameter(request, columnName);
Object newValue = getFieldValue (wsc, mField, value);
if (!ERROR.equals(newValue))
{
// De-Selected Check Boxes are null
if (newValue == null && mField.getDisplayType() == DisplayType.YesNo)
newValue = "N";
log.fine("ChangedColumn: " + columnName + "=" + newValue);
ws.curTab.setValue(mField, newValue);
}
}
}*/
return error;
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class WWindow method getMR_Form.
// getSR_Form
/**************************************************************************
* Return MultiRow Form details
* @param action action
* @param wsc session context
* @param ws window status
* @return Form
*/
public MobileDoc getMR_Form(String action, MobileSessionCtx wsc, WWindowStatus ws, boolean firstPage) {
log.fine("Tab=" + ws.curTab.getTabNo());
int initRowNo = ws.curTab.getCurrentRow();
String name = ws.curTab.getName();
int noFields = ws.curTab.getFieldCount();
ul list = new ul();
list.addAttribute("selected", "true");
list.setTitle(name);
String idSQL = "SELECT ColumnName, AD_Column_ID from AD_Column" + " WHERE AD_Table_ID = " + ws.curTab.getAD_Table_ID() + " AND IsIdentifier ='Y' ORDER BY SeqNo";
ValueNamePair[] idColumns = DB.getValueNamePairs(idSQL, false, null);
String primary = null;
String secondary = null;
for (ValueNamePair pair : idColumns) {
if (primary == null) {
primary = pair.getValue();
} else if (secondary == null) {
secondary = pair.getValue();
}
}
/**
* Lines
*/
int lastRow = initRowNo + MAX_LINES;
lastRow = Math.min(lastRow, ws.curTab.getRowCount());
for (int lineNo = initRowNo; lineNo >= 0 && lineNo < lastRow; lineNo++) {
// Row
ws.curTab.navigate(lineNo);
a anchor = new a();
anchor.setHref("WWindow?record=" + lineNo);
anchor.setTarget("_self");
for (int i = 1; i < 3; i++) {
GridField field = null;
if (i == 1 && primary != null && primary.length() > 0)
field = ws.curTab.getField(primary);
else if (secondary != null && secondary.length() > 0)
field = ws.curTab.getField(secondary);
if (field == null)
continue;
// Get Data - turn to string
Object data = ws.curTab.getValue(field.getColumnName());
String info = null;
//
if (data == null)
info = "";
else {
int dt = field.getDisplayType();
switch(dt) {
case DisplayType.Date:
info = wsc.dateFormat.format(data);
break;
case DisplayType.DateTime:
info = wsc.dateTimeFormat.format(data);
break;
case DisplayType.Amount:
info = wsc.amountFormat.format(data);
break;
case DisplayType.Number:
case DisplayType.CostPrice:
info = wsc.numberFormat.format(data);
break;
case DisplayType.Quantity:
info = wsc.quantityFormat.format(data);
break;
case DisplayType.Integer:
info = wsc.integerFormat.format(data);
break;
case DisplayType.YesNo:
info = Msg.getMsg(ws.ctx, data.toString());
break;
/** @todo output formatting 2 */
default:
if (DisplayType.isLookup(dt))
info = field.getLookup().getDisplay(data);
else
info = data.toString();
}
}
if (i == 1) {
// Empty info
if (info == null || info.length() == 0)
info = "No Identifier";
anchor.addElement(info);
} else if (info != null && info.length() > 0) {
div d = new div();
d.setClass("secondary");
d.addElement(info);
anchor.addElement(d);
}
}
li item = new li();
item.addElement(anchor);
list.addElement(item);
}
//return createLayout (action, list, wsc, ws, ws.curTab.getDescription(), statusDB);
MobileDoc doc = createPage(ws);
// Main Table
doc.getBody().addElement(list);
div div = new div();
div.setClass("toolbar");
h1 header = new h1();
header.setID("pageTitle");
div.addElement(header);
a anchor = new a();
anchor.setClass("button");
anchor.setHref(MobileEnv.getBaseDirectory("WMenu"));
anchor.setTarget("_self");
anchor.addElement("Menu");
div.addElement(anchor);
if (!firstPage) {
anchor = new a("WWindow?action=previous", "Back");
anchor.setID("previousButton");
anchor.setClass("button");
anchor.setTarget("_self");
div.addElement(anchor);
}
div div2 = new div();
div2.setClass("footer");
anchor = new a("WFindAdv", "Find");
anchor.setID("findButton");
anchor.setClass("blueButton");
div2.addElement(anchor);
if (!ws.curTab.isReadOnly() && ws.curTab.isInsertRecord() && ws.isReadOnlyView()) {
a a = new a("WWindow?action=insert", "New record");
a.setClass("redButton");
a.setTarget("_self");
div2.addElement(a);
}
doc.getBody().addElement(div);
doc.getBody().addElement(div2);
return doc;
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class WWindow method executeSave.
// executeCommand
/**
* Execute Save
* @param request request
* @param wsc web session
* @param ws
*/
private void executeSave(HttpServletRequest request, MobileSessionCtx wsc, WWindowStatus ws) {
log.info("");
boolean error = updateFields(request, wsc, ws);
// Check Mandatory
log.fine("Mandatory check");
int size = ws.curTab.getFieldCount();
for (int i = 0; i < size; i++) {
GridField field = ws.curTab.getField(i);
if (// context check
field.isMandatory(true)) {
Object value = field.getValue();
if (value == null || value.toString().length() == 0) {
// set editable otherwise deadlock
field.setInserting(true);
field.setError(true);
field.setErrorValue(value == null ? null : value.toString());
if (!error)
error = true;
log.info("Mandatory Error: " + field.getColumnName());
} else
field.setError(false);
}
}
if (error)
return;
// save it - of errors ignore changes
if (!ws.curTab.dataSave(true))
ws.curTab.dataIgnore();
else
ws.setRO(true);
log.fine("done");
}
Aggregations