Announcement

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

    How to use SmartGWT DataSource with heterogenous data

    I want to use SmartGWT's TreeGrid object to show hierarchical data. The data is heterogeneous, not all elements are of the same type and have the same fields. For example, I have the following data:
    Code:
    Home
     |-Room 1
     |-Room 2
        |-Table
        |-Chair
    All objects have unique IDs. Home has no fields. Rooms have just a name. Table has a name and an int field "seatsNumberOfPeople" which the Chair has not. Chair has a field "Color" taken from a list of possible values which the table has not.

    When an object in the TreeGrid is selected, I want to show a DetailViewer which lets the user edit the fields of that object. Obviously, the DetailViewer will have different fields and validations for each type of node.

    How should the DataSource be designed to meet these requirements? What's the best practice to create such dynamic DetailViewer from that heterogeneous data?

    Unfortunately, all examples on the web show data which is homogeneous (same fields for all objects in the Tree).

    #2
    I have a related question... how to deal with heterogeneous data in a list grid... that is, if I select a row in one grid I want to show details in a second grid. The rows in the first grid represent different object types with different fields.

    for example:

    List Grid:

    Row 1 Widget
    Row 2 Gadget


    Details Grid (select Row 1, Widget)

    Name A B C
    Widget detail 1 A1 (text) B1 (int) C1 (Date)
    Widget detail 2 A2 (text) B2 (int) C2 (Date)
    ...


    Details Grid (select Row 2, Gadget)

    Name D E
    Gadget Detail 1 D1 (text) E1 (Date)
    Gadget Detail 2 D2 (text) E2 (Date)

    So, the contents of the details grid would depend on the object type chosen from the upper grid. The underlying data model could be something like:

    Name, textField1, textField2, ... , intField1, intField2, ..., dateField1, dateField2, ...

    Then the Details Grid would always use this datasource but have a different mapping which could be set dynamically, like setFields(). I couldn't get this to work... only if you set the Fields:[] statically on the definition, but not dynamically.

    Is there a way to do this?
    .....

    Comment


      #3
      Both ListGrid and Treenode are extensions of com.smartgwt.client.core.DataClass.

      Therefore, you should be able to use get/setAttributexxx to retrieve/store values of disparate types.

      For hierarchical structure, you should be able to use TreeNode. TreeNode is used either in
      parent-linked mode: SmartSample/#tree_databinding_parentlinking,
      or child-linked mode: SmartSample/#tree_databinding_children_arrays

      Study Showcase.java, which together with SideNavTree.java, ExplorerTreeNode.java and ShowcaseData.java to form the backbone of the Showcase samples.

      In the ExplorerTreeNode.java, an object is retrieved/stored using get/setAttributeAsObject, where the object is a PanelFactory. PanelFactory interface is somewhat devised to produce the corresponding sample on the rhs of the page.

      Instead of PanelFactory, you could have your own class called ItemContainer, for example. You could store the object as an attribute directly, and then you would have to test the type of the object to decide what to do with it.

      However, how to store objects of disparate types has less to do with SmartGWT than being familiar with the restrictions of GWT. GWT does not allow an object to be stored as a general Object class, for optimisation reasons. You need to draw on your personal expertise and strategies on GWT on how to treat general objects without being stored as Object class.

      Since the general type of object must have specific type that conforms to GWT's requirement for source-code availability and Serializable, you could design that object to implement an interface of ItemContainer or ItemFactory, with an action method

      Code:
      interface ItemContainer<Whatever>{
        Whatever whatToDo();
      }
      Observe PanelFactory interface.
      Code:
      public interface PanelFactory {
        Canvas create();
        String getID();
        String getDescription();
      }
      Note that Canvas is a specific base type to which you could assign general extended types of Canvas. Similarly, you need to design your general objects with a strategy that satisfies GWT's restriction.

      Comment


        #4
        I too have a TreeGrid with heterogenous values. Items in the value column could be string, date, SSN, person name, street address, selection, etc. I build a Tree on the client side, and I don't use a DataSource. Some of the leaves in this tree are up to 16 deep, and the tree is several thousands wide.

        I would like to use a FormItem to update the value of a TreeNode, and I would like to place the FormItem/DynamicForm onto the TreeGrid cell that has been selected.

        Is there a way to get the Canvas of the selected tree cell so that a DynamicForm can be placed on that Canvas?

        Thanks

        Comment


          #5
          kitschen, did you find any answer to your question?
          I'm in the same situation.

          Thanks!

          Comment

          Working...
          X