From d20678cab83be16356b41acd366cb4025508fa4f Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 12 Sep 2012 10:47:44 -0500 Subject: [PATCH] IDEMPIERE-417 Update BPLocation.Name --- .../org/compiere/model/MBPartnerLocation.java | 8 ++-- .../src/org/compiere/model/MLocation.java | 14 +++--- .../src/org/compiere/grid/ed/VLocation.java | 28 +++-------- .../org/compiere/grid/ed/VLocationDialog.java | 46 +++++++++++++++--- .../webui/editor/WLocationEditor.java | 10 +--- .../webui/window/WLocationDialog.java | 47 ++++++++++++++++--- 6 files changed, 99 insertions(+), 54 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MBPartnerLocation.java b/org.adempiere.base/src/org/compiere/model/MBPartnerLocation.java index 07f54b9b06..e4e5b48c20 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPartnerLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MBPartnerLocation.java @@ -167,10 +167,10 @@ public class MBPartnerLocation extends X_C_BPartner_Location { return false; // Set New Name - if (!newRecord) - return true; - MLocation address = getLocation(true); - setName(getBPLocName(address)); + if (".".equals(getName())) { + MLocation address = getLocation(true); + setName(getBPLocName(address)); + } return true; } // beforeSave diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index 7571b09589..d49e9d0c5d 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -656,12 +656,14 @@ public class MLocation extends X_C_Location implements Comparator + " OR C_LocTo_ID=" + getC_Location_ID() + ")", get_TrxName()); //Update BP_Location name IDEMPIERE 417 - int bplID = DB.getSQLValueEx(get_TrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + getC_Location_ID()); - if (bplID>0) - { - MBPartnerLocation bpl = new MBPartnerLocation(getCtx(), bplID, get_TrxName()); - bpl.setName(bpl.getBPLocName(this)); - bpl.saveEx(); + if (get_TrxName().startsWith(PO.LOCAL_TRX_PREFIX)) { // saved without trx + int bplID = DB.getSQLValueEx(get_TrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + getC_Location_ID()); + if (bplID>0) + { + MBPartnerLocation bpl = new MBPartnerLocation(getCtx(), bplID, get_TrxName()); + bpl.setName(bpl.getBPLocName(this)); + bpl.saveEx(); + } } return success; } // afterSave diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocation.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocation.java index 9cfc0a0e52..ec08b06d30 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocation.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocation.java @@ -353,7 +353,7 @@ public class VLocation extends JComponent // log.config( "actionPerformed - " + m_value); VLocationDialog ld = new VLocationDialog(AEnv.getFrame(this), - Msg.getMsg(Env.getCtx(), "Location"), m_value); + Msg.getMsg(Env.getCtx(), "Location"), m_value, m_GridField); ld.setVisible(true); Object oldValue = getValue(); m_value = ld.getValue(); @@ -364,27 +364,11 @@ public class VLocation extends JComponent return; // Data Binding - try - { - int C_Location_ID = 0; - if (m_value != null) - C_Location_ID = m_value.getC_Location_ID(); - Integer ii = new Integer(C_Location_ID); - - if (C_Location_ID != 0) - fireVetoableChange(m_columnName, oldValue, ii); - setValue(ii); - if (ii.equals(oldValue) && m_GridTab != null && m_GridField != null) - { - // force Change - user does not realize that embedded object is already saved. - m_GridTab.processFieldChange(m_GridField); - } - } - catch (PropertyVetoException pve) - { - log.log(Level.SEVERE, "VLocation.actionPerformed", pve); - } - + int C_Location_ID = 0; + if (m_value != null) + C_Location_ID = m_value.getC_Location_ID(); + Integer ii = new Integer(C_Location_ID); + setValue(ii); } // actionPerformed /** diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java index 6926d2c89f..88152127eb 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocationDialog.java @@ -39,6 +39,8 @@ import javax.swing.SwingConstants; import org.compiere.apps.ADialog; import org.compiere.apps.AEnv; import org.compiere.apps.ConfirmPanel; +import org.compiere.model.GridField; +import org.compiere.model.MBPartnerLocation; import org.compiere.model.MCountry; import org.compiere.model.MLocation; import org.compiere.model.MOrgInfo; @@ -50,8 +52,10 @@ import org.compiere.swing.CLabel; import org.compiere.swing.CPanel; import org.compiere.swing.CTextField; import org.compiere.util.CLogger; +import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.Trx; import com.akunagroup.uk.postcode.AddressLookupInterface; import com.akunagroup.uk.postcode.Postcode; @@ -90,6 +94,8 @@ public class VLocationDialog extends CDialog private int m_WindowNo = 0; + private GridField m_GridField = null; + /** * Constructor * @@ -99,7 +105,12 @@ public class VLocationDialog extends CDialog */ public VLocationDialog (Frame frame, String title, MLocation location) { + this(frame, title, location, null); + } // VLocationDialog + + public VLocationDialog(Frame frame, String title, MLocation location, GridField gridField) { super(frame, title, true); + m_GridField = gridField; //m_WindowNo = WindowNo; try { @@ -143,7 +154,7 @@ public class VLocationDialog extends CDialog fOnline.addActionListener(this); fRegion.addActionListener(this); AEnv.positionCenterWindow(frame, this); - } // VLocationDialog + } private boolean m_change = false; private MLocation m_location; @@ -574,6 +585,8 @@ public class VLocationDialog extends CDialog */ private boolean action_OK() { + Trx trx = Trx.get(Trx.createTrxName("VLocationDialog"), true); + m_location.set_TrxName(trx.getTrxName()); m_location.setAddress1(fAddress1.getText()); m_location.setAddress2(fAddress2.getText()); m_location.setAddress3(fAddress3.getText()); @@ -593,14 +606,35 @@ public class VLocationDialog extends CDialog else m_location.setC_Region_ID(0); // Save changes - if(m_location.save()) + boolean success = false; + if (m_location.save()) { - return true; + // IDEMPIERE-417 Force Update BPLocation.Name + if (m_GridField != null && m_GridField.getGridTab() != null + && "C_BPartner_Location".equals(m_GridField.getGridTab().getTableName())) + { + m_GridField.getGridTab().setValue("Name", "."); + success = true; + } else { + //Update BP_Location name IDEMPIERE 417 + int bplID = DB.getSQLValueEx(trx.getTrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + m_location.getC_Location_ID()); + if (bplID>0) + { + MBPartnerLocation bpl = new MBPartnerLocation(Env.getCtx(), bplID, trx.getTrxName()); + bpl.setName(bpl.getBPLocName(m_location)); + if (bpl.save()) + success = true; + } + } } - else - { - return false; + if (success) { + trx.commit(); + } else { + trx.rollback(); } + trx.close(); + + return success; } // actionOK /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java index d2ca26b81c..e4043be53e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocationEditor.java @@ -164,7 +164,7 @@ public class WLocationEditor extends WEditor implements EventListener, Pr if ("onClick".equals(event.getName())) { log.config( "actionPerformed - " + m_value); - final WLocationDialog ld = new WLocationDialog(Msg.getMsg(Env.getCtx(), "Location"), m_value); + final WLocationDialog ld = new WLocationDialog(Msg.getMsg(Env.getCtx(), "Location"), m_value, gridField); ld.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { @Override @@ -179,14 +179,6 @@ public class WLocationEditor extends WEditor implements EventListener, Pr if (m_value != null) C_Location_ID = m_value.getC_Location_ID(); Integer ii = new Integer(C_Location_ID); - // force Change - user does not realize that embedded object is already saved. - ValueChangeEvent valuechange = new ValueChangeEvent(WLocationEditor.this,getColumnName(),null,null); - fireValueChange(valuechange); // resets m_mLocation - if (C_Location_ID != 0) - { - ValueChangeEvent vc = new ValueChangeEvent(WLocationEditor.this,getColumnName(),null,ii); - fireValueChange(vc); - } setValue(ii); } }); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java index 33932ae62e..167adc8b94 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WLocationDialog.java @@ -36,13 +36,17 @@ import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Row; import org.adempiere.webui.component.Textbox; import org.adempiere.webui.component.Window; +import org.compiere.model.GridField; +import org.compiere.model.MBPartnerLocation; import org.compiere.model.MCountry; import org.compiere.model.MLocation; import org.compiere.model.MOrgInfo; import org.compiere.model.MRegion; import org.compiere.util.CLogger; +import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.Trx; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -125,10 +129,16 @@ public class WLocationDialog extends Window implements EventListener private Button toLink; private Button toRoute; + private GridField m_GridField = null; //END public WLocationDialog(String title, MLocation location) { + this (title, location, null); + } + + public WLocationDialog(String title, MLocation location, GridField gridField) { + m_GridField = gridField; m_location = location; if (m_location == null) m_location = new MLocation (Env.getCtx(), 0, null); @@ -511,7 +521,7 @@ public class WLocationDialog extends Window implements EventListener return; } - if(action_OK()) + if (action_OK()) { m_change = true; inOKAction = false; @@ -626,6 +636,8 @@ public class WLocationDialog extends Window implements EventListener */ private boolean action_OK() { + Trx trx = Trx.get(Trx.createTrxName("WLocationDialog"), true); + m_location.set_TrxName(trx.getTrxName()); m_location.setAddress1(txtAddress1.getValue()); m_location.setAddress2(txtAddress2.getValue()); m_location.setAddress3(txtAddress3.getValue()); @@ -645,15 +657,36 @@ public class WLocationDialog extends Window implements EventListener { m_location.setC_Region_ID(0); } - // Save chnages - if(m_location.save()) + // Save changes + boolean success = false; + if (m_location.save()) { - return true; + // IDEMPIERE-417 Force Update BPLocation.Name + if (m_GridField != null && m_GridField.getGridTab() != null + && "C_BPartner_Location".equals(m_GridField.getGridTab().getTableName())) + { + m_GridField.getGridTab().setValue("Name", "."); + success = true; + } else { + //Update BP_Location name IDEMPIERE 417 + int bplID = DB.getSQLValueEx(trx.getTrxName(), "SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_Location_ID = " + m_location.getC_Location_ID()); + if (bplID>0) + { + MBPartnerLocation bpl = new MBPartnerLocation(Env.getCtx(), bplID, trx.getTrxName()); + bpl.setName(bpl.getBPLocName(m_location)); + if (bpl.save()) + success = true; + } + } } - else - { - return false; + if (success) { + trx.commit(); + } else { + trx.rollback(); } + trx.close(); + + return success; } // actionOK @Override