use of org.compiere.model.GridField in project adempiere by adempiere.
the class FindValueRenderer method getTableCellRendererComponent.
// getCheck
/*************************************************************************
* Get TableCell RendererComponent
* @param table table
* @param value value
* @param isSelected selected
* @param hasFocus focus
* @param row row
* @param col col
* @return renderer component (Label or CheckBox)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
// log.config( "FindValueRenderer.getTableCellRendererComponent", "r=" + row + ", c=" + col );
// Column
m_columnName = null;
Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
if (column != null) {
if (column instanceof ValueNamePair)
m_columnName = ((ValueNamePair) column).getValue();
else
m_columnName = column.toString();
}
// Between - enables valueToColumn
m_between = false;
Object betweenValue = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
if (m_valueToColumn && betweenValue != null && betweenValue.equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX]))
m_between = true;
boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
// set Background
if (enabled)
setBackground(AdempierePLAF.getFieldBackground_Normal());
else
setBackground(AdempierePLAF.getFieldBackground_Inactive());
// log.config( "FindValueRenderer.getTableCellRendererComponent - (" + value + ") - Enabled=" + enabled);
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
if (value == null || (m_valueToColumn && !m_between))
return c;
//
GridField field = getMField();
if (field != null && field.getDisplayType() == DisplayType.YesNo) {
JCheckBox cb = getCheck();
if (value instanceof Boolean)
cb.setSelected(((Boolean) value).booleanValue());
else
cb.setSelected(value.toString().indexOf('Y') != -1);
return cb;
}
return c;
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class FindValueRenderer method setValue.
// getTableCellRendererComponent
/**************************************************************************
* Format Display Value
* @param value value
*/
protected void setValue(Object value) {
boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
// Log.trace (Log.l4_Data, "FindValueRenderer.setValue (" + value + ") - Enabled=" + enabled);
if (value == null || !enabled) {
super.setValue(null);
return;
}
String retValue = null;
// Strip ' '
if (value != null) {
String str = value.toString();
if (str.startsWith("'") && str.endsWith("'")) {
str = str.substring(1, str.length() - 1);
value = str;
}
}
int displayType = 0;
GridField field = getMField();
if (field != null)
displayType = field.getDisplayType();
else
log.log(Level.SEVERE, "FindValueRenderer.setValue (" + value + ") ColumnName=" + m_columnName + " No Target Column");
setHorizontalAlignment(JLabel.LEFT);
// Number
if (DisplayType.isNumeric(displayType)) {
setHorizontalAlignment(JLabel.RIGHT);
retValue = DisplayType.getNumberFormat(displayType).format(value);
} else // Date
if (DisplayType.isDate(displayType)) {
if (value instanceof Date) {
retValue = DisplayType.getDateFormat(displayType).format(value);
setHorizontalAlignment(JLabel.RIGHT);
} else if (// JDBC format
value instanceof String) {
try {
java.util.Date date = DisplayType.getDateFormat_JDBC().parse((String) value);
retValue = DisplayType.getDateFormat(displayType).format(date);
setHorizontalAlignment(JLabel.RIGHT);
} catch (Exception e) {
// log.log(Level.SEVERE, "FindValueRenderer.setValue", e);
retValue = value.toString();
}
} else
retValue = value.toString();
} else // Row ID
if (displayType == DisplayType.RowID)
retValue = "";
else // Lookup
if (DisplayType.isLookup(displayType) && field != null) {
Lookup lookup = field.getLookup();
if (lookup != null)
retValue = lookup.getDisplay(value);
} else // other
{
super.setValue(value);
return;
}
// log.config( "FindValueRenderer.setValue (" + retValue + ") - DT=" + displayType);
super.setValue(retValue);
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class Find method codeUserQuery.
// actionPerformed
/**
* Code the query parameters entered in the table into a string that can be saved in the database.
* This is the counterpart to {@link #parseUserQuery()}.
* @return a StringBuffer containing the coded query information.
*/
private StringBuffer codeUserQuery() {
advancedTable.stopEditor(true);
m_query = new MQuery(m_tableName);
m_query.addRestriction(Env.parseContext(Env.getCtx(), m_targetWindowNo, m_whereExtended, false));
StringBuffer code = new StringBuffer();
int openBrackets = 0;
for (int row = 0; row < advancedTable.getRowCount(); row++) {
// Column
Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME);
if (column == null)
continue;
String ColumnName = column instanceof ValueNamePair ? ((ValueNamePair) column).getValue() : column.toString();
String infoName = column.toString();
//
GridField field = getTargetMField(ColumnName);
if (field == null)
continue;
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
String ColumnSQL = field.getColumnSQL(false);
String lBrackets = (String) advancedTable.getValueAt(row, INDEX_LEFTBRACKET);
if (lBrackets != null)
openBrackets += lBrackets.length();
String rBrackets = (String) advancedTable.getValueAt(row, INDEX_RIGHTBRACKET);
if (rBrackets != null)
openBrackets -= rBrackets.length();
boolean and = true;
if (row > 0)
and = !"OR".equals((String) advancedTable.getValueAt(row, INDEX_ANDOR));
// Op
Object op = advancedTable.getValueAt(row, INDEX_OPERATOR);
if (op == null)
continue;
String Operator = ((ValueNamePair) op).getValue();
// Value ******
Object value = advancedTable.getValueAt(row, INDEX_VALUE);
if (value == null) {
if (MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op)) {
m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets);
if (code.length() > 0)
code.append(SEGMENT_SEPARATOR);
code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append("").append(FIELD_SEPARATOR).append(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
} else {
continue;
}
} else {
Object parsedValue = parseValue(field, value);
if (parsedValue == null)
continue;
String infoDisplay = value.toString();
if (field.isLookup())
infoDisplay = field.getLookup().getDisplay(value);
else if (field.getDisplayType() == DisplayType.YesNo)
infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay);
// Value2 ******
Object value2 = null;
if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op)) {
value2 = advancedTable.getValueAt(row, INDEX_VALUE2);
if (value2 == null)
continue;
Object parsedValue2 = parseValue(field, value2);
String infoDisplay_to = value2.toString();
if (parsedValue2 == null)
continue;
m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, infoName, infoDisplay, infoDisplay_to, and, openBrackets);
} else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
if (!(parsedValue instanceof Integer)) {
continue;
}
m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
} else
m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets);
if (code.length() > 0)
code.append(SEGMENT_SEPARATOR);
code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append(value.toString()).append(FIELD_SEPARATOR).append(value2 != null ? value2.toString() : "").append(FIELD_SEPARATOR).append(and ? "AND" : "OR").append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
}
}
return code;
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class Viewer method cmd_find.
// cmd_report
/**
* Query Report
*/
private void cmd_find() {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
String title = null;
String tableName = null;
// Get Find Tab Info
String sql = "SELECT t.AD_Tab_ID " + // ,w.Name, t.Name, w.IsDefault, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)
"FROM AD_Tab t" + " INNER JOIN AD_Window w ON (t.AD_Window_ID=w.AD_Window_ID)" + " INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) " + "WHERE tt.AD_Table_ID=? " + "ORDER BY w.IsDefault DESC, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)";
int AD_Tab_ID = DB.getSQLValue(null, sql, AD_Table_ID);
// ASP
MClient client = MClient.get(Env.getCtx());
String ASPFilter = "";
if (client.isUseASP())
ASPFilter = " AND ( AD_Tab_ID IN ( " + // Just ASP subscribed tabs for client "
" SELECT t.AD_Tab_ID " + " FROM ASP_Tab t, ASP_Window w, ASP_Level l, ASP_ClientLevel cl " + " WHERE w.ASP_Level_ID = l.ASP_Level_ID " + " AND cl.AD_Client_ID = " + client.getAD_Client_ID() + " AND cl.ASP_Level_ID = l.ASP_Level_ID " + " AND t.ASP_Window_ID = w.ASP_Window_ID " + " AND t.IsActive = 'Y' " + " AND w.IsActive = 'Y' " + " AND l.IsActive = 'Y' " + " AND cl.IsActive = 'Y' " + // Show
" AND t.ASP_Status = 'S') " + " OR AD_Tab_ID IN ( " + // + show ASP exceptions for client
" SELECT AD_Tab_ID " + " FROM ASP_ClientException ce " + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + " AND ce.IsActive = 'Y' " + " AND ce.AD_Tab_ID IS NOT NULL " + " AND ce.AD_Field_ID IS NULL " + // Show
" AND ce.ASP_Status = 'S') " + " ) " + " AND AD_Tab_ID NOT IN ( " + // minus hide ASP exceptions for client
" SELECT AD_Tab_ID " + " FROM ASP_ClientException ce " + " WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + " AND ce.IsActive = 'Y' " + " AND ce.AD_Tab_ID IS NOT NULL " + " AND ce.AD_Field_ID IS NULL " + // Hide
" AND ce.ASP_Status = 'H')";
//
sql = "SELECT Name, TableName FROM AD_Tab_v WHERE AD_Tab_ID=? " + ASPFilter;
if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab"))
sql = "SELECT Name, TableName FROM AD_Tab_vt WHERE AD_Tab_ID=?" + " AND AD_Language='" + Env.getAD_Language(Env.getCtx()) + "' " + ASPFilter;
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Tab_ID);
ResultSet rs = pstmt.executeQuery();
//
if (rs.next()) {
title = rs.getString(1);
tableName = rs.getString(2);
}
//
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
GridField[] findFields = null;
if (tableName != null)
findFields = GridField.createFields(m_ctx, m_WindowNo, 0, AD_Tab_ID);
// FR [ 295 ]
if (findFields == null) {
// No Tab for Table exists
if (launchProcessPara()) {
revalidate();
} else {
return;
}
} else {
ASearch search = new ASearch(bFind, this, title, AD_Tab_ID, AD_Table_ID, tableName, m_reportEngine, findFields, 1);
search = null;
revalidate();
}
// setCursor
cmd_drill();
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class ADServiceImpl method updateFields.
/**
* Update Field Values from Parameter
* @param request request
* @param wsc session context
* @param ws window status
* @return true if error
*/
private boolean updateFields(WWindowStatus ws, DataRow dr) {
boolean error = false;
//request.getParameterNames();
Enumeration en = null;
DataField[] df = dr.getFieldArray();
DataField f;
for (int i = 0; i < df.length; i++) {
//String key = (String)en.nextElement();
f = df[i];
String cn = f.getColumn();
GridField GridField = ws.curTab.getField(cn);
if (!GridField.isDisplayed(false))
continue;
if (// kolec - byl dopisany warunek na 'DocAction' ale to nie jest ok: && !cn.equals("DocAction")
GridField.getDisplayType() == DisplayType.Button)
continue;
if (GridField != null && GridField.isEditable(true)) {
//!!!!
String value = f.getVal();
// kolec (plaba -cos wstawia do input type="text")
if (value.length() == 0)
value = null;
//kolec
if (value != null && (value.equals("-1")) && GridField.isLookup())
value = null;
if (GridField.getDisplayType() == DisplayType.YesNo) {
if (value != null && (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")))
value = value.toLowerCase();
//if (value != null && value.equalsIgnoreCase("null"))
// value = "false";
//if (value == null)
// value = "false";
}
Object dbValue = GridField.getValue();
boolean fieldError = false;
String columnName = GridField.getColumnName();
if (dbValue == null && value == null)
continue;
else // new value null
if (dbValue != null && value == null)
ws.curTab.setValue(GridField, null);
else // from null to new value
if (dbValue == null && value != null) {
fieldError = !setFieldValue(ws, GridField, value);
} else if (dbValue.equals(value))
continue;
else
fieldError = !setFieldValue(ws, GridField, value);
//
if (!error && fieldError) {
//log.info("Error: " + GridField.getColumnName());
error = true;
}
}
}
return error;
}
Aggregations