use of org.compiere.swing.CLabel in project adempiere by adempiere.
the class VPAttributeDialog method initAttributes.
// jbInit
/**
* Dyanmic Init.
* @return true if initialized
*/
private boolean initAttributes() {
if (m_M_Product_ID == 0 && !m_productWindow)
return false;
MAttributeSet as = null;
if (m_M_Product_ID != 0) {
// Get Model
m_product = MProduct.get(Env.getCtx(), m_M_Product_ID);
if (m_product.getM_AttributeSetInstance_ID() > 0) {
m_productASI = true;
// The product has an instance associated with it.
if (m_M_AttributeSetInstance_ID != m_product.getM_AttributeSetInstance_ID()) {
log.fine("Different ASI than what is specified on Product!");
}
} else {
// Only show product attributes when in the product window.
m_productASI = m_productWindow;
}
m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
if (m_masi == null) {
log.severe("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
return false;
}
Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
// Get Attribute Set
as = m_masi.getMAttributeSet();
} else {
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
m_masi = new MAttributeSetInstance(Env.getCtx(), 0, M_AttributeSet_ID, null);
as = m_masi.getMAttributeSet();
}
// Product has no Attribute Set
if (as == null) {
//ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
//return false;
}
// always read/write. The two are exclusive and can't co-exist.
if (// Set Instance Attributes and dialog controls
!m_productWindow || !m_productASI) {
if (// Instance attributes possible. Set up controls.
!m_productASI) {
// New/Edit - Selection
if (// new
m_M_AttributeSetInstance_ID == 0)
cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "NewRecord"));
else
cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "EditRecord"));
cbNewEdit.addActionListener(this);
centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
bSelect.setText(Msg.getMsg(Env.getCtx(), "SelectExisting"));
bSelect.addActionListener(this);
centerPanel.add(bSelect, null);
}
// Add the Instance Attributes if any. If its a product attribute set
// this will do nothing.
MAttribute[] attributes = as.getMAttributes(true);
log.fine("Instance Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], false, false);
}
if (as != null) {
// Product attributes can be shown in any window but are read/write in the Product window only.
// This will do nothing if it is an instance attribute set.
// False = product attribute instances
MAttribute[] attributes = as.getMAttributes(false);
log.fine("Product Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], true, !m_productWindow);
}
// Lot
if ((!m_productWindow || !m_productASI) && as.isLot()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Lot"));
label.setLabelFor(fieldLotString);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldLotString, null);
fieldLotString.setText(m_masi.getLot());
// M_Lot_ID
// int AD_Column_ID = 9771; // M_AttributeSetInstance.M_Lot_ID
// fieldLot = new VLookup ("M_Lot_ID", false,false, true,
// MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
String sql = "SELECT M_Lot_ID, Name " + "FROM M_Lot l " + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p " + "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID() + " AND p.M_Product_ID=l.M_Product_ID)";
fieldLot = new CComboBox(DB.getKeyNamePairs(sql, true));
label = new CLabel(Msg.translate(Env.getCtx(), "M_Lot_ID"));
label.setLabelFor(fieldLot);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldLot, null);
if (m_masi.getM_Lot_ID() != 0) {
for (int i = 1; i < fieldLot.getItemCount(); i++) {
KeyNamePair pp = (KeyNamePair) fieldLot.getItemAt(i);
if (pp.getKey() == m_masi.getM_Lot_ID()) {
fieldLot.setSelectedIndex(i);
fieldLotString.setEditable(false);
break;
}
}
}
fieldLot.addActionListener(this);
// New Lot Button
if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0 && m_readWrite) {
if (MRole.getDefault().isTableAccess(MLot.Table_ID, false) && MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false) && !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
centerPanel.add(bLot, null);
bLot.addActionListener(this);
}
}
// Popup
// popup
fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));
mZoom = new CMenuItem(Msg.getMsg(Env.getCtx(), "Zoom"), Env.getImageIcon("Zoom16.gif"));
mZoom.addActionListener(this);
popupMenu.add(mZoom);
}
// SerNo
if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "SerNo"));
label.setLabelFor(fieldSerNo);
fieldSerNo.setText(m_masi.getSerNo());
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldSerNo, null);
// New SerNo Button
if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0 && m_readWrite) {
if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
centerPanel.add(bSerNo, null);
bSerNo.addActionListener(this);
}
}
}
// GuaranteeDate
if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "GuaranteeDate"));
label.setLabelFor(fieldGuaranteeDate);
if (m_M_AttributeSetInstance_ID == 0)
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
else
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldGuaranteeDate, null);
}
if (m_row == 0) {
ADialog.error(m_WindowNo, this, "PAttributeNoInfo");
//return false;
}
// New/Edit Window
if ((!m_productWindow || !m_productASI) && m_AD_Column_ID != 0 && m_readWrite) {
cbNewEdit.setSelected(m_M_AttributeSetInstance_ID == 0);
cmd_newEdit();
}
// Attribute Set Instance Description
CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Description"));
label.setLabelFor(fieldDescription);
fieldDescription.setText(m_masi.getDescription());
fieldDescription.setEditable(false);
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
centerPanel.add(fieldDescription, null);
// Window usually to wide (??)
Dimension dd = centerPanel.getPreferredSize();
dd.width = Math.min(500, dd.width);
centerPanel.setPreferredSize(dd);
return true;
}
use of org.compiere.swing.CLabel in project adempiere by adempiere.
the class VPAttributeDialog method addAttributeLine.
// initAttribute
/**
* Add Attribute Line
* @param attribute attribute
* @param product product level attribute
* @param readOnly value is read only
*/
private void addAttributeLine(MAttribute attribute, boolean product, boolean readOnly) {
log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
CLabel label = new CLabel(attribute.getName());
if (product)
label.setFont(new Font(label.getFont().getFontName(), Font.BOLD, label.getFont().getSize()));
if (attribute.getDescription() != null)
label.setToolTipText(attribute.getDescription());
centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
//
MAttributeInstance instance = attribute.getMAttributeInstance(m_M_AttributeSetInstance_ID);
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType())) {
// optional = null
MAttributeValue[] values = attribute.getMAttributeValues();
CComboBox editor = new CComboBox(values);
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");
label.setLabelFor(editor);
centerPanel.add(editor, null);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
} else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType())) {
VNumber editor = new VNumber(attribute.getName(), attribute.isMandatory(), readOnly, !readOnly, DisplayType.Number, attribute.getName());
if (instance != null)
editor.setValue(instance.getValueNumber());
else
editor.setValue(Env.ZERO);
label.setLabelFor(editor);
centerPanel.add(editor, null);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
} else // Text Field
{
VString editor = new VString(attribute.getName(), attribute.isMandatory(), false, true, 20, INSTANCE_VALUE_LENGTH, null, null);
if (instance != null)
editor.setText(instance.getValue());
label.setLabelFor(editor);
centerPanel.add(editor, null);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add(editor);
}
}
use of org.compiere.swing.CLabel in project adempiere by adempiere.
the class VEditorFactory method getLabel.
// getEditor
/**
* Create Label for MField. (null for YesNo/Button)
* The Name is set to the column name for dynamic display management
*
* @param mField MField
* @return Label
*/
public static CLabel getLabel(GridField mField) {
if (mField == null)
return null;
int displayType = mField.getDisplayType();
// No Label for FieldOnly, CheckBox, Button
if (mField.isFieldOnly() || displayType == DisplayType.YesNo || displayType == DisplayType.Button || displayType == DisplayType.Chart)
return null;
//
CLabel label = new CLabel(mField.getHeader(), mField.getDescription());
label.setName(mField.getColumnName());
// label.setForeground(AdempierePLAF.getTextColor_Label());
return label;
}
use of org.compiere.swing.CLabel in project adempiere by adempiere.
the class VBPartner method createLine.
// initBPartner
/**
* Create Line
* @param field field
* @param title label value
* @param addSpace add more space
* @return label
*/
private CLabel createLine(JComponent field, String title, boolean addSpace) {
if (addSpace) {
m_gbc.gridy = m_line++;
m_gbc.gridx = 1;
m_gbc.insets = m_fieldInsets;
centerPanel.add(Box.createHorizontalStrut(6), m_gbc);
}
// Line
m_gbc.gridy = m_line++;
// Label
m_gbc.gridx = 0;
m_gbc.insets = m_labelInsets;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
CLabel label = new CLabel(Msg.translate(Env.getCtx(), title));
centerPanel.add(label, m_gbc);
// Field
m_gbc.gridx = 1;
m_gbc.insets = m_fieldInsets;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
centerPanel.add(field, m_gbc);
if (m_readOnly)
field.setEnabled(false);
return label;
}
use of org.compiere.swing.CLabel in project adempiere by adempiere.
the class Find method addSelectionColumn.
// initFind
/**
* Add Selection Column to first Tab
* @param mField field
*/
private void addSelectionColumn(GridField mField) {
log.config(mField.getHeader());
int displayLength = mField.getDisplayLength();
if (displayLength > FIELDLENGTH)
mField.setDisplayLength(FIELDLENGTH);
else
displayLength = 0;
// Editor
VEditor editor = null;
//#221
VEditor editor2 = null;
CLabel label = null;
if (mField.isLookup()) {
VLookup vl = new VLookup(mField.getColumnName(), false, false, true, mField.getLookup());
//setting mField to avoid NPE
vl.setField(mField);
vl.setName(mField.getColumnName());
editor = vl;
//
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
//
label = VEditorFactory.getLabel(mField);
//m_sLine++;
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) editor, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
} else {
if (mField.isRangeLookup()) {
new Box(BoxLayout.X_AXIS);
Box box = Box.createHorizontalBox();
editor = VEditorFactory.getEditor(mField, false);
label = VEditorFactory.getLabel(mField);
editor.setMandatory(false);
editor.setReadWrite(true);
box.add((Component) editor);
//#221
editor2 = VEditorFactory.getEditor(mField, false);
editor2.setMandatory(false);
editor2.setReadWrite(true);
if (editor2 instanceof CTextField) {
((CTextField) editor2).addActionListener(this);
}
CLabel separator = new CLabel(" - ");
box.add(separator);
box.add((Component) editor2);
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) box, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
} else {
editor = VEditorFactory.getEditor(mField, false);
editor.setMandatory(false);
editor.setReadWrite(true);
label = VEditorFactory.getLabel(mField);
//
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
//
label = VEditorFactory.getLabel(mField);
//m_sLine++;
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) editor, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
}
}
// Add action listener to custom text fields - teo_sarca [ 1709292 ]
if (editor instanceof CTextField) {
((CTextField) editor).addActionListener(this);
}
m_sEditors.add(editor);
// #221
m_sEditors2.add(editor2);
}
Aggregations