IDEMPIERE-417 Update BPLocation.Name

This commit is contained in:
Carlos Ruiz 2012-09-12 10:47:44 -05:00
parent af759b7134
commit d20678cab8
6 changed files with 99 additions and 54 deletions

View File

@ -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

View File

@ -656,12 +656,14 @@ public class MLocation extends X_C_Location implements Comparator<Object>
+ " 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

View File

@ -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
/**

View File

@ -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
/**

View File

@ -164,7 +164,7 @@ public class WLocationEditor extends WEditor implements EventListener<Event>, 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<Event>() {
@Override
@ -179,14 +179,6 @@ public class WLocationEditor extends WEditor implements EventListener<Event>, 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);
}
});

View File

@ -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