Announcement

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

    TreeGrid: How to make Integer column properly?

    I assumed this is accomplished by DataSourceIntegerField + treeNode.setAttribute("myColumnName", 15)...
    But when I set up _first_ column this way I get error message saying that TreeNode title is number. (When I move that column to 2nd position in grid everything is OK.)

    #2
    See setTreeField() for determining which field shows the tree structure.

    Comment


      #3
      Well, thank you, but I guess I am still missing something...

      Is there some particular place/moment where one should mark field as 'titleField'? (I mean like BEFORE or AFTER a DataSource is being assigned...?)
      Because neither treeGrid.setTitleField("name") nor dataSource.setTitleField("name") do seem to help.

      Also documentation says...
      for DataSource.getTitleField:
      If not explicitly set, titleField looks for fields named "title", "label", "name", and "id" in that order. If a field exists with one of those names, it becomes the titleField. If not, then the first field is designated as the titleField.
      ...which indicates that I shouldn't have to set the titleField at all, as I do have a field named "name" in my DataSource (and therefore in the TreeGrid). Yet still the ?underlying Tree? tries to get the title from my first field/column, which happens to be Integer, which leads to an error.

      Just to be sure...
      Code:
      new DataSourceTitleField("fullName", "Full name")
      ...here the "fullName" is the field-name, isnt' it?

      Ofcourse I will keep trying, I guess I'm doing something wrong. :(

      Comment


        #4
        Also, regardless of whether I am setting the titleField properly or not, getting an error for having first column of perfectly legal data-type is just wrong, IMHO.

        There is nothing that should make developer suspicious about how he builds his TreeGrid, nothing fundamentally wrong about setting first column to Integer.
        I believe underlying classes/components should handle this, because they choose how to build/determine the title, they should expect there might be an Integer, so they should take care of it.

        Best regards
        Jarda

        Comment


          #5
          Try posting actual, complete code. Most likely, you've got a usage error.

          Comment


            #6
            Originally posted by Isomorphic
            Try posting actual, complete code. Most likely, you've got a usage error.
            Probably yes. I will try to isolate the issue. Usually it pops-out during that process.

            Comment


              #7
              I haven't got to it yet, but I have just read in another post from you it is not recommended to use DataSource with TreeGrid directly, so I guess I will rather use the approach you recommended...

              Comment


                #8
                That post is very very old and no longer true (and you have furthermore misread it). TreeGrids should absolutely be used with DataSources. TreeGrids and their data model, the ResultTree, automatically update whenever update, add and remove operations complete on their DataSource, regardless of what component or programmatic action triggered the request.

                Comment


                  #9
                  As for misreading, TBH I haven't read the whole post. As I got to the Tree I pushed that aside and bookmarking that post for later with note to myself "ur doin it wrong".
                  (B/c it kinda works with the column being a text-type I'm trying to make some progress elsewhere.)
                  Also I haven't noticed the post is 2yrs old ...deleting the bookmark.
                  Last edited by jzaruba; 18 Oct 2009, 14:50.

                  Comment


                    #10
                    Here is the test-case...

                    Code:
                    public void onModuleLoad()
                    	{
                    		DataSource employeeDS = EmployeeXmlDS.getInstance();
                    
                    		final TreeGrid treeGrid = new TreeGrid();
                    		treeGrid.setLoadDataOnDemand(false);
                    		treeGrid.setDataSource(employeeDS);
                    		treeGrid.setAutoFetchData(true);
                    
                    		TreeGridField employeeField = new TreeGridField();
                    		employeeField.setName("EmployeeId");
                    
                    		TreeGridField nameField = new TreeGridField();
                    		nameField.setName("Name");
                    
                    		treeGrid.setFields(employeeField, nameField);
                    		// does not seem to have anny effect on the error
                    		treeGrid.setTitleField("Name");
                    
                    		treeGrid.addDataArrivedHandler(new DataArrivedHandler()
                    			{
                    				public void onDataArrived(DataArrivedEvent event)
                    				{
                    					treeGrid.getData().openAll();
                    				}
                    			});
                    
                    		treeGrid.draw();
                    	}
                    I have used EmployeeXmlDS.java from the Showcase. The onModuleLoad is also taken from that source, it has been 'minimized' and little bit modified though. Most importantly I have put the EmployeeId in the first position, so that the tree-structure defaults right into this very Integer-field/column. (That's exactly where I intended to have it: one column for id:int, another one for name:string. Therefore I did not use the setTreeField method you hinted.)
                    Also the setTitleField method I mentioned before does not help; probably because it has completely different purpose...?

                    1) Overriding TreeGrid.getNodeTitle is actually a way to avoid the cast/retype error with Integer-fields. I still believe the original method should handle Integer fields though.

                    the error:
                    Code:
                    Uncaught JavaScript exception [java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method '@com.smartgwt.client.widgets.tree.TreeGrid::getNodeTitle(Lcom/smartgwt/client/data/Record;ILcom/smartgwt/client/widgets/grid/ListGridField;)': Cannot convert to type java.lang.Object from number
                    	at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:132)
                    	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:233)
                    	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
                    	at com.smartgwt.client.widgets.tree.TreeGrid.getNodeTitle(TreeGrid.java)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    	at java.lang.reflect.Method.invoke(Method.java:597)
                    	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                    	at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
                    	at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
                    	at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
                    	at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
                    	at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
                    	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
                    	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
                    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
                    	at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:264)
                    	at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:557)
                    	at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
                    	at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)] in http://localhost:8080/caesar/hosted.html?caesar, line 8
                    TreeGrid.getNodeTitle overriden:
                    Code:
                    @Override
                    protected String getNodeTitle(Record node, int recordNum, ListGridField field)
                    {
                    	// quite nasty solution, checking field type for Integer 
                    	// would be probably more proper way
                    	try
                    	{
                    		// here's where the error gets thrown
                    		return super.getNodeTitle(node, recordNum, field);
                    	}
                    	catch (Exception e)
                    	{
                    		return node.getAttribute(field.getName());
                    	}
                    }
                    2) Tree-structure within Integer-field (when rendered eventually) does not work properly - the folder handlers don't respond. It seems the reason is the alignment to the right. To open a branch (with single click) you need to click in the spot where the tree would reside had there be the default alignment, which is way off their handler-icons.

                    None of your exmeples in the Showcase uses Integer-field for the tree-structure, unless I missed some. Which makes me wonder whether no one ever tried to make that work...?

                    Comment


                      #11
                      Could you explain what you're trying to do? Are you trying to make actual numbers appear as node titles? Isn't that the worst possible UI?

                      What is displayed for the tree field and the way the tree is structurally formed and two independent concepts. eg employee name is shown as a node title and id/reportsTo numeric fields dictate the tree structure.

                      Comment


                        #12
                        Originally posted by Isomorphic
                        Could you explain what you're trying to do? Are you trying to make actual numbers appear as node titles? Isn't that the worst possible UI?
                        Why do you think so? I am displaying some generic db-records, they don't even have to bear anything you could call name or title. In such cases displaying the primary key in the tree-field is the most natural and transparent choice, IMHO. Because this is the field that defines the tree.
                        The id-column in my case is very important for the person using/viewing the grid.

                        Honestly, it just seems odd that having first column of one particular (and perfectly legal) data-type causes error in such trivial operation as generating title out of int.

                        Originally posted by Isomorphic
                        What is displayed for the tree field and the way the tree is structurally formed and two independent concepts. eg employee name is shown as a node title and id/reportsTo numeric fields dictate the tree structure.
                        Yes, I am aware of that.
                        Last edited by jzaruba; 28 Oct 2009, 14:37.

                        Comment

                        Working...
                        X