use of org.compiere.model.GridField in project adempiere by adempiere.
the class WEditorPopupMenu method updateItemsFromEditor.
/**
* Update popup menu items from editor
* @param editor
*/
private void updateItemsFromEditor(WEditor editor) {
GridField gridField = editor.getGridField();
if (gridField == null)
return;
final int windowNo = gridField.getWindowNo();
GridTab gridTab = gridField.getGridTab();
if (gridTab == null)
return;
final int tabNo = gridTab.getTabNo();
final String columnName = gridField.getColumnName();
for (String action : ACTIONS) {
String context = buildDisableItemContext(action, columnName);
String value = Env.getContext(Env.getCtx(), windowNo, tabNo, context);
if ("Y".equals(value)) {
mapDisabledItems.put(action, true);
continue;
} else if ("N".equals(value)) {
mapDisabledItems.put(action, false);
continue;
}
// Check settings for all columns:
context = buildDisableItemContext(action, "*");
if ("Y".equals(value)) {
mapDisabledItems.put(action, true);
continue;
} else if ("N".equals(value)) {
mapDisabledItems.put(action, false);
continue;
}
}
updateItemsDyn();
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class FindWindow method setValues.
// createFields
/**
* sets the list of values of column and operator listboxes
* @param listColumn column
* @param listOperator operator
**/
private void setValues(Listbox listColumn, Listbox listOperator, String[] fields) {
// 0 = Columns
ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
for (int c = 0; c < m_findFields.length; c++) {
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
if (header == null || header.length() == 0) {
header = Msg.translate(Env.getCtx(), columnName);
if (header == null || header.length() == 0)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
items.add(pp);
}
ValueNamePair[] cols = new ValueNamePair[items.size()];
items.toArray(cols);
// sort alpha
Arrays.sort(cols);
ValueNamePair[] op = MQuery.OPERATORS;
if (fields == null) {
listColumn.appendItem("", "");
for (ValueNamePair item : cols) listColumn.appendItem(item.getName(), item.getValue());
listColumn.setSelectedIndex(0);
for (ValueNamePair item : op) listOperator.appendItem(item.getName(), item.getValue());
listOperator.setSelectedIndex(0);
} else {
// 0 - column
String columnName = fields.length > 0 ? fields[0] : "";
// 1 - operator
String operator = fields.length > 1 ? fields[1] : "";
boolean selected = false;
listColumn.appendItem("", "");
for (int i = 0; i < cols.length; i++) {
ValueNamePair item = cols[i];
ListItem li = listColumn.appendItem(item.getName(), item.getValue());
if (item.getValue().equals(columnName)) {
listColumn.setSelectedItem(li);
selected = true;
}
}
if (!selected)
listColumn.setSelectedIndex(0);
selected = false;
for (int i = 0; i < op.length; i++) {
ValueNamePair item = op[i];
ListItem li = listOperator.appendItem(item.getName(), item.getValue());
if (item.getValue().equals(operator)) {
listOperator.setSelectedItem(li);
selected = true;
}
}
if (!selected)
listOperator.setSelectedIndex(0);
}
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class FindWindow method cmd_ok_Simple.
// getTargetMField
/**
* Simple OK Button pressed
**/
private void cmd_ok_Simple() {
// Create Query String
m_query = new MQuery(m_tableName);
if (hasValue && !fieldValue.getText().equals("%") && fieldValue.getText().length() != 0) {
String value = fieldValue.getText().toUpperCase();
if (!value.endsWith("%"))
value += "%";
m_query.addRestriction("UPPER(Value)", MQuery.LIKE, value, lblValue.getValue(), value);
}
//
if (hasDocNo && !fieldDocumentNo.getText().equals("%") && fieldDocumentNo.getText().length() != 0) {
String value = fieldDocumentNo.getText().toUpperCase();
if (!value.endsWith("%"))
value += "%";
m_query.addRestriction("UPPER(DocumentNo)", MQuery.LIKE, value, lblDocumentNo.getValue(), value);
}
//
if ((hasName) && !fieldName.getText().equals("%") && fieldName.getText().length() != 0) {
String value = fieldName.getText().toUpperCase();
if (!value.endsWith("%"))
value += "%";
m_query.addRestriction("UPPER(Name)", MQuery.LIKE, value, lblName.getValue(), value);
}
//
if (hasDescription && !fieldDescription.getText().equals("%") && fieldDescription.getText().length() != 0) {
String value = fieldDescription.getText().toUpperCase();
if (!value.endsWith("%"))
value += "%";
m_query.addRestriction("UPPER(Description)", MQuery.LIKE, value, lblDescription.getValue(), value);
}
// Special Editors
for (int i = 0; i < m_sEditors.size(); i++) {
WEditor wed = (WEditor) m_sEditors.get(i);
Object value = wed.getValue();
Object modifiedvalue = null;
String ColumnSQL = null;
String ColumnName = wed.getColumnName();
GridField field = getTargetMField(ColumnName);
if (value != null && value.toString().length() > 0) {
log.fine(ColumnName + "=" + value);
// globalqss - Carlos Ruiz - 20060711
// fix a bug with virtualColumn + isSelectionColumn not yielding results
field = getTargetMField(ColumnName);
// add encryption here if the field is encrypted.
if (field.isEncryptedColumn()) {
value = SecureEngine.encrypt(value);
}
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
ColumnSQL = field.getColumnSQL(false);
// Be more permissive for String columns
if (isSearchLike(field)) {
String valueStr = value.toString().toUpperCase();
if (!valueStr.endsWith("%"))
valueStr += "%";
//
ColumnSQL = "UPPER(" + ColumnSQL + ")";
modifiedvalue = valueStr;
} else
modifiedvalue = value;
//
if (modifiedvalue.toString().indexOf('%') != -1 && !field.isRangeLookup())
m_query.addRestriction(ColumnSQL, MQuery.LIKE, modifiedvalue, ColumnName, wed.getDisplay());
else if (isProductCategoryField && value instanceof Integer)
m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
else if (//20121115
!field.isRangeLookup())
m_query.addRestriction(ColumnSQL, MQuery.EQUAL, value, ColumnName, wed.getDisplay());
/*
if (value.toString().indexOf('%') != -1)
m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay());
else
m_query.addRestriction(ColumnName, MQuery.EQUAL, value, ColumnName, ved.getDisplay());
*/
// end globalqss patch
}
if (field.isRangeLookup()) {
WEditor toRangeEditor = (WEditor) m_sEditors2.get(i);
Object value2 = null;
Object parsedValue = null;
Object parsedValue2 = null;
String infoDisplay_to = null;
String infoDisplay = null;
if (toRangeEditor != null)
value2 = toRangeEditor.getValue();
if ((value != null && !value.toString().isEmpty()) && (value2 != null && !value2.toString().isEmpty()) && value2.toString().length() > 0) {
ColumnName = toRangeEditor.getColumnName();
log.fine(ColumnName + "=" + value2);
field = getTargetMField(ColumnName);
infoDisplay = value.toString();
parsedValue = parseValue(field, value);
parsedValue2 = parseValue(field, value2);
infoDisplay_to = value2.toString();
if (parsedValue2 == null)
continue;
m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, ColumnSQL, infoDisplay, infoDisplay_to);
} else // then get all the records after the First value
if (value != null && !value.toString().isEmpty() && (value2 == null || value2.toString().isEmpty())) {
ColumnName = wed.getColumnName();
m_query.addRestriction(ColumnSQL, MQuery.GREATER_EQUAL, value, ColumnName, wed.getDisplay());
} else // then get all the records before the second value
if ((value == null || value.toString().isEmpty()) && value2 != null && !value2.toString().isEmpty()) {
ColumnName = toRangeEditor.getColumnName();
field = getTargetMField(ColumnName);
ColumnSQL = field.getColumnSQL(false);
m_query.addRestriction(ColumnSQL, MQuery.LESS_EQUAL, value2, ColumnName, toRangeEditor.getDisplay());
}
}
}
// editors
// teo_sarca [ 1708717 ]
m_isCancel = false;
// Test for no records
if (getNoOfRecords(m_query, true) != 0)
dispose();
}
use of org.compiere.model.GridField in project adempiere by adempiere.
the class FindWindow method codeUserQuery.
// cmd_save
/**
* 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()}. Also updates the {@link #m_query} variable with
* the current query information.
* @return a StringBuffer containing the coded query information.
*/
private StringBuffer codeUserQuery() {
m_query = new MQuery(m_tableName);
StringBuffer code = new StringBuffer();
int openBrackets = 0;
List<?> rowList = advancedPanel.getChildren();
for (int rowIndex = 1; rowIndex < rowList.size(); rowIndex++) {
// Column
ListItem row = (ListItem) rowList.get(rowIndex);
Listbox column = (Listbox) row.getFellow("listColumn" + row.getId());
if (column == null)
continue;
String ColumnName = column.getSelectedItem().getValue().toString();
String infoName = column.toString();
//
GridField field = getTargetMField(ColumnName);
if (field == null)
// Elaine 2008/07/29
continue;
boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
String ColumnSQL = field.getColumnSQL(false);
// Left brackets
Listbox listLeftBracket = (Listbox) row.getFellow("listLeftBracket" + row.getId());
String lBrackets = listLeftBracket.getSelectedItem().getValue().toString();
if (lBrackets != null)
openBrackets += lBrackets.length();
// Right brackets
Listbox listRightBracket = (Listbox) row.getFellow("listRightBracket" + row.getId());
String rBrackets = listRightBracket.getSelectedItem().getValue().toString();
if (rBrackets != null)
openBrackets -= rBrackets.length();
// And Or
Listbox listAndOr = (Listbox) row.getFellow("listAndOr" + row.getId());
String andOr = listAndOr.getSelectedItem().getValue().toString();
boolean and = true;
if (rowIndex > 1) {
and = !"OR".equals(andOr);
}
// Op
Listbox op = (Listbox) row.getFellow("listOperator" + row.getId());
if (op == null)
continue;
String Operator = op.getSelectedItem().getValue().toString();
// Value ******
ListCell cellQueryFrom = (ListCell) row.getFellow("cellQueryFrom" + row.getId());
Object value = cellQueryFrom.getAttribute("value");
ListCell cellQueryTo = (ListCell) row.getFellow("cellQueryTo" + row.getId());
Object value2 = cellQueryTo.getAttribute("value");
if (value == null) {
// Capture the case "is 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);
} else {
continue;
}
} else {
// Value has a value - check for range too.
Object parsedValue = parseValue(field, value);
if (parsedValue == null)
continue;
//TODO - verify compatibility with find.java
if (field.isEncryptedColumn()) {
value = SecureEngine.encrypt(value);
}
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 ******
if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op.getSelectedItem().toValueNamePair())) {
if (value2 == null)
continue;
Object parsedValue2 = parseValue(field, value2);
String infoDisplay_to = value2.toString();
if (parsedValue2 == null)
continue;
//encrypt the value if we are searching an encrypted column.
if (field.isEncryptedColumn()) {
value2 = SecureEngine.encrypt(value2);
}
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(andOr).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 FindWindow method initFind.
private void initFind() {
log.config("");
// Get Info from target Tab
int parameterNo = 0;
for (int i = 0; i < m_findFields.length; i++) {
GridField mField = m_findFields[i];
if (mField.isSelectionColumn())
parameterNo++;
}
if (parameterNo >= 7)
isTwoColumns = true;
for (int i = 0; i < m_findFields.length; i++) {
GridField mField = m_findFields[i];
// Make Yes-No searchable as list
if (mField.getVO().displayType == DisplayType.YesNo) {
GridFieldVO vo = mField.getVO();
GridFieldVO ynvo = vo.clone(vo.ctx, vo.WindowNo, vo.TabNo, vo.AD_Window_ID, vo.AD_Tab_ID, vo.tabReadOnly);
ynvo.IsDisplayed = true;
ynvo.displayType = DisplayType.List;
ynvo.AD_Reference_Value_ID = AD_REFERENCE_ID_YESNO;
ynvo.lookupInfo = MLookupFactory.getLookupInfo(ynvo.ctx, ynvo.WindowNo, ynvo.AD_Column_ID, ynvo.displayType, Env.getLanguage(ynvo.ctx), ynvo.ColumnName, ynvo.AD_Reference_Value_ID, ynvo.IsParent, ynvo.ValidationCode);
ynvo.lookupInfo.InfoFactoryClass = ynvo.InfoFactoryClass;
GridField ynfield = new GridField(ynvo);
// replace the original field by the YN List field
m_findFields[i] = ynfield;
mField = ynfield;
}
// Make Buttons searchable
if (mField.getVO().displayType == DisplayType.Button) {
GridFieldVO vo = mField.getVO();
if (vo.AD_Reference_Value_ID > 0) {
GridFieldVO postedvo = vo.clone(vo.ctx, vo.WindowNo, vo.TabNo, vo.AD_Window_ID, vo.AD_Tab_ID, vo.tabReadOnly);
postedvo.IsDisplayed = true;
postedvo.displayType = DisplayType.List;
postedvo.lookupInfo = MLookupFactory.getLookupInfo(postedvo.ctx, postedvo.WindowNo, postedvo.AD_Column_ID, postedvo.displayType, Env.getLanguage(postedvo.ctx), postedvo.ColumnName, postedvo.AD_Reference_Value_ID, postedvo.IsParent, postedvo.ValidationCode);
postedvo.lookupInfo.InfoFactoryClass = postedvo.InfoFactoryClass;
GridField postedfield = new GridField(postedvo);
// replace the original field by the Posted List field
m_findFields[i] = postedfield;
mField = postedfield;
}
}
/** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214
if (columnName.equals("Value"))
hasValue = true;
else if (columnName.equals("Name"))
hasName = true;
else if (columnName.equals("DocumentNo"))
hasDocNo = true;
else if (columnName.equals("Description"))
hasDescription = true;
else
/**/
if (mField.isSelectionColumn()) {
addSelectionColumn(mField);
isPair = !isPair;
}
/** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214
else if (columnName.indexOf("Name") != -1)
addSelectionColumn (mField);
/**/
// TargetFields
m_targetFields.put(new Integer(mField.getAD_Column_ID()), mField);
}
// for all target tab fields
// Disable simple query fields
pnlValue.setVisible(hasValue);
if (hasValue)
fieldValue.addEventListener(Events.ON_CHANGE, this);
pnlDocument.setVisible(hasDocNo);
if (hasDocNo)
fieldDocumentNo.addEventListener(Events.ON_CHANGE, this);
pnlName.setVisible(hasName);
if (hasName)
fieldName.addEventListener(Events.ON_CHANGE, this);
pnlDescription.setVisible(hasDescription);
if (hasDescription)
fieldDescription.addEventListener(Events.ON_CHANGE, this);
m_total = getNoOfRecords(null, false);
}
Aggregations