IDEMPIERE-2911 NF3.0 Tree On Any Table not working correctly in subtab

This commit is contained in:
Carlos Ruiz 2018-12-29 00:04:32 +01:00
parent bce0ae0611
commit b32038f30b
12 changed files with 255 additions and 25 deletions

View File

@ -0,0 +1,51 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-2911
-- Dec 28, 2018, 10:15:03 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,AD_Val_Rule_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Reference_Value_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (213823,0,'Parent Column','The link column on the parent tab.',288,100,'Parent_Column_ID',22,'N','N','N','N','N',0,'N',18,251,0,0,'Y',TO_DATE('2018-12-28 22:15:03','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2018-12-28 22:15:03','YYYY-MM-DD HH24:MI:SS'),100,53874,'Y','N','D','N','N','N','Y','6ba6d93a-99c2-4b97-b8eb-df3739282a99','Y',0,'N','N','N','N')
;
-- Dec 28, 2018, 10:15:05 PM CET
UPDATE AD_Column SET FKConstraintName='ParentColumn_ADTree', FKConstraintType='N',Updated=TO_DATE('2018-12-28 22:15:05','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=213823
;
-- Dec 28, 2018, 10:15:05 PM CET
ALTER TABLE AD_Tree ADD Parent_Column_ID NUMBER(10) DEFAULT NULL
;
-- Dec 28, 2018, 10:15:05 PM CET
ALTER TABLE AD_Tree ADD CONSTRAINT ParentColumn_ADTree FOREIGN KEY (Parent_Column_ID) REFERENCES ad_column(ad_column_id) DEFERRABLE INITIALLY DEFERRED
;
-- Dec 28, 2018, 10:16:02 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (205899,'Parent Column','The link column on the parent tab.',243,213823,'Y',22,140,'N','N','N','N',0,0,'Y',TO_DATE('2018-12-28 22:16:01','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2018-12-28 22:16:01','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','37ab9f61-295a-4c3a-9fc0-e88e99e50e61','Y',130,2)
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=100, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, XPosition=1, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=205899
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=110, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5228
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=120, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=12421
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=130, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204379
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=140, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=8371
;
-- Dec 28, 2018, 10:17:22 PM CET
UPDATE AD_Field SET DisplayLogic='@TreeType@=''TL''', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2018-12-28 22:17:22','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=205899
;
SELECT register_migration_script('201812282333_IDEMPIERE-2911.sql') FROM dual
;

View File

@ -0,0 +1,48 @@
-- IDEMPIERE-2911
-- Dec 28, 2018, 10:15:03 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,AD_Val_Rule_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Reference_Value_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (213823,0,'Parent Column','The link column on the parent tab.',288,100,'Parent_Column_ID',22,'N','N','N','N','N',0,'N',18,251,0,0,'Y',TO_TIMESTAMP('2018-12-28 22:15:03','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2018-12-28 22:15:03','YYYY-MM-DD HH24:MI:SS'),100,53874,'Y','N','D','N','N','N','Y','6ba6d93a-99c2-4b97-b8eb-df3739282a99','Y',0,'N','N','N','N')
;
-- Dec 28, 2018, 10:15:05 PM CET
UPDATE AD_Column SET FKConstraintName='ParentColumn_ADTree', FKConstraintType='N',Updated=TO_TIMESTAMP('2018-12-28 22:15:05','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=213823
;
-- Dec 28, 2018, 10:15:05 PM CET
ALTER TABLE AD_Tree ADD COLUMN Parent_Column_ID NUMERIC(10) DEFAULT NULL
;
-- Dec 28, 2018, 10:15:05 PM CET
ALTER TABLE AD_Tree ADD CONSTRAINT ParentColumn_ADTree FOREIGN KEY (Parent_Column_ID) REFERENCES ad_column(ad_column_id) DEFERRABLE INITIALLY DEFERRED
;
-- Dec 28, 2018, 10:16:02 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (205899,'Parent Column','The link column on the parent tab.',243,213823,'Y',22,140,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2018-12-28 22:16:01','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2018-12-28 22:16:01','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','37ab9f61-295a-4c3a-9fc0-e88e99e50e61','Y',130,2)
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=100, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, XPosition=1, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=205899
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=110, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5228
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=120, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=12421
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=130, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204379
;
-- Dec 28, 2018, 10:16:56 PM CET
UPDATE AD_Field SET SeqNo=140, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:16:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=8371
;
-- Dec 28, 2018, 10:17:22 PM CET
UPDATE AD_Field SET DisplayLogic='@TreeType@=''TL''', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2018-12-28 22:17:22','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=205899
;
SELECT register_migration_script('201812282333_IDEMPIERE-2911.sql') FROM dual
;

View File

@ -215,6 +215,21 @@ public interface I_AD_Tree
*/ */
public String getName(); public String getName();
/** Column name Parent_Column_ID */
public static final String COLUMNNAME_Parent_Column_ID = "Parent_Column_ID";
/** Set Parent Column.
* The link column on the parent tab.
*/
public void setParent_Column_ID (int Parent_Column_ID);
/** Get Parent Column.
* The link column on the parent tab.
*/
public int getParent_Column_ID();
public org.compiere.model.I_AD_Column getParent_Column() throws RuntimeException;
/** Column name Processing */ /** Column name Processing */
public static final String COLUMNNAME_Processing = "Processing"; public static final String COLUMNNAME_Processing = "Processing";

View File

@ -34,6 +34,7 @@ import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Util;
/** /**
* Builds Tree. * Builds Tree.
@ -48,7 +49,7 @@ public class MTree extends MTree_Base
/** /**
* *
*/ */
private static final long serialVersionUID = -6412057411585787707L; private static final long serialVersionUID = -212066085945645584L;
/** /**
* Default Constructor. * Default Constructor.
@ -74,11 +75,23 @@ public class MTree extends MTree_Base
public MTree (Properties ctx, int AD_Tree_ID, public MTree (Properties ctx, int AD_Tree_ID,
boolean editable, boolean clientTree, String trxName) boolean editable, boolean clientTree, String trxName)
{ {
this (ctx, AD_Tree_ID, editable, clientTree, false, trxName); this (ctx, AD_Tree_ID, editable, clientTree, false, trxName, null, 0);
} // MTree
public MTree (Properties ctx, int AD_Tree_ID,
boolean editable, boolean clientTree, String trxName, String linkColName, int linkID)
{
this (ctx, AD_Tree_ID, editable, clientTree, false, trxName, linkColName, linkID);
} // MTree } // MTree
public MTree (Properties ctx, int AD_Tree_ID, public MTree (Properties ctx, int AD_Tree_ID,
boolean editable, boolean clientTree, boolean allNodes, String trxName) boolean editable, boolean clientTree, boolean allNodes, String trxName)
{
this (ctx, AD_Tree_ID, editable, clientTree, allNodes, trxName, null, 0);
} // MTree
public MTree (Properties ctx, int AD_Tree_ID,
boolean editable, boolean clientTree, boolean allNodes, String trxName, String linkColName, int linkID)
{ {
this (ctx, AD_Tree_ID, trxName); this (ctx, AD_Tree_ID, trxName);
m_editable = editable; m_editable = editable;
@ -93,7 +106,7 @@ public class MTree extends MTree_Base
+ ", Editable=" + editable + ", Editable=" + editable
+ ", OnClient=" + clientTree); + ", OnClient=" + clientTree);
// //
loadNodes(AD_User_ID); loadNodes(AD_User_ID, linkColName, linkID);
} // MTree } // MTree
/** Is Tree editable */ /** Is Tree editable */
@ -170,7 +183,7 @@ public class MTree extends MTree_Base
String query = "SELECT tr.AD_Tree_ID " String query = "SELECT tr.AD_Tree_ID "
+ "FROM AD_Tree tr " + "FROM AD_Tree tr "
+ "JOIN AD_Table t ON (tr.AD_Table_ID=t.AD_Table_ID) " + "JOIN AD_Table t ON (tr.AD_Table_ID=t.AD_Table_ID) "
+ "WHERE tr.AD_Client_ID=? AND tr.TreeType=? AND tr.IsActive='Y' AND tr.IsAllNodes='Y' AND t.TableName = ? " + "WHERE tr.AD_Client_ID=? AND tr.TreeType=? AND tr.IsActive='Y' AND t.TableName = ? "
+ "ORDER BY tr.AD_Tree_ID"; + "ORDER BY tr.AD_Tree_ID";
int treeID = DB.getSQLValueEx(null, query, Env.getAD_Client_ID(Env.getCtx()), TREETYPE_CustomTable, tableName); int treeID = DB.getSQLValueEx(null, query, Env.getAD_Client_ID(Env.getCtx()), TREETYPE_CustomTable, tableName);
@ -217,9 +230,11 @@ public class MTree extends MTree_Base
/************************************************************************* /*************************************************************************
* Load Nodes and Bar * Load Nodes and Bar
* @param AD_User_ID user for tree bar * @param AD_User_ID user for tree bar
* @param linkColName
* @param linkID
*/ */
private void loadNodes (int AD_User_ID) private void loadNodes (int AD_User_ID, String linkColName, int linkID)
{ {
// SQL for TreeNodes // SQL for TreeNodes
StringBuffer sql = new StringBuffer(); StringBuffer sql = new StringBuffer();
@ -252,6 +267,8 @@ public class MTree extends MTree_Base
+ "WHERE tn.AD_Tree_ID=?"); // #2 + "WHERE tn.AD_Tree_ID=?"); // #2
if (!m_editable) if (!m_editable)
sql.append(" AND tn.IsActive='Y'"); sql.append(" AND tn.IsActive='Y'");
if (!Util.isEmpty(linkColName))
sql.append(" AND st.").append(linkColName).append("=").append(linkID);
sql.append(" ORDER BY COALESCE(tn.Parent_ID, -1), tn.SeqNo"); sql.append(" ORDER BY COALESCE(tn.Parent_ID, -1), tn.SeqNo");
//do not check access if allNodes //do not check access if allNodes
if (AD_User_ID != -1) if (AD_User_ID != -1)

View File

@ -345,6 +345,11 @@ public class MTree_Base extends X_AD_Tree
if (!isActive() || !isAllNodes()) if (!isActive() || !isAllNodes())
setIsDefault(false); setIsDefault(false);
if (! TREETYPE_CustomTable.equals(getTreeType())) {
setAD_Table_ID(-1);
setParent_Column_ID(-1);
}
String tableName = getSourceTableName(true); String tableName = getSourceTableName(true);
MTable table = MTable.get(getCtx(), tableName); MTable table = MTable.get(getCtx(), tableName);
if (table.getColumnIndex("IsSummary") < 0) { if (table.getColumnIndex("IsSummary") < 0) {

View File

@ -67,6 +67,7 @@ import org.compiere.util.Msg;
import org.compiere.util.SecureEngine; import org.compiere.util.SecureEngine;
import org.compiere.util.Trace; import org.compiere.util.Trace;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.compiere.util.Util;
import org.compiere.util.ValueNamePair; import org.compiere.util.ValueNamePair;
import org.osgi.service.event.Event; import org.osgi.service.event.Event;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -108,7 +109,7 @@ public abstract class PO
/** /**
* *
*/ */
private static final long serialVersionUID = -6777678451696979575L; private static final long serialVersionUID = -1743619574547406959L;
public static final String LOCAL_TRX_PREFIX = "POSave"; public static final String LOCAL_TRX_PREFIX = "POSave";
@ -4013,7 +4014,14 @@ public abstract class PO
if (I_C_ElementValue.Table_Name.equals(sourceTableName)) { if (I_C_ElementValue.Table_Name.equals(sourceTableName)) {
newParentID = retrieveIdOfElementValue(value, getAD_Client_ID(), ((I_C_ElementValue)this).getC_Element().getC_Element_ID(), get_TrxName()); newParentID = retrieveIdOfElementValue(value, getAD_Client_ID(), ((I_C_ElementValue)this).getC_Element().getC_Element_ID(), get_TrxName());
} else { } else {
newParentID = retrieveIdOfParentValue(value, sourceTableName, getAD_Client_ID(), get_TrxName()); int linkColId = tree.getParent_Column_ID();
String linkColName = null;
int linkID = 0;
if (linkColId > 0) {
linkColName = MColumn.getColumnName(Env.getCtx(), linkColId);
linkID = (Integer)this.get_Value(linkColName);
}
newParentID = retrieveIdOfParentValue(value, sourceTableName, linkColName, linkID, getAD_Client_ID(), get_TrxName());
} }
int seqNo = DB.getSQLValueEx(get_TrxName(), selMinSeqNo, newParentID, tree.getAD_Tree_ID(), value); int seqNo = DB.getSQLValueEx(get_TrxName(), selMinSeqNo, newParentID, tree.getAD_Tree_ID(), value);
if (seqNo == -1) if (seqNo == -1)
@ -4040,9 +4048,17 @@ public abstract class PO
} }
/** Returns the summary node with the corresponding value */ /** Returns the summary node with the corresponding value */
public static int retrieveIdOfParentValue(String value, String tableName, int clientID, String trxName) public static int retrieveIdOfParentValue(String value, String tableName, int clientID, String trxName) {
return retrieveIdOfParentValue(value, tableName, null, 0, clientID, trxName);
}
public static int retrieveIdOfParentValue(String value, String tableName, String linkCol, int linkID, int clientID, String trxName)
{ {
String sql = "SELECT " + tableName + "_ID FROM " + tableName + " WHERE IsSummary='Y' AND AD_Client_ID=? AND Value=?"; String sql = "SELECT " + tableName + "_ID FROM " + tableName + " WHERE IsSummary='Y'";
if (!Util.isEmpty(linkCol)) {
sql = sql + " AND " + linkCol + "=" + linkID;
}
sql = sql + " AND AD_Client_ID=? AND Value=?";
int pos = value.length()-1; int pos = value.length()-1;
while (pos > 0) { while (pos > 0) {
String testParentValue = value.substring(0, pos); String testParentValue = value.substring(0, pos);

View File

@ -30,7 +30,7 @@ public class X_AD_Tree extends PO implements I_AD_Tree, I_Persistent
/** /**
* *
*/ */
private static final long serialVersionUID = 20181226L; private static final long serialVersionUID = 20181228L;
/** Standard Constructor */ /** Standard Constructor */
public X_AD_Tree (Properties ctx, int AD_Tree_ID, String trxName) public X_AD_Tree (Properties ctx, int AD_Tree_ID, String trxName)
@ -305,6 +305,34 @@ public class X_AD_Tree extends PO implements I_AD_Tree, I_Persistent
return new KeyNamePair(get_ID(), getName()); return new KeyNamePair(get_ID(), getName());
} }
public org.compiere.model.I_AD_Column getParent_Column() throws RuntimeException
{
return (org.compiere.model.I_AD_Column)MTable.get(getCtx(), org.compiere.model.I_AD_Column.Table_Name)
.getPO(getParent_Column_ID(), get_TrxName()); }
/** Set Parent Column.
@param Parent_Column_ID
The link column on the parent tab.
*/
public void setParent_Column_ID (int Parent_Column_ID)
{
if (Parent_Column_ID < 1)
set_Value (COLUMNNAME_Parent_Column_ID, null);
else
set_Value (COLUMNNAME_Parent_Column_ID, Integer.valueOf(Parent_Column_ID));
}
/** Get Parent Column.
@return The link column on the parent tab.
*/
public int getParent_Column_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_Parent_Column_ID);
if (ii == null)
return 0;
return ii.intValue();
}
/** Set Process Now. /** Set Process Now.
@param Processing Process Now */ @param Processing Process Now */
public void setProcessing (boolean Processing) public void setProcessing (boolean Processing)

View File

@ -73,6 +73,7 @@ import org.compiere.model.GridField;
import org.compiere.model.GridTab; import org.compiere.model.GridTab;
import org.compiere.model.GridTable; import org.compiere.model.GridTable;
import org.compiere.model.GridWindow; import org.compiere.model.GridWindow;
import org.compiere.model.MColumn;
import org.compiere.model.MTree; import org.compiere.model.MTree;
import org.compiere.model.MTreeNode; import org.compiere.model.MTreeNode;
import org.compiere.swing.CPanel; import org.compiere.swing.CPanel;
@ -658,8 +659,15 @@ public class GridController extends CPanel
if (AD_Tree_ID == 0) if (AD_Tree_ID == 0)
AD_Tree_ID = MTree.getDefaultAD_Tree_ID ( AD_Tree_ID = MTree.getDefaultAD_Tree_ID (
Env.getAD_Client_ID(Env.getCtx()), m_mTab.getKeyColumnName()); Env.getAD_Client_ID(Env.getCtx()), m_mTab.getKeyColumnName());
int linkColId = MTree.get(Env.getCtx(), AD_Tree_ID, null).getParent_Column_ID();
String linkColName = null;
int linkID = 0;
if (linkColId > 0) {
linkColName = MColumn.getColumnName(Env.getCtx(), linkColId);
linkID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, linkColName, true);
}
if (m_tree != null) if (m_tree != null)
m_tree.initTree (AD_Tree_ID); m_tree.initTree (AD_Tree_ID, linkColName, linkID);
} }
activateChilds(); activateChilds();

View File

@ -173,7 +173,7 @@ public final class VTreePanel extends CPanel
/** /**
* *
*/ */
private static final long serialVersionUID = -7188402231414573844L; private static final long serialVersionUID = 8238886431744822217L;
private static final String PREFIX_DOCUMENT_SEARCH = "/"; private static final String PREFIX_DOCUMENT_SEARCH = "/";
@ -242,13 +242,22 @@ public final class VTreePanel extends CPanel
* @return true if loaded ok * @return true if loaded ok
*/ */
public boolean initTree (int AD_Tree_ID) public boolean initTree (int AD_Tree_ID)
{
return initTree (AD_Tree_ID, null, 0);
}
public boolean initTree (int AD_Tree_ID, String linkColName, int linkID)
{ {
if (log.isLoggable(Level.CONFIG)) log.config("AD_Tree_ID=" + AD_Tree_ID); if (log.isLoggable(Level.CONFIG)) log.config("AD_Tree_ID=" + AD_Tree_ID);
// //
m_AD_Tree_ID = AD_Tree_ID; m_AD_Tree_ID = AD_Tree_ID;
// Get Tree // Get Tree
MTree vTree = new MTree (Env.getCtx(), AD_Tree_ID, m_editable, true, null); MTree vTree = null;
if (linkColName != null)
vTree = new MTree (Env.getCtx(), AD_Tree_ID, m_editable, true, null, linkColName, linkID);
else
vTree = new MTree (Env.getCtx(), AD_Tree_ID, m_editable, true, null);
m_root = vTree.getRoot(); m_root = vTree.getRoot();
m_root.setName(Msg.getMsg(Env.getCtx(), vTree.getName() ) ); // translate name of menu. m_root.setName(Msg.getMsg(Env.getCtx(), vTree.getName() ) ); // translate name of menu.
// m_root.setName(Msg.getMsg(Env.getCtx(), "Menu") ); // @Trifon; this is the hardcoded way. // m_root.setName(Msg.getMsg(Env.getCtx(), "Menu") ); // @Trifon; this is the hardcoded way.

View File

@ -67,6 +67,7 @@ import org.compiere.model.GridTab;
import org.compiere.model.GridTable; import org.compiere.model.GridTable;
import org.compiere.model.GridWindow; import org.compiere.model.GridWindow;
import org.compiere.model.I_AD_Preference; import org.compiere.model.I_AD_Preference;
import org.compiere.model.MColumn;
import org.compiere.model.MLookup; import org.compiere.model.MLookup;
import org.compiere.model.MPreference; import org.compiere.model.MPreference;
import org.compiere.model.MRole; import org.compiere.model.MRole;
@ -135,7 +136,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
/** /**
* *
*/ */
private static final long serialVersionUID = -1639104320722589666L; private static final long serialVersionUID = 5117210424909609150L;
private static final String ON_SAVE_OPEN_PREFERENCE_EVENT = "onSaveOpenPreference"; private static final String ON_SAVE_OPEN_PREFERENCE_EVENT = "onSaveOpenPreference";
@ -758,7 +759,14 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
treePanel.initTree(AD_Tree_ID, windowNo); treePanel.initTree(AD_Tree_ID, windowNo);
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null);
} else if (AD_Tree_ID_Default != 0) { } else if (AD_Tree_ID_Default != 0) {
treePanel.initTree(AD_Tree_ID_Default, windowNo); int linkColId = MTree.get(Env.getCtx(), AD_Tree_ID_Default, null).getParent_Column_ID();
String linkColName = null;
int linkID = 0;
if (linkColId > 0) {
linkColName = MColumn.getColumnName(Env.getCtx(), linkColId);
linkID = Env.getContextAsInt(Env.getCtx(), windowNo, linkColName, true);
}
treePanel.initTree(AD_Tree_ID_Default, windowNo, linkColName, linkID);
Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null);
} }
} }
@ -1441,13 +1449,25 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
else else
{ {
AD_Tree_ID = MTree.getDefaultAD_Tree_ID (Env.getAD_Client_ID(Env.getCtx()), gridTab.getKeyColumnName()); AD_Tree_ID = MTree.getDefaultAD_Tree_ID (Env.getAD_Client_ID(Env.getCtx()), gridTab.getKeyColumnName());
treePanel.initTree(AD_Tree_ID, windowNo); treePanel.prepareForRefresh();
int linkColId = MTree.get(Env.getCtx(), AD_Tree_ID, null).getParent_Column_ID();
String linkColName = null;
int linkID = 0;
if (linkColId > 0) {
linkColName = MColumn.getColumnName(Env.getCtx(), linkColId);
linkID = Env.getContextAsInt(Env.getCtx(), windowNo, linkColName, true);
}
if (treePanel.initTree(AD_Tree_ID, windowNo, linkColName, linkID))
echoDeferSetSelectedNodeEvent();
else
setSelectedNode(gridTab.getRecord_ID());
} }
} }
}else if(e.isInserting() && gridTab.getRecord_ID() < 0 && gridTab.getTabLevel() > 0 ) } else if (e.isInserting() && gridTab.getRecord_ID() < 0 && gridTab.getTabLevel() > 0
{ && gridTab.getParentTab() != null && gridTab.getParentTab().getValue("AD_Tree_ID") != null)
{
int AD_Tree_ID = Integer.parseInt(gridTab.getParentTab().getValue("AD_Tree_ID").toString()); int AD_Tree_ID = Integer.parseInt(gridTab.getParentTab().getValue("AD_Tree_ID").toString());
treePanel.initTree(AD_Tree_ID, windowNo); treePanel.initTree(AD_Tree_ID, windowNo);
} }

View File

@ -43,7 +43,7 @@ public class ADTreePanel extends Panel implements EventListener<Event>
/** /**
* *
*/ */
private static final long serialVersionUID = 164816320839461191L; private static final long serialVersionUID = 2718257463734592729L;
private static final String ON_EXPAND_MENU_EVENT = "onExpandMenu"; private static final String ON_EXPAND_MENU_EVENT = "onExpandMenu";
private TreeSearchPanel pnlSearch; private TreeSearchPanel pnlSearch;
private Tree tree; private Tree tree;
@ -70,11 +70,16 @@ public class ADTreePanel extends Panel implements EventListener<Event>
* @param windowNo * @param windowNo
*/ */
public boolean initTree(int AD_Tree_ID, int windowNo) public boolean initTree(int AD_Tree_ID, int windowNo)
{
return initTree(AD_Tree_ID, windowNo, null, 0);
}
public boolean initTree(int AD_Tree_ID, int windowNo, String linkColName, int linkID)
{ {
if (this.AD_Tree_ID != AD_Tree_ID) if (this.AD_Tree_ID != AD_Tree_ID)
{ {
this.AD_Tree_ID = AD_Tree_ID; this.AD_Tree_ID = AD_Tree_ID;
SimpleTreeModel.initADTree(tree, AD_Tree_ID, windowNo); SimpleTreeModel.initADTree(tree, AD_Tree_ID, windowNo, linkColName, linkID);
MTree_Base tb = MTree_Base.get(Env.getCtx(), AD_Tree_ID, null); MTree_Base tb = MTree_Base.get(Env.getCtx(), AD_Tree_ID, null);
if (tb.isLoadAllNodesImmediately()) if (tb.isLoadAllNodesImmediately())
TreeUtils.collapseTree(tree, true); TreeUtils.collapseTree(tree, true);

View File

@ -48,7 +48,7 @@ public class SimpleTreeModel extends org.zkoss.zul.DefaultTreeModel<Object> impl
/** /**
* *
*/ */
private static final long serialVersionUID = -1591436379012706094L; private static final long serialVersionUID = 4945968834244672653L;
private static final CLogger logger = CLogger.getCLogger(SimpleTreeModel.class); private static final CLogger logger = CLogger.getCLogger(SimpleTreeModel.class);
@ -68,6 +68,10 @@ public class SimpleTreeModel extends org.zkoss.zul.DefaultTreeModel<Object> impl
public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo) { public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo) {
return initADTree(tree, AD_Tree_ID, windowNo, true, null); return initADTree(tree, AD_Tree_ID, windowNo, true, null);
} }
public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo, String linkColName, int linkID) {
return initADTree(tree, AD_Tree_ID, windowNo, true, null, linkColName, linkID);
}
/** /**
* @param tree * @param tree
@ -77,8 +81,12 @@ public class SimpleTreeModel extends org.zkoss.zul.DefaultTreeModel<Object> impl
* @param trxName * @param trxName
* @return SimpleTreeModel * @return SimpleTreeModel
*/ */
public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo, boolean editable, String trxName) { public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo, boolean editable, String trxName) {
MTree vTree = new MTree (Env.getCtx(), AD_Tree_ID, editable, true, trxName); return initADTree(tree, AD_Tree_ID, windowNo, editable, trxName, null, 0);
}
public static SimpleTreeModel initADTree(Tree tree, int AD_Tree_ID, int windowNo, boolean editable, String trxName, String linkColName, int linkID) {
MTree vTree = new MTree (Env.getCtx(), AD_Tree_ID, editable, true, trxName, linkColName, linkID);
MTreeNode root = vTree.getRoot(); MTreeNode root = vTree.getRoot();
SimpleTreeModel treeModel = SimpleTreeModel.createFrom(root); SimpleTreeModel treeModel = SimpleTreeModel.createFrom(root);
treeModel.setItemDraggable(true); treeModel.setItemDraggable(true);