Griffon
  1. Griffon
  2. GRIFFON-396

Views should be able to identify the top node and expose to other MVC members

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.3-beta-2
    • Fix Version/s: 0.9.4
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Most of the times a View script defines a single node. This node is set as the return value of the script, which is useful for composing secondary Views by calling the build() method on the primary View.

      However, there may be times where the "root" node is not the last expression evaluated in the script (due to additional configuration like bindings or setting up listeners for example). In this case the developer must set a reference to the top node and make an explicit return at the end of the script.

      It would be better if Views were capable of identifying the root node by convention, so that View composition would be DRYer.

      Proposal:

      Add a root() method to AbstractGriffonView and AbstractGriffonViewScript with three variants:

      • root(JComponent c) - identifies the passed in argument as the root node, will compute an unique identifier based on the script's and component's classes
      • root(String id, JComponent c) - identifies the passed in argument as the root node using a developer supplied id
      • root() - returns the root component as set with either of the two previous methods.

      This a secondary View script may look like the following one

      root(panel {
          gridLayout(cols: 2, rows: 1)
          label 'Foo'
          textField columns: 20
      })
      
      noparent {
          label text: bind{model.value}
      }
      

      which can be reused in a primary View like this

      widget(build(MyContent).root())
      

      where MyContent.root() returns the panel built in the secondary View instead of a List (noparent creates a List for those who didn't know the trick

        Activity

        Hide
        Dierk König added a comment -

        I'd give it more than one vote if I could

        Show
        Dierk König added a comment - I'd give it more than one vote if I could
        Hide
        Andres Almiray added a comment -

        Secondary view script (assuming class name is Secondary)

        root(
            l = label('fooooooooo')
        )
        
        noparent {
            l.text = 'FOOOOOO !!!'
        }
        

        Primary view script

        build(Secondary)
        ...
        widget root(Secondary)
        
        Show
        Andres Almiray added a comment - Secondary view script (assuming class name is Secondary) root( l = label('fooooooooo') ) noparent { l.text = 'FOOOOOO !!!' } Primary view script build(Secondary) ... widget root(Secondary)

          People

          • Assignee:
            Andres Almiray
            Reporter:
            Andres Almiray
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: