Hi,
by reading the following thread I managed to get my treegrid filled with the objects of two different datasources;
http://forums.smartclient.com/showthread.php?t=11861&highlight=treegrid+datasources
I have two ds.xml files for each source which I load within the Store class and convert the objects of both sources two a common interface:
With this interface the tree gets filled by this xml definition:
Now I am facing 2 major problems:
1) How to handle the IDs? Right now I am converting the job IDs by multiplying by 10 so the IDs stay unique. But this is not an option, because when I have more than 100 servers, the IDs would not be unique again.
What do you recommend?
(I need the IDs to indicate dependencies from jobs that run on certain servers.)
2) How do I implement the following scenario: A click on an object within the tree opens either a server specific dynamic editor or a job specific one - depending on the former type of the object. I can read the type with the following code:
But having a dynamic form with the "servers" datasource attached I cannot go with
as these are two records from different datasources.
So how do I manage to open a selected item from the tree inside a dynamic form that is attached to either "servers" DS or "jobs" DS.
(Just the opening or searching for the openRecord(XXX) is required as I can read the type as shown in my code.)
Big thank you for your help!
by reading the following thread I managed to get my treegrid filled with the objects of two different datasources;
http://forums.smartclient.com/showthread.php?t=11861&highlight=treegrid+datasources
I have two ds.xml files for each source which I load within the Store class and convert the objects of both sources two a common interface:
Code:
public interface TreeItem { public enum OriginalType { Server, Job } public Long getId(); public void setId(Long id); public String getTitle(); public void setTitle(String title); public Long getParentId(); public void setParentId(Long parentId); public OriginalType getOriginalType(); }
Code:
DataSource serverDS = DataSourceManager.get("servers"); List servers = serverDS.fetch(new HashMap()); int maxServerRows = servers.size(); if (maxServerRows > 300) maxServerRows = 300; for (int i = 0; i < maxServerRows; i++) { Map properties = (Map)servers.get(i); TreeItem item = new ServerItem(); DataTools.setProperties(properties, item); item.setParentId(0L); storeItem(item); } DataSource jobDS = DataSourceManager.get("jobs"); List jobs = jobDS.fetch(new HashMap()); int maxJobRows = jobs.size(); if (maxJobRows > 300) maxJobRows = 300; for (int i = 0; i < maxJobRows; i++) { Map properties = (Map)jobs.get(i); TreeItem item = new JobItem(); DataTools.setProperties(properties, item); item.setId(item.getId()*10); // DEBUG storeItem(item); }
Code:
<DataSource ID="treeitems" serverType="generic"> <fields> <field name="id" title="ID" type="integer" primaryKey="true" required="true" hidden="true" /> <field name="title" title="Title" type="text" /> <field name="parentId" title="Parent ID" type="integer" foreignKey="treeitems.id" rootvalue="0" /> <field name="originalType" title="Entity type" type="com.hp.dp7.serverdialog.smartgwt.server.TreeItem.OriginalType" hidden="true" /> </fields> <serverObject lookupStyle="new" className="com.hp.dp7.serverdialog.smartgwt.server.TreeItemsDMI"/> </DataSource>
Now I am facing 2 major problems:
1) How to handle the IDs? Right now I am converting the job IDs by multiplying by 10 so the IDs stay unique. But this is not an option, because when I have more than 100 servers, the IDs would not be unique again.
What do you recommend?
(I need the IDs to indicate dependencies from jobs that run on certain servers.)
2) How do I implement the following scenario: A click on an object within the tree opens either a server specific dynamic editor or a job specific one - depending on the former type of the object. I can read the type with the following code:
Code:
tree.addSelectionChangedHandler(new SelectionChangedHandler() { @Override public void onSelectionChanged(SelectionEvent event) { //Window.alert("Selected a " + event.getRecord().getAttributeAsString("originalType")); } });
Code:
editRecord(event.getRecord())
So how do I manage to open a selected item from the tree inside a dynamic form that is attached to either "servers" DS or "jobs" DS.
(Just the opening or searching for the openRecord(XXX) is required as I can read the type as shown in my code.)
Big thank you for your help!
Comment