Announcement

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

    Parent Canvas casting question (getting from ListGrid to parent SectionStackSection)

    Hi Isomorphic,

    for a long time I passed parents of a Widget down in the constructor like this
    Code:
    new MyListGrid(...., MyWhateverClass parent){}
    With this I can access the parent from my ListGrid-Subclass and call methods there. But of course this inheritance chain somehow defies reusability and is just not nice.
    But you have Canvas.getParentCanvas() that helps here, so that I don't need to pass the parent down, which is great.

    The only problem is what do I do with it in SmartGWT in case of SectionStack or more specifically SectionStackSection?

    Code:
    SectionStackSection mySection = (SectionStackSection)this.getParentCanvas()
    gives me an Cannot cast from Canvas to SectionStackSection-error.

    This seems correct, as Canvas is not a Superclass of SectionStackSection. But how do I get to the section from it's items? With another .getParentCanvas() I can get to SectionStack, which is a Subclass of Canvas, but not the SectionStackSection.

    I'm sure this will be pretty easy in the end, but right now I don't see how.

    Thank you & Best regards
    Blama

    #2
    It's unclear what you want to do here, but SectionStackSection is not a Canvas - it's a configuration object passed to SectionStack, and SectionStack creates a SectionHeader widget from it.

    The correct way to manipulate a section, such as changing its title or expand/collapsing it programmatically, is via APIs on SectionStack. Directly manipulating the SectionHeader widget would be invalid in most cases (e.g. hide()ing it would be invalid).

    If you need to know which section your widget is in, two approaches:

    1. pass the sectionId into the widget's constructor

    2. iterate over all the SectionStackSections checking the items array until you find your widget

    Comment


      #3
      Hi Isomorphic,

      Your suggested way 1. is basically what I'm doing currently, but I don't think this is nice design.
      Your suggested way 2. I thought about, but assumed there must be a nicer way of doing this.

      My usecase is that I have Buttons (Filter, Reload, Export) affecting the ListGrid in SectionStackSection.controls. The ListGrid in question is in SectionStackSection.items.
      This is basically what you do in the customToolbars sample, but in a different UI above and outside the ListGrid.

      So far the buttons just worked onClick. But now the filter button should be stateful (I have stored ViewStates, a self built version of 13.0p savingPreferences) and Button.selected should mirror ListGrid.showFilterEditor.

      If I go down your route 2, I could get to the SectionStack with myListGrid.getParentCanvas().getParentCanvas(). But then I'm stuck as in the Developer Console Watch Tab I can see that the items under section stack are not in any particular order. And getting them and sorting them by getY() to the to the item before is most likely not the way to go. Is there another way of more directly finding the SectionStackSection.controls of a Canvas in SectionStackSection.items?

      Thank you & Best regards
      Blama

      Comment


        #4
        SectionStack is a subclass of Layout, and if you access its contents via the inherited Layout.getMembers() API, they will be in the visual order.

        Note that if you are in a component that was part of section.items, the SectionStack is your immediate parentCanvas. The sections do not represent another layer of containment.

        As far as how best to handle this, we would think of the ListGrid and its controlling buttons as one logical component, even though they appear under different containers. So rather than navigate around the containment hierarchy, we would add a method on the ListGrid that returns a toolStrip that you use in as section.controls, and the ListGrid can return that toolStrip with two-way references already established.

        Comment


          #5
          Hi Isomorphic,

          thanks for the hint on the Layout.getMembers() order.

          Also thanks for the idea of handling the ListGrid and its controlling buttons as one logical component. I think this is what I'll do.

          Best regards
          Blama

          Comment

          Working...
          X