[squeak-dev] Re: Maui questions

Chris Muller asqueaker at gmail.com
Wed Jan 9 00:12:37 UTC 2013


Hi, thanks for the great feedback!

> I've got a set of classes that represent the messages of a network protocol which can be serialized and sent
> over a socket, stored in byte arrays, etc. Essentially, the fields of the messages are stored in instance vars,
> and there are getter/setter accessors for each.

Wow, just fyi, that is _exactly_ what Ma-Client-Server does.  :)
Sounds like you have a very similar need and solution.

       http://wiki.squeak.org/squeak/2978

> I'm trying to build a Maui interface to allow me to select an arbitrary one of the messages (classes), fill in its
> values, then pick it up and drop it onto a Maui morph wrapping a socket connection, and thus send the
> message.
> I can explicitly (manually) create a MauiMorph for a specific message (instance of a class) in my protocol,
> drop the accessor selectors, and make them be getter/setters. I can fill in the fields of such a message and
> drop it onto the socket-wrapping MauiMorph. The message gets sent properly. I wish to build a more generic
> MauiMorph that allows me to select which message of the network protocol (class) to build, then have the
> accessors for that particular class automatically render in a panel, ready for filling in. I'm trying to avoid
> manually creating views for each of the message types.

No problem, in fact there is already a nearly identical example of
doing that with MauiColorSchemMorph.  It adds a getter/setter for each
method in a particular category.  Make a copy of that class which also
inherits from MauiDomainMorph.  It has just two short methods!  Please
examine these to see how its done.

Lo and behold, the code there even sets up pickers for each of the
getter/setter messages!   :)   Obviously we are really thinking alike!

It's up to you but I typically I call my specialized MDM subclasses,
Maui[DomainClassName]Morph, so, in your case perhaps it would be,
MauiNetworkMessageMorph.

Once you have your new subclass, there is one final step.  You have to
tell Maui to USE that subclass for instances of your NetworkMessage
domain class.  Here's how that's done:

  MauiRegistry global
      register: MauiNetworkMessageMorph
      forAny: NetworkMessage

A good place to do that is in the class-side #initialize method for
MauiNetworkMessageMorph.

Now, creating a subclass of MauiDomainMorph will create a dependency
on Maui for your app.  What I typically do to manage that is simply
make a "-Maui" version of the package which can be optionally loaded.

> I tried to implement a 'picker' on a parameter holder but I can't figure out how to do it. Of course I can get an
> array of all the existing message subclasses and I can get that to render as a MauiCollectionMorph, but I
> can't see how to make this list be the choices of the picker. (I tried 'maui this morph' on the
> MauiCollectionMorph). I'm after functionality similar to the way the selectStrategy: parameter holder (in the
> MauiMessage settings panel) pops up a list of strategy classes and allows the user to select one of them.
> Also, I need to know how to populate the set of accessors particular to the selected message's fields.

The only limitation to pickers is that they should not contain domain
objects -- otherwise the Maui panels cannot be saved "purely" (e.g.,
without any domain classes).  So rather than actual classes, you
should have class names (Symbols) in your pick-list.

You already know how to make pickers work via code by the
MauiColorScheme example above.  To do it graphically, I hope you won't
mind if I first try to refer you to page 40 of the Maui User Guide
under the heading "Specifying an Object "Picker".  The guide is here:

   http://wiki.squeak.org/squeak/uploads/3836/Maui1.1r1.pdf

> Another approach I tried (and couldn't make work) is to override the default behavior when a class is picked up from a browser and dropped onto the desktop. Instead of creating a MauiMorph on that class, I wished to create a MauiMorph on an instance of the class with all accessor MauiMessageMorphs already built. I tried overriding the 'maui' method on the class side, in which I send 'maui' to a new instance, programmatically add the accessors with 'addMessageNamed:' and return the result. Overriding 'maui' didn't work … is there an easy way to do this? (A side question: how can I programmatically add a method and have it be a getter/setter?).

I think I answered this above, please let me know if I missed something.


More information about the Squeak-dev mailing list