BF [ 2866493 ] VTreePanel is not saving who did the node move

https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2866493&group_id=176962

* refactored AD_TreeNode update part
* fixed AD_TreeNode insertion too (from PO)

Please help me with review
This commit is contained in:
teo_sarca 2009-09-25 11:45:33 +00:00
parent 8825f20780
commit dde0f2b5f4
2 changed files with 50 additions and 57 deletions

View File

@ -78,6 +78,8 @@ import org.w3c.dom.Element;
* https://sourceforge.net/tracker/?func=detail&aid=2849122&group_id=176962&atid=879332 * https://sourceforge.net/tracker/?func=detail&aid=2849122&group_id=176962&atid=879332
* <li>BF [ 2859125 ] Can't set AD_OrgBP_ID * <li>BF [ 2859125 ] Can't set AD_OrgBP_ID
* https://sourceforge.net/tracker/index.php?func=detail&aid=2859125&group_id=176962&atid=879332 * https://sourceforge.net/tracker/index.php?func=detail&aid=2859125&group_id=176962&atid=879332
* <li>BF [ 2866493 ] VTreePanel is not saving who did the node move
* https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2866493&group_id=176962
* @author Victor Perez, e-Evolution SC * @author Victor Perez, e-Evolution SC
* <li>[ 2195894 ] Improve performance in PO engine * <li>[ 2195894 ] Improve performance in PO engine
* <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335 * <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335
@ -3324,7 +3326,7 @@ public abstract class PO
.append(MTree_Base.getNodeTableName(treeType)) .append(MTree_Base.getNodeTableName(treeType))
.append(" (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, " .append(" (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, "
+ "AD_Tree_ID, Node_ID, Parent_ID, SeqNo) " + "AD_Tree_ID, Node_ID, Parent_ID, SeqNo) "
+ "SELECT t.AD_Client_ID,0, 'Y', SysDate, 0, SysDate, 0," + "SELECT t.AD_Client_ID, 0, 'Y', SysDate, "+getUpdatedBy()+", SysDate, "+getUpdatedBy()+","
+ "t.AD_Tree_ID, ").append(get_ID()).append(", 0, 999 " + "t.AD_Tree_ID, ").append(get_ID()).append(", 0, 999 "
+ "FROM AD_Tree t " + "FROM AD_Tree t "
+ "WHERE t.AD_Client_ID=").append(getAD_Client_ID()).append(" AND t.IsActive='Y'"); + "WHERE t.AD_Client_ID=").append(getAD_Client_ID()).append(" AND t.IsActive='Y'");

View File

@ -91,6 +91,7 @@ import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.compiere.util.TrxRunnable;
import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer; import org.jdesktop.swingx.JXTaskPaneContainer;
@ -111,8 +112,12 @@ import de.schaeffer.compiere.tools.DocumentSearch;
* @author Jorg Janke * @author Jorg Janke
* @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ * @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $
* *
* Contributors: * @author kthiemann / Carlos Ruiz
* kthiemann / Carlos Ruiz - 2761420 - Advanced Search * <li>2761420 - Advanced Search
*
* @author Teo Sarca
* <li>BF [ 2866493 ] VTreePanel is not saving who did the node move
* https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2866493&group_id=176962
*/ */
public final class VTreePanel extends CPanel public final class VTreePanel extends CPanel
implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener
@ -627,12 +632,12 @@ public final class VTreePanel extends CPanel
return; return;
// remove // remove
MTreeNode oldParent = (MTreeNode)movingNode.getParent(); final MTreeNode oldParent = (MTreeNode)movingNode.getParent();
movingNode.removeFromParent(); movingNode.removeFromParent();
treeModel.nodeStructureChanged(oldParent); treeModel.nodeStructureChanged(oldParent);
// insert // insert
MTreeNode newParent; final MTreeNode newParent;
int index; int index;
if (!toNode.isSummary()) // drop on a child node if (!toNode.isSummary()) // drop on a child node
{ {
@ -648,69 +653,55 @@ public final class VTreePanel extends CPanel
treeModel.nodeStructureChanged(newParent); treeModel.nodeStructureChanged(newParent);
// *** Save changes to disk // *** Save changes to disk
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Trx trx = Trx.get (Trx.createTrxName("VTreePanel"), true);
try try
{ {
//begin vpj-cd e-evolution 07/12/2005 PostgreSQL setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//Statement stmt = trx.getConnection().createStatement(); Trx.run(new TrxRunnable() {
//end vpj-cd e-evolution 07/12/2005 PostgreSQL public void run(String trxName) {
// START TRANSACTION ************** for (int i = 0; i < oldParent.getChildCount(); i++)
int no = 0; {
for (int i = 0; i < oldParent.getChildCount(); i++) MTreeNode nd = (MTreeNode)oldParent.getChildAt(i);
{ updateTreeNode(nd.getNode_ID(), oldParent.getNode_ID(), i, trxName);
MTreeNode nd = (MTreeNode)oldParent.getChildAt(i); }
StringBuffer sql = new StringBuffer("UPDATE "); if (oldParent != newParent)
sql.append(m_nodeTableName) {
.append(" SET Parent_ID=").append(oldParent.getNode_ID()) for (int i = 0; i < newParent.getChildCount(); i++)
.append(", SeqNo=").append(i) {
.append(", Updated=SysDate") MTreeNode nd = (MTreeNode)newParent.getChildAt(i);
.append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) updateTreeNode(nd.getNode_ID(), newParent.getNode_ID(), i, trxName);
.append(" AND Node_ID=").append(nd.getNode_ID()); }
log.fine(sql.toString()); }
//begin vpj-cd e-evolution 07/12/2005 PostgreSQL
//stmt.executeUpdate(sql.toString());
no = DB.executeUpdate(sql.toString(),trx.getTrxName());
//end vpj-cd e-evolution 07/12/2005 PostgreSQL
}
if (oldParent != newParent)
for (int i = 0; i < newParent.getChildCount(); i++)
{
MTreeNode nd = (MTreeNode)newParent.getChildAt(i);
StringBuffer sql = new StringBuffer("UPDATE ");
sql.append(m_nodeTableName)
.append(" SET Parent_ID=").append(newParent.getNode_ID())
.append(", SeqNo=").append(i)
.append(", Updated=SysDate")
.append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
.append(" AND Node_ID=").append(nd.getNode_ID());
log.fine(sql.toString());
//begin vpj-cd e-evolution 07/12/2005 PostgreSQL
//stmt.executeUpdate(sql.toString());
no = DB.executeUpdate(sql.toString(),trx.getTrxName());
//end vpj-cd e-evolution 07/12/2005 PostgreSQL
} }
// COMMIT ********************* });
trx.commit(true);
//begin vpj-cd e-evolution 07/12/2005 PostgreSQL
//stmt.close();
//end vpj-cd e-evolution 07/12/2005 PostgreSQL
} }
///begin vpj-cd e-evolution 07/12/2005 PostgreSQL catch (Exception e)
//catch (SQLException e)
catch (Exception e)
//end vpj-cd e-evolution 07/12/2005 PostgreSQL
{ {
trx.rollback();
log.log(Level.SEVERE, "move", e); log.log(Level.SEVERE, "move", e);
ADialog.error(m_WindowNo, this, "TreeUpdateError", e.getLocalizedMessage()); ADialog.error(m_WindowNo, this, "TreeUpdateError", e.getLocalizedMessage());
} }
trx.close(); finally
trx = null; {
setCursor(Cursor.getDefaultCursor()); setCursor(Cursor.getDefaultCursor());
}
log.config("complete"); log.config("complete");
} // moveNode } // moveNode
private int updateTreeNode(int Node_ID, int Parent_ID, int SeqNo, String trxName)
{
// We do not use parametrized statements because we need to log these migration scripts
StringBuffer sql = new StringBuffer("UPDATE ");
sql.append(m_nodeTableName)
.append(" SET Parent_ID=").append(Parent_ID)
.append(", SeqNo=").append(SeqNo)
.append(", Updated=SysDate")
.append(", UpdatedBy=").append(Env.getAD_User_ID(Env.getCtx()))
.append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID)
.append(" AND Node_ID=").append(Node_ID);
log.fine(sql.toString());
int no = DB.executeUpdateEx(sql.toString(), trxName);
return no;
}
/*************************************************************************/ /*************************************************************************/