IDEMPIERE-5690 Make WPAttributeEditor and WPAttributeDialog more extensible (#1801)

This commit is contained in:
hengsin 2023-04-28 18:25:13 +08:00 committed by GitHub
parent f18bb88f4b
commit 6f7e0001a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 94 deletions

View File

@ -48,15 +48,13 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
private static final CLogger log = CLogger.getCLogger(WPAttributeEditor.class); private static final CLogger log = CLogger.getCLogger(WPAttributeEditor.class);
private int m_WindowNo; protected int m_WindowNo;
private Lookup m_mPAttribute; protected Lookup m_mPAttribute;
private int m_C_BPartner_ID; protected int m_C_BPartner_ID;
private Object m_value; protected Object m_value;
private GridTab m_GridTab;
/** No Instance Key */ /** No Instance Key */
private static Integer NO_INSTANCE = Integer.valueOf(0); private static Integer NO_INSTANCE = Integer.valueOf(0);
@ -81,7 +79,7 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
public WPAttributeEditor(GridTab gridTab, GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) public WPAttributeEditor(GridTab gridTab, GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration)
{ {
super(new PAttributebox(), gridField, tableEditor, editorConfiguration); super(new PAttributebox(), gridField, tableEditor, editorConfiguration);
m_GridTab = gridTab; setGridTab(gridTab);
initComponents(); initComponents();
} }
@ -181,12 +179,12 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
int M_AttributeSetInstance_ID = oldValueInt; int M_AttributeSetInstance_ID = oldValueInt;
int M_Product_ID = 0; int M_Product_ID = 0;
int M_ProductBOM_ID = 0; int M_ProductBOM_ID = 0;
if (m_GridTab != null) { if (gridTab != null) {
M_Product_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, m_GridTab.getTabNo(), "M_Product_ID"); M_Product_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, gridTab.getTabNo(), "M_Product_ID");
M_ProductBOM_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, m_GridTab.getTabNo(), "M_ProductBOM_ID"); M_ProductBOM_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, gridTab.getTabNo(), "M_ProductBOM_ID");
//For third level tab (e.g, LineMA), should take M_Product_ID from Line instead of from Header //For third level tab (e.g, LineMA), should take M_Product_ID from Line instead of from Header
if (m_GridTab.getTabLevel() > 1 && m_GridTab.getParentTab() != null && m_GridTab.getField("M_Product_ID")==null) { if (gridTab.getTabLevel() > 1 && gridTab.getParentTab() != null && gridTab.getField("M_Product_ID")==null) {
int tmp = Env.getContextAsInt (Env.getCtx (), m_WindowNo, m_GridTab.getParentTab().getTabNo(), "M_Product_ID"); int tmp = Env.getContextAsInt (Env.getCtx (), m_WindowNo, gridTab.getParentTab().getTabNo(), "M_Product_ID");
if (tmp > 0) if (tmp > 0)
M_Product_ID = tmp; M_Product_ID = tmp;
} }
@ -227,12 +225,12 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
{ {
getComponent().setText(vad.getM_AttributeSetInstanceName()); getComponent().setText(vad.getM_AttributeSetInstanceName());
M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID(); M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
if (m_GridTab != null && !productWindow && vad.getM_Locator_ID() > 0) if (gridTab != null && !productWindow && vad.getM_Locator_ID() > 0)
{ {
if (gridField.getColumnName().equals("M_AttributeSetInstanceTo_ID")) if (gridField.getColumnName().equals("M_AttributeSetInstanceTo_ID"))
m_GridTab.setValue("M_LocatorTo_ID", vad.getM_Locator_ID()); gridTab.setValue("M_LocatorTo_ID", vad.getM_Locator_ID());
else else
m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID()); gridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
} }
changed = true; changed = true;
@ -247,44 +245,7 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
}); });
} }
/** Selection } // cmd_dialog
{
// Get Model
MAttributeSetInstance masi = MAttributeSetInstance.get(Env.getCtx(), M_AttributeSetInstance_ID, M_Product_ID);
if (masi == null)
{
log.log(Level.SEVERE, "No Model for M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", M_Product_ID=" + M_Product_ID);
}
else
{
Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", masi.getM_AttributeSet_ID());
// Get Attribute Set
MAttributeSet as = masi.getMAttributeSet();
// Product has no Attribute Set
if (as == null)
ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
// Product has no Instance Attributes
else if (!as.isInstanceAttribute())
ADialog.error(m_WindowNo, this, "PAttributeNoInstanceAttribute");
else
{
int M_Warehouse_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Warehouse_ID");
int M_Locator_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Locator_ID");
String title = "";
PAttributeInstance pai = new PAttributeInstance (
Env.getFrame(this), title,
M_Warehouse_ID, M_Locator_ID, M_Product_ID, m_C_BPartner_ID);
if (pai.getM_AttributeSetInstance_ID() != -1)
{
m_text.setText(pai.getM_AttributeSetInstanceName());
M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
changed = true;
}
}
}
}
**/
} // cmd_file
private void processChanges(int oldValueInt, int M_AttributeSetInstance_ID) { private void processChanges(int oldValueInt, int M_AttributeSetInstance_ID) {
if (log.isLoggable(Level.FINEST)) log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID); if (log.isLoggable(Level.FINEST)) log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
@ -296,10 +257,10 @@ public class WPAttributeEditor extends WEditor implements ContextMenuListener
ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue()); ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue());
fireValueChange(vce); fireValueChange(vce);
if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null) if (M_AttributeSetInstance_ID == oldValueInt && gridTab != null && gridField != null)
{ {
// force Change - user does not realize that embedded object is already saved. // force Change - user does not realize that embedded object is already saved.
m_GridTab.processFieldChange(gridField); gridTab.processFieldChange(gridField);
} }
} }

View File

@ -164,53 +164,53 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
AEnv.showCenterScreen(this); AEnv.showCenterScreen(this);
} // VPAttributeDialog } // VPAttributeDialog
private int m_WindowNo; protected int m_WindowNo;
private MAttributeSetInstance m_masi; protected MAttributeSetInstance m_masi;
private int m_M_AttributeSetInstance_ID; protected int m_M_AttributeSetInstance_ID;
private int m_M_Locator_ID; protected int m_M_Locator_ID;
private String m_M_AttributeSetInstanceName; protected String m_M_AttributeSetInstanceName;
private int m_M_Product_ID; protected int m_M_Product_ID;
private int m_C_BPartner_ID; protected int m_C_BPartner_ID;
private int m_AD_Column_ID; protected int m_AD_Column_ID;
private int m_WindowNoParent; protected int m_WindowNoParent;
/** Enter Product Attributes */ /** Enter Product Attributes */
private boolean m_productWindow = false; protected boolean m_productWindow = false;
/** Change */ /** Change */
private boolean m_changed = false; protected boolean m_changed = false;
private static final CLogger log = CLogger.getCLogger(WPAttributeDialog.class); private static final CLogger log = CLogger.getCLogger(WPAttributeDialog.class);
/** Row Counter */ /** Row Counter */
private int m_row = 0; private int m_row = 0;
/** List of Editors */ /** List of Editors */
private ArrayList<WEditor> m_editors = new ArrayList<WEditor>(); protected ArrayList<WEditor> m_editors = new ArrayList<WEditor>();
private Checkbox cbNewEdit = new Checkbox(); protected Checkbox cbNewEdit = new Checkbox();
private Button bNewRecord = new Button(Msg.getMsg(Env.getCtx(), "NewRecord")); protected Button bNewRecord = new Button(Msg.getMsg(Env.getCtx(), "NewRecord"));
private Listbox existingCombo = new Listbox(); protected Listbox existingCombo = new Listbox();
private Button bSelect = new Button(); protected Button bSelect = new Button();
// Lot // Lot
private Textbox fieldLotString = new Textbox(); protected Textbox fieldLotString = new Textbox();
private Listbox fieldLot = new Listbox(); protected Listbox fieldLot = new Listbox();
private Button bLot = new Button(Msg.getMsg (Env.getCtx(), "New")); protected Button bLot = new Button(Msg.getMsg (Env.getCtx(), "New"));
// Lot Popup // Lot Popup
Menupopup popupMenu = new Menupopup(); protected Menupopup popupMenu = new Menupopup();
private Menuitem mZoom; protected Menuitem mZoom;
// Ser No // Ser No
private Textbox fieldSerNo = new Textbox(); protected Textbox fieldSerNo = new Textbox();
private Button bSerNo = new Button(Msg.getMsg (Env.getCtx(), "New")); protected Button bSerNo = new Button(Msg.getMsg (Env.getCtx(), "New"));
// Date // Date
private Datebox fieldGuaranteeDate = new Datebox(); protected Datebox fieldGuaranteeDate = new Datebox();
// //
private Textbox fieldDescription = new Textbox(); //TODO: set length to 20 protected Textbox fieldDescription = new Textbox(); //TODO: set length to 20
// //
private Borderlayout mainLayout = new Borderlayout(); protected Borderlayout mainLayout = new Borderlayout();
private Panel centerPanel = new Panel(); protected Panel centerPanel = new Panel();
private Grid centerLayout = new Grid(); protected Grid centerLayout = new Grid();
private Panel northPanel = new Panel(); protected Panel northPanel = new Panel();
private Grid northLayout = new Grid(); protected Grid northLayout = new Grid();
private ConfirmPanel confirmPanel = new ConfirmPanel (true); protected ConfirmPanel confirmPanel = new ConfirmPanel (true);
private String m_columnName = null; protected String m_columnName = null;
/** /**
* Layout * Layout
@ -838,14 +838,14 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
log.log(Level.SEVERE, "not found - " + e); log.log(Level.SEVERE, "not found - " + e);
} // actionPerformed } // actionPerformed
private void onCancel() { protected void onCancel() {
m_changed = false; m_changed = false;
m_M_AttributeSetInstance_ID = 0; m_M_AttributeSetInstance_ID = 0;
m_M_Locator_ID = 0; m_M_Locator_ID = 0;
dispose(); dispose();
} }
private void cmd_existingCombo() { protected void cmd_existingCombo() {
ListItem pp = existingCombo.getSelectedItem(); ListItem pp = existingCombo.getSelectedItem();
if (pp != null && (Integer)pp.getValue() != -1) if (pp != null && (Integer)pp.getValue() != -1)
{ {
@ -865,7 +865,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
} }
} }
private void cmd_newRecord() { protected void cmd_newRecord() {
cbNewEdit.setSelected(false); cbNewEdit.setSelected(false);
cbNewEdit.setEnabled(false); cbNewEdit.setEnabled(false);
bNewRecord.setEnabled(false); bNewRecord.setEnabled(false);
@ -883,7 +883,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
fieldDescription.setText(""); fieldDescription.setText("");
} }
private void cmd_edit() { protected void cmd_edit() {
boolean check = cbNewEdit.isSelected(); boolean check = cbNewEdit.isSelected();
for (int i = 0; i < m_editors.size(); i++) for (int i = 0; i < m_editors.size(); i++)
{ {
@ -896,7 +896,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
* Instance Selection Button * Instance Selection Button
* @return true if selected * @return true if selected
*/ */
private void cmd_select() protected void cmd_select()
{ {
log.config(""); log.config("");
@ -965,7 +965,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
/** /**
* Instance New/Edit * Instance New/Edit
*/ */
private void cmd_newEdit() protected void cmd_newEdit()
{ {
boolean rw = cbNewEdit.isChecked(); boolean rw = cbNewEdit.isChecked();
if (log.isLoggable(Level.CONFIG)) log.config("R/W=" + rw + " " + m_masi); if (log.isLoggable(Level.CONFIG)) log.config("R/W=" + rw + " " + m_masi);
@ -1005,7 +1005,7 @@ public class WPAttributeDialog extends Window implements EventListener<Event>
* Save Selection * Save Selection
* @return true if saved * @return true if saved
*/ */
private boolean saveSelection() protected boolean saveSelection()
{ {
log.info(""); log.info("");