use of org.compiere.apps.search.InfoPAttribute in project adempiere by adempiere.
the class VPAttribute method actionPerformed.
// addActionListener
/**
* Action Listener - start dialog
* @param e Event
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(RecordInfo.CHANGE_LOG_COMMAND)) {
RecordInfo.start(m_GridField);
return;
}
if (!m_button.isEnabled())
return;
m_button.setEnabled(false);
//
Integer oldValue = 0;
try {
oldValue = (Integer) getValue();
} catch (ClassCastException cce) {
// Possible Invalid Cast exception if getValue() return new instance of Object.
}
int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
int M_AttributeSetInstance_ID = oldValueInt;
int M_Product_ID = 0;
int M_ProductBOM_ID = 0;
if (m_GridTab != null) {
M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_Product_ID");
M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, m_GridTab.getTabNo(), "M_ProductBOM_ID");
} else {
M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");
}
int M_Locator_ID = -1;
log.config("M_Product_ID=" + M_Product_ID + "/" + M_ProductBOM_ID + ",M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", AD_Column_ID=" + m_AD_Column_ID);
// M_Product.M_AttributeSetInstance_ID = 8418
// HARDCODED
boolean productWindow = m_AD_Column_ID == 8418;
// Exclude ability to enter ASI
boolean exclude = false;
if (M_Product_ID != 0) {
MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
int M_AttributeSet_ID = product.getM_AttributeSet_ID();
if (M_AttributeSet_ID != 0) {
MAttributeSet mas = MAttributeSet.get(Env.getCtx(), M_AttributeSet_ID);
exclude = mas.excludeEntry(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNo));
}
}
boolean changed = false;
if (// Use BOM Component
M_ProductBOM_ID != 0)
M_Product_ID = M_ProductBOM_ID;
// If the VPAttribute component is in a dialog, use the search
if (m_searchOnly) {
// The component is an element in a CPanel, which is part of a JPanel
// which is in a JLayeredPane which is in ... the InfoProduct window
Container me = ((Container) this).getParent();
while (me != null) {
if (me instanceof InfoProduct)
break;
me = me.getParent();
}
InfoPAttribute ia = new InfoPAttribute((CDialog) me);
m_pAttributeWhere = ia.getWhereClause();
String oldText = m_text.getText();
m_text.setText(ia.getDisplay());
// The text can be long. Use the tooltip to help display the info.
m_text.setToolTipText(m_text.getText());
ActionEvent ae = new ActionEvent(m_text, 1001, "updated");
// TODO not the generally correct way to fire an event
((InfoProduct) me).actionPerformed(ae);
} else if (!productWindow && (M_Product_ID == 0 || exclude)) {
changed = true;
m_text.setText(null);
M_AttributeSetInstance_ID = 0;
} else {
VPAttributeDialog vad = new VPAttributeDialog(Env.getFrame(this), M_AttributeSetInstance_ID, M_Product_ID, m_C_BPartner_ID, productWindow, m_AD_Column_ID, m_WindowNo, isReadWrite());
if (vad.isChanged()) {
m_text.setText(vad.getM_AttributeSetInstanceName());
// The text can be long. Use the tooltip to help display the info.
m_text.setToolTipText(vad.getM_AttributeSetInstanceName());
M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
if (!productWindow && vad.getM_Locator_ID() > 0) {
M_Locator_ID = vad.getM_Locator_ID();
}
changed = true;
}
}
// Set Value
if (changed) {
log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
// force re-query display
m_value = new Object();
if (M_AttributeSetInstance_ID == 0)
setValue(null);
else
setValue(new Integer(M_AttributeSetInstance_ID));
// Change Locator
if (m_GridTab != null && M_Locator_ID > 0) {
log.finest("Change M_Locator_ID=" + M_Locator_ID);
m_GridTab.setValue("M_Locator_ID", M_Locator_ID);
}
//
try {
String columnName = "M_AttributeSetInstance_ID";
if (m_GridField != null) {
columnName = m_GridField.getColumnName();
}
fireVetoableChange(columnName, new Object(), getValue());
} catch (PropertyVetoException pve) {
log.log(Level.SEVERE, "", pve);
}
if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && m_GridField != null) {
// force Change - user does not realize that embedded object is already saved.
m_GridTab.processFieldChange(m_GridField);
}
}
// change
m_button.setEnabled(true);
requestFocus();
}
Aggregations