IDEMPIERE-4867 Updating moving node by PO (#810)
* Using PO update for all node that's being updated * Using saveEx(trxName) when saving PO for all updated nodes * Checking PO.is_Changed() and using saveEx(trxName) when saving PO for all updated nodes
This commit is contained in:
parent
ce689bbbc2
commit
b8437b2c23
|
@ -18,8 +18,9 @@ import org.adempiere.webui.util.TreeUtils;
|
|||
import org.adempiere.webui.window.FDialog;
|
||||
import org.compiere.model.MTree;
|
||||
import org.compiere.model.MTreeNode;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.Query;
|
||||
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;
|
||||
|
@ -163,22 +164,12 @@ public class ADTreeOnDropListener implements EventListener<Event> {
|
|||
trx.setDisplayName(getClass().getName()+"_moveNode");
|
||||
try
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
int no = 0;
|
||||
MTreeNode oldMParent = (MTreeNode) oldParent.getData();
|
||||
for (int i = 0; i < oldParent.getChildCount(); i++)
|
||||
{
|
||||
DefaultTreeNode<?> nd = (DefaultTreeNode<?>)oldParent.getChildAt(i);
|
||||
MTreeNode md = (MTreeNode) nd.getData();
|
||||
StringBuilder sql = new StringBuilder("UPDATE ");
|
||||
sql.append(mTree.getNodeTableName())
|
||||
.append(" SET Parent_ID=").append(oldMParent.getNode_ID())
|
||||
.append(", SeqNo=").append(i)
|
||||
.append(", Updated=getDate()")
|
||||
.append(" WHERE AD_Tree_ID=").append(mTree.getAD_Tree_ID())
|
||||
.append(" AND Node_ID=").append(md.getNode_ID());
|
||||
if (log.isLoggable(Level.FINE)) log.fine(sql.toString());
|
||||
no = DB.executeUpdate(sql.toString(),trx.getTrxName());
|
||||
updateNodePO(oldMParent, md, i, trx.getTrxName());
|
||||
}
|
||||
if (oldParent != newParent)
|
||||
{
|
||||
|
@ -187,15 +178,7 @@ public class ADTreeOnDropListener implements EventListener<Event> {
|
|||
{
|
||||
DefaultTreeNode<?> nd = (DefaultTreeNode<?>)newParent.getChildAt(i);
|
||||
MTreeNode md = (MTreeNode) nd.getData();
|
||||
StringBuilder sql = new StringBuilder("UPDATE ");
|
||||
sql.append(mTree.getNodeTableName())
|
||||
.append(" SET Parent_ID=").append(newMParent.getNode_ID())
|
||||
.append(", SeqNo=").append(i)
|
||||
.append(", Updated=getDate()")
|
||||
.append(" WHERE AD_Tree_ID=").append(mTree.getAD_Tree_ID())
|
||||
.append(" AND Node_ID=").append(md.getNode_ID());
|
||||
if (log.isLoggable(Level.FINE)) log.fine(sql.toString());
|
||||
DB.executeUpdateEx(sql.toString(),trx.getTrxName());
|
||||
updateNodePO(newMParent, md, i, trx.getTrxName());
|
||||
}
|
||||
}
|
||||
// COMMIT *********************
|
||||
|
@ -213,6 +196,16 @@ public class ADTreeOnDropListener implements EventListener<Event> {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateNodePO(MTreeNode mtnParentNode, MTreeNode mtnMovingNode, int NodeIndex, String trxName) {
|
||||
StringBuilder whereClause = new StringBuilder("AD_Tree_ID=").append(mTree.getAD_Tree_ID())
|
||||
.append(" AND Node_ID=").append(mtnMovingNode.getNode_ID());
|
||||
PO mnPO = new Query(Env.getCtx(), mTree.getNodeTableName(), whereClause.toString(), trxName).first();
|
||||
mnPO.set_ValueNoCheck("Parent_ID", mtnParentNode.getNode_ID());
|
||||
mnPO.set_ValueNoCheck("SeqNo", NodeIndex);
|
||||
if (mnPO.is_Changed())
|
||||
mnPO.saveEx(trxName);
|
||||
}
|
||||
|
||||
class MenuListener implements EventListener<Event> {
|
||||
private DefaultTreeNode<Object> movingNode;
|
||||
private DefaultTreeNode<Object> toNode;
|
||||
|
|
Loading…
Reference in New Issue