I have a set of 4 separate tables that represent a hierarchy; Division->Department->SubDepartment->Class. Each table has a primary key which is a number. The top level has a 2-digit primary key, the next level's key is 3-digits and the last two levels have 4-digit keys.
I've joined the tables together in a SQL UNION with a calculated ID field so they can be represented as a tree, with a unique ID and ParentID. This is the data source.
I've used this successfully in a TreeGrid and now I'm trying to use it in a PickTreeItem. The PickTreeItem is the editor for the "Class" field in a related data source. I want the users to be able to navigate the tree to pick a leaf "Class". I'm setting up the PickTreeItem like this.
The tree displays correctly and I can navigate down the tree to pick a Class. The problem is, when the form is populated with an existing record, the tree does not show the correct leaf in the tree based on the value for Class in the record.
I know it is because of the calculated ID field which doesn't correspond to the value for the Class. But how do I translate the Class value to the calculated ID field and vice versa when populating the form or getting values back from the form?
I've tried overriding the PickTreeItem's setValue() and getValue() methods, but those don't seem to be called when the form is populated with data or submitted.
Is there a better way to handle multiple tables that represent a tree like this?
I've joined the tables together in a SQL UNION with a calculated ID field so they can be represented as a tree, with a unique ID and ParentID. This is the data source.
Code:
<DataSource ID="IPMerchHierarchyDS" dataFormat="iscServer" serverType="sql" dbName="as400" sparseUpdates="true" tableName="IPMerchHierarchy" cacheAllData="true" serverConstructor="com.islandpacific.gui.server.customDataSource.IpDataSource"> <!-- Full merchandise hierarchy in a tree view. --> <fields> <field name="Name" type="text" canFilter="true"> <filterEditorProperties operator="iContains" /> </field> <field name="ID" type="integer" primaryKey="true" canFilter="false" hidden="true"/> <field name="ParentID" type="integer" rootValue="0" canFilter="false" hidden="true" foreignKey="IPMerchHierarchy.ID" /> <field name="Type" type="text" length="3" canFilter="true" detail="true"> <filterEditorProperties operator="equals" /> <valueMap> <value ID="DIV">Division</value> <value ID="DPT">Department</value> <value ID="SUB">Sub-department</value> <value ID="CLS">Class</value> </valueMap> </field> <field name="Code" type="integer" length="4" canFilter="true"> <filterEditorProperties operator="equals" /> </field> </fields> <operationBindings> <operationBinding operationType="fetch"> <customSQL> <![CDATA[ WITH IpMerchHierarchy AS ( select 100+DDIV ID, DNAM Name, 0 ParentID, 'DIV' Type, DDIV Code from ipdivsn union select 1000+DDPT ID, DNAM Name, 100+DDIV ParentID, 'DPT' Type, DDPT Code from ipdepts union select 10000+SSBD ID, SNAM Name, 1000+SDPT ParentID, 'SUB' Type, SSBD Code from ipsbdpt union select 100000+CCLS ID, CLNM Name, 10000+CSBD ParentID, 'CLS' Type, CCLS Code from ipclass ) SELECT * FROM IpMerchHierarchy WHERE $defaultWhereClause ]]> </customSQL> </operationBinding> </operationBindings> </DataSource>
Code:
DataSource merchHierarchyDS = DataSource.get(IslandPacificDSConstants.DATASOURCE_IPMerchHierarchyDS); setDataSource(merchHierarchyDS); setValueField("Code"); setLoadDataOnDemand(false); setCanSelectParentItems(false);
I know it is because of the calculated ID field which doesn't correspond to the value for the Class. But how do I translate the Class value to the calculated ID field and vice versa when populating the form or getting values back from the form?
I've tried overriding the PickTreeItem's setValue() and getValue() methods, but those don't seem to be called when the form is populated with data or submitted.
Is there a better way to handle multiple tables that represent a tree like this?
Comment