Initialisation of componentClass

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Initialisation of componentClass

Iwan Vosloo
Hi there,

We have an issue related to magritte-seaside.

When you set the Component to be used on a MADescription, eg:

descriptionThings
   ^ MAToManyRelationDescription new
          ...
          componentClass: MyFancyTableComponent;
          yourself

.. then there is no way (that I am aware of) to initialize the created
MyFancyTableComponent in a customised way.

In the example above, for instance one may have a MyFancyTableComponent
that divides its items into several pages (like an MAReport would do).
The number of items displayed per page has to be hard-coded in
MyFancyTableComponent. It would be nice to have a way to initialize a
newly created instance, something like:

descriptionThings
   ^ MAToManyRelationDescription new
          ...
          componentClass: MyFancyTableComponent;
          initializeComponent: [ :newlyCreatedComponent|
newlyCreatedComponent itemsPerPage: 40 ];
          yourself

There are, of course, several ways one could do this. I am not
necessarily suggesting the above example as the way to do it... I am
just illustrating the point.

If you do not have such a mechanism, the only thing you can do is
subclass MyFancyTableComponent with the express motivation - to be able
to set a new instance up a certain way. We have a log of code that does
this sort of subclassing. It makes things go really messy eventually.
We'd like to get rid of all those subclasses and rather let the user of
a component 'configure' it appropriately.

Building something like what I am proposing means changes to
magritte-seaside code though. So, if we do it we'd prefer to contribute
upstream.

Has anyone else come across this issue? Any ideas? Worthwhile to others too?

Regards
- Iwan

--
Reahl, the Python only web framework: http://www.reahl.org

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Initialisation of componentClass

JupiterJones
There are a lot of ways of achieving this, but if you’re after a simple solution, you can use the:

MAObject-#propertyAt:put:

eg.
^ MAToManyRelationDescription new
        ...
        componentClass: MyFancyTableComponent;
        propertyAt: #fancyItemsPerPage put: 10;
        yourself

Then within MyFancyTableComponent instances you can check for the for the property in the description with:

MAObject-hasProperty: #fancyItemsPerPage
or
MAObject-#propertyAt: #fancyItemsPerPage

As you suggest, you could also subclass MAToManyRelationDescription and implement the behaviour you want. You can then override MADescription-C-#defaultComponentClasses to automatically use your MyFancyTableComponent... but yes, this does add more classes and apparent complexity - however, it’s all quite neat and everything is in it’s place :)

Is this what you were after?

J

> On 16 May 2016, at 8:09 PM, Iwan Vosloo <[hidden email]> wrote:
>
> Hi there,
>
> We have an issue related to magritte-seaside.
>
> When you set the Component to be used on a MADescription, eg:
>
> descriptionThings
>  ^ MAToManyRelationDescription new
>         ...
>         componentClass: MyFancyTableComponent;
>         yourself
>
> .. then there is no way (that I am aware of) to initialize the created MyFancyTableComponent in a customised way.
>
> In the example above, for instance one may have a MyFancyTableComponent that divides its items into several pages (like an MAReport would do). The number of items displayed per page has to be hard-coded in MyFancyTableComponent. It would be nice to have a way to initialize a newly created instance, something like:
>
> descriptionThings
>  ^ MAToManyRelationDescription new
>         ...
>         componentClass: MyFancyTableComponent;
>         initializeComponent: [ :newlyCreatedComponent| newlyCreatedComponent itemsPerPage: 40 ];
>         yourself
>
> There are, of course, several ways one could do this. I am not necessarily suggesting the above example as the way to do it... I am just illustrating the point.
>
> If you do not have such a mechanism, the only thing you can do is subclass MyFancyTableComponent with the express motivation - to be able to set a new instance up a certain way. We have a log of code that does this sort of subclassing. It makes things go really messy eventually. We'd like to get rid of all those subclasses and rather let the user of a component 'configure' it appropriately.
>
> Building something like what I am proposing means changes to magritte-seaside code though. So, if we do it we'd prefer to contribute upstream.
>
> Has anyone else come across this issue? Any ideas? Worthwhile to others too?
>
> Regards
> - Iwan
>
> --
> Reahl, the Python only web framework: http://www.reahl.org
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Initialisation of componentClass

Iwan Vosloo
Hi Jupiter,

On 16/05/2016 13:19, Jupiter Jones wrote:
> eg.
> ^ MAToManyRelationDescription new
>          ...
>          componentClass: MyFancyTableComponent;
> propertyAt: #fancyItemsPerPage put: 10;
>          yourself
>
> Then within MyFancyTableComponent instances you can check for the for the property in the description with:

Thanks! Of course. I never thought of that.

Is this sort of usage the intent of having properties on a MADescription?

I must say, there is something wholesome if you can actually call a
setter: it makes the relationship between the component and the property
explicit; it shows up as a sender etc. (But I'd much rather conform to
how people will generally do it than try to be otherwise!)

Regards
- Iwan



--
Reahl, the Python only web framework: http://www.reahl.org

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Initialisation of componentClass

Mariano Martinez Peck
In reply to this post by JupiterJones
Hi Iwan,

Just for the record, I also workaround this with Jupiter way.

Cheers,


On Mon, May 16, 2016 at 8:19 AM, Jupiter Jones <[hidden email]> wrote:
There are a lot of ways of achieving this, but if you’re after a simple solution, you can use the:

MAObject-#propertyAt:put:

eg.
^ MAToManyRelationDescription new
        ...
        componentClass: MyFancyTableComponent;
        propertyAt: #fancyItemsPerPage put: 10;
        yourself

Then within MyFancyTableComponent instances you can check for the for the property in the description with:

MAObject-hasProperty: #fancyItemsPerPage
or
MAObject-#propertyAt: #fancyItemsPerPage

As you suggest, you could also subclass MAToManyRelationDescription and implement the behaviour you want. You can then override MADescription-C-#defaultComponentClasses to automatically use your MyFancyTableComponent... but yes, this does add more classes and apparent complexity - however, it’s all quite neat and everything is in it’s place :)

Is this what you were after?

J

> On 16 May 2016, at 8:09 PM, Iwan Vosloo <[hidden email]> wrote:
>
> Hi there,
>
> We have an issue related to magritte-seaside.
>
> When you set the Component to be used on a MADescription, eg:
>
> descriptionThings
>  ^ MAToManyRelationDescription new
>         ...
>         componentClass: MyFancyTableComponent;
>         yourself
>
> .. then there is no way (that I am aware of) to initialize the created MyFancyTableComponent in a customised way.
>
> In the example above, for instance one may have a MyFancyTableComponent that divides its items into several pages (like an MAReport would do). The number of items displayed per page has to be hard-coded in MyFancyTableComponent. It would be nice to have a way to initialize a newly created instance, something like:
>
> descriptionThings
>  ^ MAToManyRelationDescription new
>         ...
>         componentClass: MyFancyTableComponent;
>         initializeComponent: [ :newlyCreatedComponent| newlyCreatedComponent itemsPerPage: 40 ];
>         yourself
>
> There are, of course, several ways one could do this. I am not necessarily suggesting the above example as the way to do it... I am just illustrating the point.
>
> If you do not have such a mechanism, the only thing you can do is subclass MyFancyTableComponent with the express motivation - to be able to set a new instance up a certain way. We have a log of code that does this sort of subclassing. It makes things go really messy eventually. We'd like to get rid of all those subclasses and rather let the user of a component 'configure' it appropriately.
>
> Building something like what I am proposing means changes to magritte-seaside code though. So, if we do it we'd prefer to contribute upstream.
>
> Has anyone else come across this issue? Any ideas? Worthwhile to others too?
>
> Regards
> - Iwan
>
> --
> Reahl, the Python only web framework: http://www.reahl.org
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



--

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Initialisation of componentClass

Iwan Vosloo
Hi Mariano,

On 16/05/2016 14:09, Mariano Martinez Peck wrote:
> Just for the record, I also workaround this with Jupiter way.

Thanks, yes we will also follow suit.

Regards
- Iwan


--
Reahl, the Python only web framework: http://www.reahl.org

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Initialisation of componentClass

Stephan Eggermont-3
In reply to this post by Iwan Vosloo
On 16-05-16 12:09, Iwan Vosloo wrote:

> Hi there,
>
> We have an issue related to magritte-seaside.
>
> When you set the Component to be used on a MADescription, eg:
>
> descriptionThings
>   ^ MAToManyRelationDescription new
>          ...
>          componentClass: MyFancyTableComponent;
>          yourself
>
> .. then there is no way (that I am aware of) to initialize the created
> MyFancyTableComponent in a customised way.
>
There are several ways to do this, and Magritte provides the building blocks
to choose the one reducing duplication most. In QCMagritte, we chain the
visitors building the form to do e.g. translations and access control.
In Magritte 'style' you'd want to prefer a declarative style with properties
over coupling the description strongly to the component.

Important for your choice in how to do this is also the question of
reuse. If you need it once, your first solution, or just a subclass is fine.
In a UI that adapts to screen size, you might want to avoid direct numbers
and use properties like large, wide, small to direct the layout

Stephan

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside