use of org.adempiere.webui.component.NumberBox in project adempiere by adempiere.
the class WPAttributeDialog method saveSelection.
// cmd_zoom
/**
* Save Selection
* @return true if saved
*/
private boolean saveSelection() {
log.info("");
MAttributeSet as = m_masi.getMAttributeSet();
if (as == null)
return true;
//
m_changed = false;
String mandatory = "";
if (!m_productWindow && as.isLot()) {
log.fine("Lot=" + fieldLotString.getText());
String text = fieldLotString.getText();
m_masi.setLot(text);
if (as.isLotMandatory() && (text == null || text.length() == 0))
mandatory += " - " + Msg.translate(Env.getCtx(), "Lot");
m_changed = true;
}
// Lot
if (!m_productWindow && as.isSerNo()) {
log.fine("SerNo=" + fieldSerNo.getText());
String text = fieldSerNo.getText();
m_masi.setSerNo(text);
if (as.isSerNoMandatory() && (text == null || text.length() == 0))
mandatory += " - " + Msg.translate(Env.getCtx(), "SerNo");
m_changed = true;
}
// SerNo
if (!m_productWindow && as.isGuaranteeDate()) {
log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
Date gDate = fieldGuaranteeDate.getValue();
Timestamp ts = gDate != null ? new Timestamp(gDate.getTime()) : null;
m_masi.setGuaranteeDate(ts);
if (as.isGuaranteeDateMandatory() && ts == null)
mandatory += " - " + Msg.translate(Env.getCtx(), "GuaranteeDate");
m_changed = true;
}
// New Instance
if (m_changed || m_masi.getM_AttributeSetInstance_ID() == 0) {
m_masi.save();
m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
m_M_AttributeSetInstanceName = m_masi.getDescription();
}
// Save attributes
if (m_M_AttributeSetInstance_ID > 0) {
// Save Instance Attributes
MAttribute[] attributes = as.getMAttributes(!m_productASI);
for (int i = 0; i < attributes.length; i++) {
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributes[i].getAttributeValueType())) {
Listbox editor = (Listbox) m_editors.get(i);
ListItem item = editor.getSelectedItem();
MAttributeValue value = item != null ? (MAttributeValue) item.getValue() : null;
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && value == null)
mandatory += " - " + attributes[i].getName();
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
} else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
NumberBox editor = (NumberBox) m_editors.get(i);
BigDecimal value = editor.getValue();
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && value == null)
mandatory += " - " + attributes[i].getName();
//setMAttributeInstance doesn't work without decimal point
if (value != null && value.scale() == 0)
value = value.setScale(1, BigDecimal.ROUND_HALF_UP);
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
} else {
Textbox editor = (Textbox) m_editors.get(i);
String value = editor.getText();
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && (value == null || value.length() == 0))
mandatory += " - " + attributes[i].getName();
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
}
}
m_changed = true;
}
// Save Model
if (m_changed) {
m_masi.setDescription();
m_masi.save();
}
m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID();
m_M_AttributeSetInstanceName = m_masi.getDescription();
//
if (mandatory.length() > 0) {
FDialog.error(m_WindowNo, this, "FillMandatory", mandatory);
return false;
}
return true;
}
use of org.adempiere.webui.component.NumberBox in project adempiere by adempiere.
the class WPAttributeDialog method addAttributeLine.
// initAttribute
/**
* Add Attribute Line
* @param attribute attribute
* @param product product level attribute
* @param readOnly value is read only
*/
private void addAttributeLine(Rows rows, MAttribute attribute, boolean product, boolean readOnly) {
log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
m_row++;
Label label = new Label(attribute.getName());
if (product)
label.setStyle("font-weight: bold");
if (attribute.getDescription() != null)
label.setTooltiptext(attribute.getDescription());
Row row = rows.newRow();
row.appendChild(label.rightAlign());
//
MAttributeInstance instance = attribute.getMAttributeInstance(m_M_AttributeSetInstance_ID);
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
// optional = null
MAttributeValue[] values = attribute.getMAttributeValues();
Listbox editor = new Listbox();
editor.setMold("select");
for (MAttributeValue value : values) {
ListItem item = new ListItem(value != null ? value.getName() : "", value);
editor.appendChild(item);
}
boolean found = false;
if (instance != null) {
for (int i = 0; i < values.length; i++) {
if (values[i] != null && values[i].getM_AttributeValue_ID() == instance.getM_AttributeValue_ID()) {
editor.setSelectedIndex(i);
found = true;
break;
}
}
if (found)
log.fine("Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
else
log.warning("Attribute=" + attribute.getName() + " #" + values.length + " - NOT found: " + instance);
} else
// setComboBox
log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
row.appendChild(editor);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
} else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
NumberBox editor = new NumberBox(false);
if (instance != null)
editor.setValue(instance.getValueNumber());
else
editor.setValue(Env.ZERO);
row.appendChild(editor);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
} else // Text Field
{
Textbox editor = new Textbox();
if (instance != null)
editor.setText(instance.getValue());
row.appendChild(editor);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
}
}
use of org.adempiere.webui.component.NumberBox in project adempiere by adempiere.
the class InfoPaymentPanel method statInit.
// InfoPaymentPanel
/**
* Static Setup - add fields to parameterPanel
*/
private void statInit() {
fDocumentNo = new Textbox();
fDocumentNo.setWidth("100%");
fDocumentNo.addEventListener(Events.ON_CHANGE, this);
fDocumentNo.setAttribute("zk_component_ID", "Lookup_Criteria_fDocumentNo");
fDocumentNo.addEventListener(Events.ON_CHANGE, this);
// Format the dates and number boxes
fDateFrom = new Datebox();
fDateFrom.setWidth("97px");
fDateFrom.setAttribute("zk_component_ID", "Lookup_Criteria_DateFrom");
fDateFrom.addEventListener(Events.ON_CHANGE, this);
//
fDateTo = new Datebox();
fDateTo.setWidth("97px");
fDateTo.setAttribute("zk_component_ID", "Lookup_Criteria_DateTo");
fDateTo.addEventListener(Events.ON_CHANGE, this);
//
SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date, AEnv.getLanguage(Env.getCtx()));
fDateFrom.setFormat(dateFormat.toPattern());
fDateTo.setFormat(dateFormat.toPattern());
//
fAmtFrom = new NumberBox(false);
fAmtFrom.getDecimalbox().setWidth("90px");
fAmtFrom.setAttribute("zk_component_ID", "Lookup_Criteria_AmtFrom");
fAmtFrom.addEventListener(Events.ON_CHANGE, this);
//
fAmtTo = new NumberBox(false);
fAmtTo.getDecimalbox().setWidth("90px");
fAmtTo.setAttribute("zk_component_ID", "Lookup_Criteria_AmtTo");
fAmtTo.addEventListener(Events.ON_CHANGE, this);
//
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx()));
fAmtFrom.getDecimalbox().setFormat(format.toPattern());
fAmtFrom.getDecimalbox().setStyle("text-align:right; " + fAmtFrom.getDecimalbox().getStyle());
fAmtTo.getDecimalbox().setFormat(format.toPattern());
fAmtTo.getDecimalbox().setStyle("text-align:right; " + fAmtTo.getDecimalbox().getStyle());
//
fCheckReceipt.setLabel(Msg.translate(Env.getCtx(), "OnlyReceipt"));
fCheckReceipt.setName("OnlyReceipt");
fCheckReceipt.addEventListener(Events.ON_CHECK, this);
fCheckReceipt.setAttribute("zk_component_ID", "Lookup_Criteria_CheckReceipt");
//
fCheckPayment.setLabel(Msg.translate(Env.getCtx(), "OnlyPayment"));
fCheckPayment.setName("OnlyPayment");
fCheckPayment.addEventListener(Events.ON_CHECK, this);
fCheckPayment.setAttribute("zk_component_ID", "Lookup_Criteria_CheckPayment");
//
fBPartner_ID = new WSearchEditor(MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_BPartner_ID), DisplayType.Search), Msg.translate(Env.getCtx(), "C_BPartner_ID"), "", false, false, true);
fBPartner_ID.getComponent().setAttribute("zk_component_ID", "Lookup_Criteria_C_BPartner_ID");
fBPartner_ID.addValueChangeListener(this);
fBankAccount_ID = new WSearchEditor(MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MPayment.Table_Name, MPayment.COLUMNNAME_C_BankAccount_ID), DisplayType.Search), Msg.translate(Env.getCtx(), "C_BankAccount_ID"), "", false, false, true);
fBankAccount_ID.getComponent().setAttribute("zk_component_ID", "Lookup_Criteria_C_BankAccount_ID");
fBankAccount_ID.addValueChangeListener(this);
Rows rows = new Rows();
Row row = new Row();
rows.appendChild(row);
row.appendChild(lDocumentNo.rightAlign());
row.appendChild(fDocumentNo);
row.appendChild(fBPartner_ID.getLabel().rightAlign());
row.appendChild(fBPartner_ID.getComponent());
row.appendChild(fCheckReceipt);
row = new Row();
rows.appendChild(row);
row.appendChild(fBankAccount_ID.getLabel().rightAlign());
row.appendChild(fBankAccount_ID.getComponent());
row.appendChild(lDateFrom.rightAlign());
Hbox hbox = new Hbox();
hbox.appendChild(fDateFrom);
hbox.appendChild(lDateTo);
hbox.appendChild(fDateTo);
row.appendChild(hbox);
row.appendChild(fCheckPayment);
row = new Row();
rows.appendChild(row);
row.appendCellChild(lAmtFrom.rightAlign(), 3);
hbox = new Hbox();
hbox.appendChild(fAmtFrom);
hbox.appendChild(lAmtTo);
hbox.appendChild(fAmtTo);
row.appendCellChild(hbox, 1);
p_criteriaGrid.appendChild(rows);
super.setSizes();
}
use of org.adempiere.webui.component.NumberBox in project adempiere by adempiere.
the class InfoPAttributePanel method addAttributes.
// dynInit
/**
* Add Attributes
* @return rows
*/
private int addAttributes() {
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) {
Row row = new Row();
rows.appendChild(row);
row.setSpans("2");
Label group = new Label(Msg.translate(Env.getCtx(), "IsProductAttribute"));
row.appendChild(group);
rows.appendChild(row);
row = new Row();
rows.appendChild(row);
row.setSpans("2");
Separator separator = new Separator();
separator.setBar(true);
row.appendChild(separator);
rows.appendChild(row);
productLine = true;
}
// Add label for Instances attributes
if (!instanceLine && isInstanceAttribute) {
Row row = new Row();
rows.appendChild(row);
row.setSpans("2");
Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
row.appendChild(group);
rows.appendChild(row);
row = new Row();
rows.appendChild(row);
row.setSpans("2");
Separator separator = new Separator();
separator.setBar(true);
row.appendChild(separator);
rows.appendChild(row);
instanceLine = true;
}
//
Row row = new Row();
rows.appendChild(row);
Label label = new Label(name);
if (description != null && description.length() > 0)
label.setTooltiptext(description);
Div div = new Div();
div.setAlign("right");
div.appendChild(label);
row.appendChild(div);
Component field = null;
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
field = new Listbox();
((Listbox) field).setRows(0);
((Listbox) field).setMultiple(false);
((Listbox) field).setMold("select");
((Listbox) field).setWidth("150px");
KeyNamePair[] knp = getAttributeList(attribute_ID);
for (int i = 0; i < knp.length; i++) ((Listbox) field).appendItem(knp[i].getName(), knp[i]);
} else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
field = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
((NumberBox) field).setWidth("150px");
} else {
field = new WStringEditor(name, false, false, true, 10, 40, null, null).getComponent();
((Textbox) field).setWidth("150px");
}
row.appendChild(field);
//
field.setId(String.valueOf(attribute_ID));
// If name is null, replace it with "_"
if (name.equals("")) {
name = "_";
}
field.setAttribute("zk_component_ID", "InfoPAttributePanel_field_" + name.replaceAll("[^a-zA-Z0-9_]", "_"));
//
if (isInstanceAttribute)
m_instanceEditors.add(field);
else
m_productEditors.add(field);
// To (numbers)
Component fieldTo = null;
if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
fieldTo = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
((NumberBox) fieldTo).setWidth("150px");
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(new Label("-"));
row.appendChild(div);
row.appendChild(fieldTo);
}
if (fieldTo != null)
fieldTo.setAttribute("zk_component_ID", "InfoPAttributePanel_fieldTo_" + name);
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) {
Row row = new Row();
rows.appendChild(row);
row.setSpans("2");
Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
row.appendChild(group);
rows.appendChild(row);
row = new Row();
rows.appendChild(row);
row.setSpans("2");
Separator separator = new Separator();
separator.setBar(true);
row.appendChild(separator);
rows.appendChild(row);
instanceLine = true;
}
}
return 0;
}
use of org.adempiere.webui.component.NumberBox in project adempiere by adempiere.
the class InfoInvoicePanel method initComponents.
private void initComponents() {
lblDocumentNo = new Label(Util.cleanAmp(Msg.translate(Env.getCtx(), "DocumentNo")));
lblDescription = new Label(Msg.translate(Env.getCtx(), "Description"));
lblDateInvoiced = new Label(Msg.translate(Env.getCtx(), "DateInvoiced"));
lblGrandTotal = new Label(Msg.translate(Env.getCtx(), "GrandTotal"));
//
fDocumentNo = new Textbox();
fDocumentNo.addEventListener(Events.ON_CHANGE, this);
fDocumentNo.setAttribute("zk_component_ID", "Lookup_Criteria_DocumentNo");
fDescription = new Textbox();
fDescription.addEventListener(Events.ON_CHANGE, this);
fDescription.setAttribute("zk_component_ID", "Lookup_Criteria_Description");
// Format the dates and number boxes
fDateFrom = new Datebox();
fDateTo = new Datebox();
fDateFrom.setWidth("97px");
fDateTo.setWidth("97px");
//
fDateFrom.setAttribute("zk_component_ID", "Lookup_Criteria_DateFrom");
fDateFrom.addEventListener(Events.ON_CHANGE, this);
fDateTo.setAttribute("zk_component_ID", "Lookup_Criteria_DateTo");
fDateTo.addEventListener(Events.ON_CHANGE, this);
//
SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.Date, AEnv.getLanguage(Env.getCtx()));
fDateFrom.setFormat(dateFormat.toPattern());
fDateTo.setFormat(dateFormat.toPattern());
//
DecimalFormat format = DisplayType.getNumberFormat(DisplayType.Amount, AEnv.getLanguage(Env.getCtx()));
fAmtFrom = new NumberBox(false);
fAmtFrom.getDecimalbox().setWidth("90px");
fAmtFrom.getDecimalbox().setFormat(format.toPattern());
fAmtFrom.getDecimalbox().setStyle("text-align:right; " + fAmtFrom.getDecimalbox().getStyle());
fAmtFrom.setAttribute("zk_component_ID", "Lookup_Criteria_AmtFrom");
fAmtFrom.addEventListener(Events.ON_CHANGE, this);
fAmtTo = new NumberBox(false);
fAmtTo.getDecimalbox().setWidth("90px");
fAmtTo.getDecimalbox().setFormat(format.toPattern());
fAmtTo.getDecimalbox().setStyle("text-align:right; " + fAmtTo.getDecimalbox().getStyle());
fAmtTo.setAttribute("zk_component_ID", "Lookup_Criteria_AmtTo");
fAmtTo.addEventListener(Events.ON_CHANGE, this);
//
fIsPaid = new Checkbox();
fIsPaid.setLabel(Msg.translate(Env.getCtx(), "IsPaid"));
fIsPaid.setAttribute("zk_component_ID", "Lookup_Criteria_IsPaid");
fIsPaid.addActionListener(this);
//
fIsSOTrx = new Checkbox();
fIsSOTrx.setLabel(Msg.translate(Env.getCtx(), "IsSOTrx"));
fIsSOTrx.setAttribute("zk_component_ID", "Lookup_Criteria_IsSoTrx");
fIsSOTrx.addActionListener(this);
//
fBPartner_ID = new WSearchEditor(MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MInvoice.Table_Name, MInvoice.COLUMNNAME_C_BPartner_ID), DisplayType.Search), Msg.translate(Env.getCtx(), "C_BPartner_ID"), "", false, false, true);
fBPartner_ID.getComponent().setAttribute("zk_component_ID", "Lookup_Criteria_C_BPartner_ID");
fBPartner_ID.addValueChangeListener(this);
//
fOrder_ID = new WSearchEditor(MLookupFactory.get(Env.getCtx(), p_WindowNo, 0, MColumn.getColumn_ID(MInvoice.Table_Name, MInvoice.COLUMNNAME_C_Order_ID), DisplayType.Search), Msg.translate(Env.getCtx(), "C_Order_ID"), "", false, false, true);
fOrder_ID.getComponent().setAttribute("zk_component_ID", "Lookup_Criteria_C_Order_ID");
fOrder_ID.addValueChangeListener(this);
}
Aggregations