Quantcast

Visitors Underused?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Visitors Underused?

Sean P. DeNigris
Administrator
Should or could the MADescriptionMorph hierarchy use/inherit-fro MAVisitor?

"Magritte Meta-Described Web Application Development" says "Custom Rendering... Sometimes other layouts are more convenient, for example the widgets should be laid out from left to right with the labels on top... Magritte allows one to define one’s own builder by subclassing a Visitor and overriding some of the methods used to place the user interface elements".

With the current implementation, it seems one would have to hack the MADescriptionMorph classes themselves for that kind of change, but if a visitor was used, they could just supply a custom visitor class, no?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Visitors Underused?

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
Should or could the MADescriptionMorph hierarchy use/inherit-fro MAVisitor?
I gave it a shot and think it worked out pretty well. A few methods and an instVar removed from MAContainerMorph, in exchange two methods for a pluggable visitor. The visitor(s) themselves are two MAVisitor subclasses with 1 API method each, and one instVar with accessors.

Magritte-Morph-SeanDeNigris.89
[FEATURE]: MADescriptionMorphs use visitor pattern to allow customization

Simple Use Case: layout labels above field widgets instead of to the left
1. Subclass MAMorphicContainerVisitor, overriding #visitDescription:
2. Subclass MAContainerMorph, overriding #visitorClass supplying #1
3. In your domain class, override #descriptionContainer to send #morphClass: iwith #2

Details:
- New MAMorphicVisitor build morphs for each of a MADescriptionMorph's fields and add them to its morph
- Now you can easily override the building of different field types by subclassing MAMorphicVisitor
- MAContainerMorph
        - remove all #children related logic, as that work is now delegated to the visitor
        - custom visitor can be specified by overriding #visitorClass
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Visitors Underused?

Stephan Eggermont
In reply to this post by Sean P. DeNigris
Could you compare this what we did with description builders in QCMagritte?

QCObject>>magritteDescription
     |basicDescription builders|
     basicDescription := self basicMagritteDescription.
     builders := self magritteDescriptionBuilders.
     builders ifNotNil: [^builders buildFrom: basicDescription target:
self].
     ^basicDescription

QCContainerComponent>>magritteDescription
     ^magritteDescription ifNil: [
         | model builder |
         builder := description descriptionBuilder.
         builder ifNil: [ ^description].
         model := self model.
         magritteDescription := builder buildFrom: description target:
model model: self model model.
         self setMemento: (model mementoClass model: model description:
magritteDescription).
         magritteDescription ]

Stephan

On 26/03/15 14:25, Sean P. DeNigris wrote:

> Should or could the MADescriptionMorph hierarchy use/inherit-fro MAVisitor?
>
> "Magritte Meta-Described Web Application Development" says "Custom
> Rendering... Sometimes other layouts are more convenient, for example the
> widgets should be laid out from left to right with the labels on top...
> Magritte allows one to define one’s own builder by subclassing a Visitor and
> overriding some of the methods used to place the user interface elements".
>
> With the current implementation, it seems one would have to hack the
> MADescriptionMorph classes themselves for that kind of change, but if a
> visitor was used, they could just supply a custom visitor class, no?
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Visitors-Underused-tp4815294.html
> Sent from the Magritte, Pier and Related Tools mailing list archive at Nabble.com.
>
> _______________________________________________
> Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Visitors Underused?

Sean P. DeNigris
Administrator
Sure, I'm not yet sold on what I did. I feel like there's something I'm missing but don't know yet what it is.

One thing is that it seems like MADescriptionMorph and friends should themselves be the visitors, but currently they inherit from Model (I wonder if they have to).

Also, the visitor pattern should be able to handle both Seaside and Morphic, where right now these are handled totally separately.

OTOH, I went back to Design Patterns, which says that Visitor is appropriate when the set of operated-on classes is stable, but here anyone that wants to have a custom rendered view (i.e. MyPianoMorph instead of a checkbox) would have to hunt around adding #visitPianoDescription: methods to all the builders.

On Mar 28, 2015, at 5:17 AM, Stephan Eggermont [via Smalltalk] <[hidden email]> wrote:

Could you compare this what we did with description builders in QCMagritte?

QCObject>>magritteDescription
     |basicDescription builders|
     basicDescription := self basicMagritteDescription.
     builders := self magritteDescriptionBuilders.
     builders ifNotNil: [^builders buildFrom: basicDescription target:
self].
     ^basicDescription

QCContainerComponent>>magritteDescription
     ^magritteDescription ifNil: [
         | model builder |
         builder := description descriptionBuilder.
         builder ifNil: [ ^description].
         model := self model.
         magritteDescription := builder buildFrom: description target:
model model: self model model.
         self setMemento: (model mementoClass model: model description:
magritteDescription).
         magritteDescription ]

Stephan

On 26/03/15 14:25, Sean P. DeNigris wrote:

> Should or could the MADescriptionMorph hierarchy use/inherit-fro MAVisitor?
>
> "Magritte Meta-Described Web Application Development" says "Custom
> Rendering... Sometimes other layouts are more convenient, for example the
> widgets should be laid out from left to right with the labels on top...
> Magritte allows one to define one’s own builder by subclassing a Visitor and
> overriding some of the methods used to place the user interface elements".
>
> With the current implementation, it seems one would have to hack the
> MADescriptionMorph classes themselves for that kind of change, but if a
> visitor was used, they could just supply a custom visitor class, no?
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Visitors-Underused-tp4815294.html
> Sent from the Magritte, Pier and Related Tools mailing list archive at Nabble.com.
>
> _______________________________________________
> Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


If you reply to this email, your message will be added to the discussion below:
http://forum.world.st/Visitors-Underused-tp4815294p4815727.html
To unsubscribe from Visitors Underused?, click here.
NAML

Cheers,
Sean
Loading...