How to build a Magritte form

When a class defines methods with the pragma magritteDescription as exemplified in How to define a Magritte form field, the message Object>>#asGtMagritteViewModel asGtMagritteViewModel ^ GtMagritteViewModel forObject: self will produce a view model that can then be converted into a BlElement Object subclass: #BlElement uses: TBlTransformable + TBlEventTarget + TBlDebug instanceVariableNames: 'spaceReference parent children bounds measuredBounds boundsCache eventDispatcher constraints layout transformation taskQueue errorHandler userData visuals flags' classVariableNames: '' package: 'Bloc-Core' using GtMagritteViewModel>>#asElement asElement | aFrame | aFrame := BrFrame new. aFrame hFitContentLimited; vFitContent; constraintsDo: [ :c | c frame horizontal alignCenter. c frame vertical alignCenter ]; withAsyncFutureDo: [ :anElementFuture | anElementFuture whenPending: [ :theContainer | theContainer addChild: (BrLabel new fitContent; aptitude: (BrGlamorousLabelAptitude new foreground: BrGlamorousColors disabledButtonTextColor); text: 'Preparing...'; constraintsDo: [ :c | c frame horizontal alignCenter. c frame vertical alignCenter ]) ]; whenError: [ :theContainer :anError | theContainer userData at: self class gtMementoSymbol put: anError. theContainer removeChildren; addChild: (anError asDebuggableElement hFitContentLimited; vFitContent; constraintsDo: [ :c | c frame horizontal alignCenter. c frame vertical alignCenter ]) ]; whenSuccess: [ :theFrame :aMemento | self initializeForm: theFrame forMemento: aMemento ] ]. aFrame asyncFuture executionConfiguration: GtMagritteBuilderUtility executionConfiguration. aFrame asyncFuture future: self mementoFuture. ^ aFrame .

Let’s use this example once again on GtClassCreationForm GtBehaviorCreationForm subclass: #GtClassCreationForm instanceVariableNames: 'superclassName classVars pools' classVariableNames: '' package: 'GToolkit-Pharo-Coder-UI-Forms - Models' .

Putting all that we’ve learned so far together, a form for adding a class can be produced through calling:

GtClassCreationForm new asGtMagritteViewModel asElement
  

This can be used within elements and stencils to cohabitate models and their respective UIs.