Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeGrid node expansion question

    Hi there,
    I'm on latest nightly build of evaluation SmartGWT EE, and I'm testing TreeGrid functionalities.

    This is my TreeGrid code:

    Code:
    Tree tree = new Tree();
    tree.setModelType(TreeModelType.PARENT);
    
    kioskGroupTreeGrid = new TreeGrid();
    kioskGroupTreeGrid.setData(tree);
    kioskGroupTreeGrid.setDataSource(DTPDataSourceManager.getDatasource(DTPDataSourceType.KIOSK_GROUP_DS));
    kioskGroupTreeGrid.setHeight100();
    kioskGroupTreeGrid.setShowHeader(false);
    kioskGroupTreeGrid.setLeaveScrollbarGap(false);
    kioskGroupTreeGrid.setAnimateFolders(true);
    kioskGroupTreeGrid.setCanAcceptDroppedRecords(true);
    kioskGroupTreeGrid.setCanReparentNodes(true);
    kioskGroupTreeGrid.setSortField("name");
    kioskGroupTreeGrid.setCanEdit(true);
    kioskGroupTreeGrid.setSelectionType(SelectionStyle.SINGLE);
    kioskGroupTreeGrid.setShowConnectors(true);
    kioskGroupTreeGrid.setShowFullConnectors(true);
    kioskGroupTreeGrid.setGridComponents((new Object[] { ListGridComponent.HEADER, ListGridComponent.FILTER_EDITOR, ListGridComponent.BODY, getKioskGroupTreeGridToolStrip() }));
    kioskGroupTreeGrid.setAutoFetchData(true);
    
    TreeGridField fieldName = new TreeGridField("name");
    kioskGroupTreeGrid.setFields(fieldName);
    addMember(kioskGroupTreeGrid);
    My TreeGrid is bound to DataSource and all CRUD operation are implemented and working.

    At loading, my pane shows only "root" nodes loaded from database (correct). When I expand them, via "fetch" DMI method I retrieve sub-structures, and show. The problem is that the "expand\collapse icon [+]" appears even if the node is a "leaf" and not a "folder". I saw same thing into Showcase demo application. Is there any way to avoid this?

    This is my fetch(...) method:
    Code:
    public DSResponse fetch(DSRequest dsRequest) throws Exception {
            DSResponse dsResponse = new DSResponse();
    	Long parentId = null;
    	if (dsRequest.getFieldValue("parentId") instanceof String) {
    		parentId = Long.parseLong((String) dsRequest.getFieldValue("parentId"));
    	} else {
    		parentId = (Long) dsRequest.getFieldValue("parentId");
    	}
    	Session hibernateSession = sessionFactory.getCurrentSession();
    	List<KioskGroup> kioskGroupList = hibernateSession.getNamedQuery("KioskGroup.fetchByParentId").setLong("parentId", parentId).list();
    	log.info("FETCH " + kioskGroupList.size() + " KioskGroup record");
    	dsResponse.setData(kioskGroupList);
    	return dsResponse;
    }
    Thanks for support.

    Luca.
    Last edited by l.arcangeli; 10 May 2013, 04:11.

    #2
    See Tree DataBinding overview and note discussion of isFolder.

    Comment


      #3
      Thanks for answer.
      I had altready read the Tree DataBinding section, but probably I've "simplified" too much the meanings of paragraph.

      After some attempts, I solved with these modifications.

      My .ds.xml become:
      Code:
      <DataSource ID="kioskGroup" schemaBean="it.onetech.dtproviding.server.entity.KioskGroup">
      	<fields>
      		<field name="parentId" type="integer" rootValue="0" foreignKey="id" />
      		<field name="isFolder" type="boolean"hidden="true" required="true" />
      	</fields>
      	<serverObject lookupStyle="spring" bean="kioskGroupDao" />
      </DataSource>
      and Hibernate related Entity:
      Code:
      @Entity
      @Table(name = "kiosk_group")
      @NamedQueries({
      		@NamedQuery(name = "KioskGroup.fetchAll", query = "from KioskGroup order by name"),
      		@NamedQuery(name = "KioskGroup.fetchByParentId", query = "from KioskGroup where parentId = :parentId order by name")
      })
      public class KioskGroup implements Serializable {
      
      	private static final long serialVersionUID = 705115081184951769L;
      
      	@Id
      	@SequenceGenerator(name = "idSeq", sequenceName = "kiosk_group_id_seq")
      	@GeneratedValue(generator = "idSeq")
      	@Column(name = "id")
      	protected Long id = null;
      
      	@Column(name = "name")
      	protected String name = null;
      
      	@Column(name = "parent_id")
      	protected Long parentId = null;
      
      	@Transient
      	protected Boolean isFolder = null;
      
              //** getters() ans setters() */
      Into my latest attempts I was setting only the @Transient attributes on Entity (to avoid unused database bind), thinking that DataSource mappings was done automatically (as other fields).

      In the matter of fact, this was my main mistake.

      Thansk, Luca.

      Comment

      Working...
      X