Announcement

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

    treeNode cast problem

    Hello,

    I use GWT 2.2 and SGWT 2.4.

    I have a custom TreeGrid (PatientTree), a custom DataSource (ClinicalDS) and a custom TreeNode (CliniCalNode).
    I want to load on datasource children of a node when I open parent node/folder. Everything is ok on the first level of nodes. I open the parent, children are loaded !
    But when I want to open newly created children, a cast exception occurs:

    Code:
    java.lang.ClassCastException: com.smartgwt.client.widgets.tree.[B]TreeNode
    cannot be cast to[/B]
    org.ub.le2i.[B]ClinicalNode
    [/B]
    Here are my classes :

    Code:
    class [B]PatientTree [/B] extends TreeGrid{
    
        ClinicalDS ds;
    
        public [B]PatientTree[/B](){
            ds = new ClinicalDS();
            ds.initialize();
            this.setDataSource(ds);
        
             [B]addFolderOpenedHandler[/B](new FolderOpenedHandler() {
                public void onFolderOpened(FolderOpenedEvent event) {
                   
                   ClinicalNode node = (ClinicalNode) event.getNode();           // CAST EXCEPTION
                    ds.[B]addChildren[/B](node);
                }
            });
        }
    }
    Code:
    class [B]ClinicalDS[/B] extends DataSource{
        public void [B]initialize[/B](){
      
            // load patients from database : List<Patient>  patients;
            for (Patient patient : patients){
                [B]ClinicalNode [/B]child = new [B]ClinicalNode[/B](patient);
                addData(child);
            }
        }
    
        public void [B]addChildren[/B](ClinicalNode parent){
      
            // load samples from database : List<Sample>  samples;
            for (Sample sample: samples){
                [B]ClinicalNode [/B]child = new [B]ClinicalNode[/B](sample);
                child.setParent(parent);
                addData(child);
            }
        }
    
    }
    Code:
    class [B]ClinicalNode[/B] extends TreeNode{
    
        private Object object;
    
        public ClinicalNode([B]Patient [/B]patient){
            // setAttributes, etc.
    
            object = patient;    // this is why I need a custom TreeNode
        }
    
        public ClinicalNode([B]Sample [/B]sample){
            // setAttributes, etc.
    
            object = sample;
        }
    
    }
    some screenshots :
    - 1.png => first level loaded by ds.initialize() => OK
    - 2.png => second level loaded by ds.addchild() => OK
    - 3.png => I log the toString() of the node => first line : click on Patient1 OK, second line click on Prel1 KO

    thanks ;)

    Pierre
    Attached Files
    Last edited by Psidoler; 20 May 2011, 04:39.

    #2
    I check the child object type during the "addChildren" and during the "openFolder" with a sout
    Code:
    node.getAttribute("objectName")+":"+node.toString()
    "Prel1" object during the addChildren :
    Code:
    [B]Prel1[/B]:org.ub.le2i.[B]ClinicalNode[/B]@2a170174
    "Prel1" object during the openFolder:
    Code:
    [B]Prel1[/B]:com.smartgwt.client.widgets.tree.[B]TreeNode[/B]@585d78f8
    As you can see, the type and the object IDs are not the same... It's smells like if the ClinicalNode a been copy to a new TreeNode object during the "on the fly" loading.
    Last edited by Psidoler; 20 May 2011, 04:36.

    Comment


      #3
      Last precison, my problems occurs in Dev-Mode AND in "normal" mode. on FF 3.6, FF 4, IE 8, IE 9, Chrome 11.0

      Comment


        #4
        any updates or another way to have the nedded behaviour ?

        Comment


          #5
          Hello,

          I have find the problem. It's come from RPC calls. When I try to load children during the RPC callback, my nodes have the bad type. When I try a fake load without RPC it's OK.

          Here is the addChildren from RPC:

          Code:
              public void addChildren(ClinicalNode parent){
          
                  // RPC CALL (load samples from database)
             [B]SampleServiceAsync service = SampleService.Util.getInstance();
                  service.getSamples[/B](parent.getAttribute("objectName"), new AsyncCallback<List<Sample>>() {
          
                      public void onFailure(Throwable caught) {}
          
                      public void [B]onSuccess[/B](List<Sample> result) {
          
                          for (Sample sample: result){
                              ClinicalNode child = new ClinicalNode(sample);
                              child.setParent(parent);
                              addData(child);
                          }
                      }
              }
          Here is the fake (but working) addChildren without RPC:

          Code:
              public void addChildren(ClinicalNode parent){
          
                  Sample fakeSample1 = new Sample();
                  fakeSample1.setName("fakeSample1");
                  // etc.
                  Sample fakeSample2 = new Sample();
                  fakeSample2.setName("fakeSample2");
                  // etc.
               
                  List<Sample>  samples = new ArrayList<Sample>();
                  samples.add(fakeSample1);
                  samples.add(fakeSample2);
          
                  for (Sample sample: samples){
                      ClinicalNode child = new ClinicalNode(sample);
                      child.setParent(parent);
                      addData(child);
              }
          How can I bypass this problem ?

          Comment

          Working...
          X