use of org.compiere.grid.ed.VString in project adempiere by adempiere.
the class GridController method dynamicDisplay.
// propertyChange
/**
* Dynamic Display.
* - Single Row Screen layout and update of dynamic Lookups
* <p>
* Single Row layout:
* the components's name is the ColumnName; if it matches, the
* MField.isDisplayed(true) is used to determine if it is visible
* if the component is a VEditor, setEnabled is set from the MField
* <p>
* Multi Row layout is not changed:
* VCellRenderer calls JTable.isCellEditable -> checks MField.isEditable (Active, isDisplayed)
* VCellEditor.isCellEditable calls MField.isEditable(true) <br>
* If a column is not displayed, the width is set to 0 in dynInit
* <p>
* Dynamic update of data is handeled in VLookup.focusGained/Lost.
* When focus is gained the model is temporarily updated with the
* specific validated data, if lost, it is switched back to the
* unvalidated data (i.e. everything). This allows that the display
* methods have a lookup to display. <br>
* Here: if the changed field has dependents and the dependent
* is a Lookup and this lookup has a dynamic dependence of the changed field,
* the value of that field is set to null (in MTab.processDependencies -
* otherwise it would show an invalid value).
* As Editors listen for value changed of their MField, the display is updated.
* <p>
* Called from GridController.valueChanged/dataStatusChanged, APane;.stateChanged/unlock/cmd_...
* @param col selective column number or 0 if all
*/
public void dynamicDisplay(int col) {
// Don't update if multi-row
if (!isSingleRow() || m_onlyMultiRow)
return;
if (!m_mTab.isOpen())
return;
// Selective
if (col > 0) {
GridField changedField = m_mTab.getField(col);
String columnName = changedField.getColumnName();
ArrayList<GridField> dependants = m_mTab.getDependantFields(columnName);
log.config("(" + m_mTab.toString() + ") " + columnName + " - Dependents=" + dependants.size());
// No Dependents and no Callout - Set just Background
if (dependants.size() == 0 && changedField.getCallout().length() == 0) {
Component[] comp = vPanel.getComponentsRecursive();
for (int i = 0; i < comp.length; i++) {
if (columnName.equals(comp[i].getName()) && comp[i] instanceof VEditor) {
VEditor ve = (VEditor) comp[i];
boolean manMissing = false;
boolean noValue = changedField.getValue() == null || changedField.getValue().toString().length() == 0;
if (// check context
noValue && changedField.isEditable(true) && changedField.isMandatory(true))
manMissing = true;
ve.setBackground(manMissing || changedField.isError());
break;
}
}
return;
}
}
// selective
// complete single row re-display
boolean noData = m_mTab.getRowCount() == 0;
log.config(m_mTab.toString() + " - Rows=" + m_mTab.getRowCount());
// All Components in vPanel (Single Row)
Set<String> hiddens = new HashSet<String>();
Component[] comps = vPanel.getComponentsRecursive();
for (int i = 0; i < comps.length; i++) {
Component comp = comps[i];
String columnName = comp.getName();
if (comp instanceof VChart && isSingleRow()) {
((VChart) comp).createChart();
}
if (columnName != null && columnName.length() > 0) {
GridField mField = m_mTab.getField(columnName);
if (mField != null) {
if (// check context
mField.isDisplayed(true)) {
if (!comp.isVisible())
// visibility
comp.setVisible(true);
/**
* Feature Request [1707462]
* Enable runtime change of VFormat
* @author fer_luck
*/
if (comp instanceof VString) {
VString vs = (VString) comp;
if ((vs.getVFormat() != null && vs.getVFormat().length() > 0 && mField.getVFormat() == null) || (vs.getVFormat() == null && mField.getVFormat() != null && mField.getVFormat().length() > 0) || (vs.getVFormat() != null && mField.getVFormat() != null && !vs.getVFormat().equals(mField.getVFormat()))) {
vs.setVFormat(mField.getVFormat());
}
}
//End Feature Request [1707462]
if (comp instanceof VEditor) {
VEditor ve = (VEditor) comp;
if (noData)
ve.setReadWrite(false);
else {
// r/w - check Context
boolean rw = mField.isEditable(true);
ve.setReadWrite(rw);
// log.log(Level.FINEST, "RW=" + rw + " " + mField);
boolean manMissing = false;
// least expensive operations first // missing mandatory
if (rw && (mField.getValue() == null || mField.getValue().toString().isEmpty()) && // check context. Some fields can return "" instead of null
mField.isMandatory(true))
manMissing = true;
ve.setBackground(manMissing || mField.isError());
}
}
} else {
if (comp.isVisible())
comp.setVisible(false);
hiddens.add(columnName);
}
}
}
}
// hide empty field group based on the environment
for (int i = 0; i < comps.length; i++) {
Component comp = comps[i];
if (comp instanceof CollapsiblePanel) {
if (comp.getName() == null || comp.getName().startsWith("IncludedTab#"))
continue;
else {
boolean hasVisible = false;
Component[] childs = ((CollapsiblePanel) comp).getCollapsiblePane().getContentPane().getComponents();
for (int j = 0; j < childs.length; j++) {
if (childs[j].isVisible()) {
String columnName = childs[j].getName();
if (columnName != null && columnName.length() > 0) {
GridField mField = m_mTab.getField(columnName);
if (mField != null) {
hasVisible = true;
break;
}
}
}
}
if (comp.isVisible() != hasVisible)
comp.setVisible(hasVisible);
}
}
}
//
log.config(m_mTab.toString() + " - fini - " + (col <= 0 ? "complete" : "seletive"));
}
use of org.compiere.grid.ed.VString in project adempiere by adempiere.
the class InfoPAttribute method createQuery.
// actionPerformed
/**
* Create Query
* <code>
* Available synonyms:
* M_Product p
* M_ProductPrice pr
* M_AttributeSet pa
* </code>
* @return query
*/
private String createQuery() {
/** Base Query
SELECT *
FROM M_Product p
INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)
LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)
WHERE
**/
/*** Instance Attributes */
StringBuffer sb = new StringBuffer();
// Serial No
String s = serNoField.getText();
if (s != null && s.length() > 0) {
sb.append(" AND asi.SerNo");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot Number
s = lotField.getText();
if (s != null && s.length() > 0) {
sb.append(" AND asi.Lot");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot ID
KeyNamePair pp = (KeyNamePair) lotSelection.getSelectedItem();
if (pp != null && pp.getKey() != -1) {
int ID = pp.getKey();
sb.append(" AND asi.M_Lot_ID=").append(ID);
}
// Guarantee Date
Timestamp ts = (Timestamp) guaranteeDateField.getValue();
if (ts != null) {
sb.append(" AND TRUNC(asi.GuaranteeDate, 'DD')");
// < = >
int index = guaranteeDateSelection.getSelectedIndex();
if (index == 0)
sb.append("<");
else if (index == 1)
sb.append("=");
else
sb.append(">");
sb.append(DB.TO_DATE(ts, true));
}
// Instance Editors
for (int i = 0; i < m_instanceEditors.size(); i++) {
StringBuffer iAttr = new StringBuffer();
Component c = (Component) m_instanceEditors.get(i);
Component cTo = (Component) m_instanceEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getName());
if (c instanceof VComboBox) {
VComboBox field = (VComboBox) c;
pp = (KeyNamePair) field.getSelectedItem();
if (pp != null && pp.getKey() != -1) {
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
} else if (c instanceof VNumber) {
VNumber field = (VNumber) c;
BigDecimal value = (BigDecimal) field.getValue();
VNumber fieldTo = (VNumber) cTo;
BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
if (value != null || valueTo != null) {
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
if (value != null && valueTo == null)
iAttr.append("=").append(value);
else if (value == null && valueTo != null)
iAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
iAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
}
} else {
VString field = (VString) c;
String value = field.getText();
if (value != null && value.length() > 0) {
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
iAttr.append("=");
else
iAttr.append(" LIKE ");
iAttr.append(DB.TO_STRING(value));
}
}
// Add to where
if (iAttr.length() > 0)
sb.append(" AND asi.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance " + "WHERE ").append(iAttr).append(")");
}
// finish Instance Attributes
if (sb.length() > 0) {
sb.insert(0, " AND EXISTS (SELECT * FROM M_Storage s" + " INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) " + "WHERE s.M_Product_ID=p.M_Product_ID");
sb.append(")");
}
// Product Attributes
for (int i = 0; i < m_productEditors.size(); i++) {
StringBuffer pAttr = new StringBuffer();
Component c = (Component) m_productEditors.get(i);
Component cTo = (Component) m_productEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getName());
if (c instanceof VComboBox) {
VComboBox field = (VComboBox) c;
pp = (KeyNamePair) field.getSelectedItem();
if (pp != null && pp.getKey() != -1) {
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
} else if (c instanceof VNumber) {
VNumber field = (VNumber) c;
BigDecimal value = (BigDecimal) field.getValue();
VNumber fieldTo = (VNumber) cTo;
BigDecimal valueTo = (BigDecimal) fieldTo.getValue();
if (value != null || valueTo != null) {
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND ValueNumber");
if (value != null && valueTo == null)
pAttr.append("=").append(value);
else if (value == null && valueTo != null)
pAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
pAttr.append(" BETWEEN ").append(value).append(" AND ").append(valueTo);
}
} else {
VString field = (VString) c;
String value = field.getText();
if (value != null && value.length() > 0) {
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID).append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
pAttr.append("=");
else
pAttr.append(" LIKE ");
pAttr.append(DB.TO_STRING(value));
}
}
// Add to Where
if (pAttr.length() > 0)
sb.append(" AND p.M_AttributeSetInstance_ID IN " + "(SELECT M_AttributeSetInstance_ID " + "FROM M_AttributeInstance WHERE ").append(pAttr).append(")");
}
//
m_query = null;
if (sb.length() > 0)
m_query = sb.toString();
log.config(m_query);
return m_query;
}
use of org.compiere.grid.ed.VString in project adempiere by adempiere.
the class InfoPAttribute method setDisplay.
/**
* Set the display text
*/
private void setDisplay() {
StringBuffer display = new StringBuffer();
if (serNoField != null && serNoField.getValue().toString().length() > 0)
display.append(serNoField.getValue().toString() + "-");
if (lotField != null && lotField.getValue().toString().length() > 0)
display.append(lotField.getValue().toString() + "-");
if (lotSelection != null && lotSelection.getDisplay().length() > 0)
display.append(lotSelection.getDisplay() + "-");
if (guaranteeDateField != null && guaranteeDateField.getValue() != null)
display.append(guaranteeDateSelection.getDisplay() + guaranteeDateField.getValue().toString() + "-");
for (int i = 0; i < m_productEditors.size(); i++) {
Component c = (Component) m_productEditors.get(i);
Component cTo = (Component) m_productEditorsTo.get(i);
if (c instanceof VComboBox) {
VComboBox field = (VComboBox) c;
display.append(field.getDisplay() + "-");
} else if (c instanceof VNumber) {
VNumber field = (VNumber) c;
display.append(field.getDisplay() + "-");
VNumber fieldTo = (VNumber) cTo;
display.append(fieldTo.getDisplay() + "-");
} else {
VString field = (VString) c;
display.append(field.getDisplay() + "-");
}
}
for (int i = 0; i < m_instanceEditors.size(); i++) {
Component c = (Component) m_instanceEditors.get(i);
Component cTo = (Component) m_instanceEditorsTo.get(i);
if (c instanceof VComboBox) {
VComboBox field = (VComboBox) c;
display.append(field.getDisplay() + "-");
} else if (c instanceof VNumber) {
VNumber field = (VNumber) c;
display.append(field.getDisplay() + "-");
VNumber fieldTo = (VNumber) cTo;
display.append(fieldTo.getDisplay() + "-");
} else {
VString field = (VString) c;
display.append(field.getDisplay() + "-");
}
}
// TODO - there is a more elegant way to do this.
while (display.toString().contains("--") && display.length() > 1) {
display.delete(display.indexOf("--"), display.indexOf("--") + 1);
}
while (display.toString().startsWith("-") && display.length() >= 1) {
display.delete(0, 1);
}
while (display.toString().endsWith("-") && display.length() >= 1) {
display.delete(display.length() - 1, display.length());
}
m_display = display.toString();
}
use of org.compiere.grid.ed.VString in project lar_361 by comitsrl.
the class VCreateFromStatementUI method dynInit.
/**
* Dynamic Init
* @throws Exception if Lookups cannot be initialized
* @return true if initialized
*/
public boolean dynInit() throws Exception {
log.config("");
super.dynInit();
// Refresh button
CButton refreshButton = ConfirmPanel.createRefreshButton(false);
refreshButton.setMargin(new Insets(1, 10, 0, 10));
refreshButton.setDefaultCapable(true);
refreshButton.addActionListener(this);
dialog.getConfirmPanel().addButton(refreshButton);
dialog.getRootPane().setDefaultButton(refreshButton);
if (getGridTab().getValue("C_BankStatement_ID") == null) {
ADialog.error(0, dialog, "SaveErrorRowNotFound");
return false;
}
dialog.setTitle(getTitle());
// C_BankStatement.C_BankAccount_ID
int AD_Column_ID = COLUMN_C_BANKSTATEMENT_C_BANKACCOUNT_ID;
MLookup lookup = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
bankAccountField = new VLookup("C_BankAccount_ID", true, true, true, lookup);
// Set Default
int C_BankAccount_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_BankAccount_ID");
bankAccountField.setValue(new Integer(C_BankAccount_ID));
// initial Loading
authorizationField = new VString("authorization", false, false, true, 10, 30, null, null);
authorizationField.addActionListener(this);
MLookup lookupDocument = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_DocType_ID), DisplayType.TableDir);
documentTypeField = new VLookup(MPayment.COLUMNNAME_C_DocType_ID, false, false, true, lookupDocument);
documentTypeField.addActionListener(this);
MLookup lookupTender = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_TenderType), DisplayType.List);
tenderTypeField = new VLookup(MPayment.COLUMNNAME_TenderType, false, false, true, lookupTender);
tenderTypeField.setName("TenderType");
tenderTypeField.addActionListener(this);
MLookup lookupTipoTarjeta = MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MLARTarjetaCredito.Table_Name, "CreditCardType"), DisplayType.List);
tipoTarjetaField = new VLookup("CreditCardType", false, false, true, lookupTipoTarjeta);
tipoTarjetaField.addActionListener(this);
bPartnerLookup = new VLookup("C_BPartner_ID", false, false, true, MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, 3499, DisplayType.Search));
BPartner_idLabel.setLabelFor(bPartnerLookup);
Timestamp date = Env.getContextAsDate(Env.getCtx(), p_WindowNo, MBankStatement.COLUMNNAME_StatementDate);
dateToField.setValue(date);
bankAccount = new MBankAccount(Env.getCtx(), C_BankAccount_ID, null);
loadBankAccount();
return true;
}
use of org.compiere.grid.ed.VString in project adempiere by adempiere.
the class InfoPAttribute method addAttributes.
// dynInit
/**
* Add Attributes
* @return rows
*/
private int addAttributes() {
int row = 0;
PreparedStatement pstmt = null;
ResultSet rs = null;
String whereAttributeSet;
if (p_M_AttributeSet_ID > 0)
whereAttributeSet = "AND M_Attribute_ID IN (SELECT M_Attribute_ID FROM M_AttributeUse WHERE M_AttributeSet_ID=" + p_M_AttributeSet_ID + ")";
else
whereAttributeSet = "";
String sql = MRole.getDefault().addAccessSQL("SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute " + "FROM M_Attribute " + "WHERE IsActive='Y' " + whereAttributeSet + " ORDER BY IsInstanceAttribute, Name", "M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
boolean instanceLine = false;
boolean productLine = false;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next()) {
int attribute_ID = rs.getInt(1);
String name = rs.getString(2);
String description = rs.getString(3);
String attributeValueType = rs.getString(4);
boolean isInstanceAttribute = "Y".equals(rs.getString(5));
// Add label for product attributes if there are any
if (!productLine && !isInstanceAttribute) {
CPanel group = new CPanel();
group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsProductAttribute")));
group.add(Box.createVerticalStrut(VLine.SPACE));
centerPanel.add(group, new ALayoutConstraint(row++, 0));
productLine = true;
}
// Add label for Instances attributes
if (!instanceLine && isInstanceAttribute) {
CPanel group = new CPanel();
group.add(Box.createVerticalStrut(VLine.SPACE));
group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
group.add(Box.createVerticalStrut(VLine.SPACE));
centerPanel.add(group, new ALayoutConstraint(row++, 0));
instanceLine = true;
}
//
CLabel label = new CLabel(name);
if (description != null && description.length() > 0)
label.setToolTipText(description);
centerPanel.add(label, new ALayoutConstraint(row++, 0));
Component field = null;
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType))
field = new VComboBox(getAttributeList(attribute_ID));
else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
field = new VNumber(name, false, false, true, DisplayType.Number, name);
else
field = new VString(name, false, false, true, 10, 40, null, null);
label.setLabelFor(field);
centerPanel.add(field, null);
//
field.setName(String.valueOf(attribute_ID));
if (isInstanceAttribute)
m_instanceEditors.add(field);
else
m_productEditors.add(field);
// To (numbers)
Component fieldTo = null;
if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
fieldTo = new VNumber(name, false, false, true, DisplayType.Number, name);
centerPanel.add(new CLabel("-"), null);
centerPanel.add(fieldTo, null);
}
if (isInstanceAttribute)
m_instanceEditorsTo.add(fieldTo);
else
m_productEditorsTo.add(fieldTo);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// print instance line if not printed
if (!instanceLine) {
boolean isGuarantee = true;
boolean isSerial = true;
boolean isLot = true;
if (p_M_AttributeSet_ID > 0) {
MAttributeSet as = new MAttributeSet(Env.getCtx(), p_M_AttributeSet_ID, null);
isGuarantee = as.isGuaranteeDate();
isSerial = as.isSerNo();
isLot = as.isLot();
}
if (isGuarantee || isSerial || isLot) {
CPanel group = new CPanel();
group.setBorder(new VLine(Msg.translate(Env.getCtx(), "IsInstanceAttribute")));
group.add(Box.createVerticalStrut(VLine.SPACE));
centerPanel.add(group, new ALayoutConstraint(row++, 0));
instanceLine = true;
}
}
return row;
}
Aggregations