Default depending on container

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

Default depending on container

Sean P. DeNigris
Administrator
I have a described object, let's call it parent. It has a to-many relation. The reference may be an instance of multiple classes, but all have a date field, which I want to default to the date of the parent object. How do I do that?

Thanks!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Default depending on container

John McKeon
MAChainAccessor?


On Sun, Oct 6, 2013 at 10:18 PM, Sean P. DeNigris <[hidden email]> wrote:
I have a described object, let's call it parent. It has a to-many relation.
The reference may be an instance of multiple classes, but all have a date
field, which I want to default to the date of the parent object. How do I do
that?

Thanks!



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Default-depending-on-container-tp4712877.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



--
jmck.seasidehosting.st

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

Re: Default depending on container

Cameron Sanders
Just stepping back I have a question below. First let me say, please don't take offense if the question is too basic. I grapple all the time with the question of "is the model logic?", or "is it application specific logic?"
--

Remember that Magritte descriptions help define default dialogs/editors for *one* imagined application using the object, but there is no way  you will define one set of Magritte descriptions for all applications of instances of your class. [At least for highly reusable model components.]

Even with "one" imagined solution, Magritte helps you put an interface on the object, but much of your interaction with the object may be through other code that does not stop to ask the MagritteDescription how to do something. 

So my first question is: Is this a presentation problem/question or a model integrity problem/issue?

Why not define a method to get the #effectiveDate or whatever method. You said "to many" relationship, so which date should be displayed if there are 5 associated objects and they all have different dates? This sounds like some logic that belongs outside of the magritte description.
-
I quickly gave up trying to be "minimal" with Magritte descriptions. They are very handy and powerful. So I just clone them to create new ones that serve my needs... and move on. 

-Cam


On Mon, Oct 7, 2013 at 4:20 PM, John McKeon <[hidden email]> wrote:
MAChainAccessor?


On Sun, Oct 6, 2013 at 10:18 PM, Sean P. DeNigris <[hidden email]> wrote:
I have a described object, let's call it parent. It has a to-many relation.
The reference may be an instance of multiple classes, but all have a date
field, which I want to default to the date of the parent object. How do I do
that?

Thanks!



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Default-depending-on-container-tp4712877.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



--
jmck.seasidehosting.st

_______________________________________________
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
|

Re: Default depending on container

Sean P. DeNigris
Administrator
Thanks for the detailed response!

Cameron Sanders wrote
Is this a presentation problem/question or a model
integrity problem/issue?
It's a model integrity issue. In my model parent objects hold a collection of objects of mixed types that all have a date field which should be set to the same value as parent's date, so e.g.:

aParent
  - date: 1/1/2013
  - toMany: {
    - anObject
      - date: 1/1/2013
    - anInstanceOfADifferentClass (polymorphic wtr date access)
      - date: 1/1/2013 }
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Default depending on container

Cameron Sanders
Sean,

Perhaps I am misunderstanding and solving a different problem.. but it sounds like... **if** all of these instances actually store the date...

Seems to me the Parent instance #date methods should be accessed using simple method accessors of a Magritte Date description. The tricky part of model integrity should be logic of the instances of Parent and not dependent on the Magritte description -- with myriad good reasons to make exceptions. e.g. "I just need to meet the deadline or else i am fired!"

The tricky part, can be solved by either having the parent always push data down (with direct wiring) or registering self as a dependent, or the children as dependents; or the other major option is that of having the children pull it on demand (e.g. ifNil: [ date := parent date]).

-
You probably want simple methods for your parent object that push the date to children.
e.g. define something like...

#updateChildrenStates
    self children do: [:child | child date: self date. ... ]

Whether you use #changed/#update/dependency-management or announcements, or "direct wiring" with this approach is up to you.

If using #changed you would do something like this (as well as register self as a dependent):

Parent >>date: aDate
    date := aDate asDate.
    self changed: #date.

and Parent >> 
#update: aSymbol
    self updateChildrenStates

*if* the child is registered as a dependent but has no handle to the parent, implement:
Parent >>
update: aSymbol with: anObject
    aSymbol == #date ifTrue: [ self date: anObject date ].

-
Or, if using "direct wiring"
Parent >> date: aDate
    date := aDate asDate.
    self updateChildrenStates. "or more specifically self updateChildrenDates"

--
If on the other hand, the children are pulling, then they need a handle on the parent to query lazily. 
 
Good luck!
Cam


On Tue, Oct 8, 2013 at 6:51 PM, Sean P. DeNigris <[hidden email]> wrote:
Thanks for the detailed response!


Cameron Sanders wrote
> Is this a presentation problem/question or a model
> integrity problem/issue?

It's a model integrity issue. In my model parent objects hold a collection
of objects of mixed types that all have a date field which should be set to
the same value as parent's date, so e.g.:

aParent
  - date: 1/1/2013
  - toMany: {
    - anObject
      - date: 1/1/2013
    - anInstanceOfADifferentClass (polymorphic wtr date access)
      - date: 1/1/2013 }



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Default-depending-on-container-tp4712877p4713331.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
|

Re: Default depending on container

Sean P. DeNigris
Administrator
Cameron Sanders wrote
Perhaps I am misunderstanding and solving a different problem..
I think so :p The problem I'm having is: when I open a Magritte editor on aParent, I get a button "Add" to add a new object to the toMany collection. This opens up a Magritte editor on a new instance of whatever class was selected from #classes:. My problem is that I don't know how to link this new instance up to parent. There doesn't seem to be a hook to partially initialize toMany objects...
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Default depending on container

DiegoLont
Hi Sean,

I think I understand your problem. You need to create your custom ToManyComponent and override the "add" message. The basic implementation is:

add
        self root
                show: (self validatedFormOn: self selected new)
                onAnswer: [ :result |
                        result isNil
                                ifFalse: [ self value: (self value copyWith: result); refresh ] ]

The "self selected new" you want to change into something you want. Perhaps it would be nicer if this is replaced by a hook, having the default implementation of add:

add
        self root
                show: (self validatedFormOn: self newInstance)
                onAnswer: [ :result |
                        result isNil
                                ifFalse: [ self value: (self value copyWith: result); refresh ] ]

newInstance
        ^self selected new

And then override the newInstance. But in all cases you need a custom ToManyComponent that makes sure it creates the correct instance.

Cheers,
Diego

On Oct 9, 2013, at 2:04 PM, Sean P. DeNigris wrote:

> Cameron Sanders wrote
>> Perhaps I am misunderstanding and solving a different problem..
>
> I think so :p The problem I'm having is: when I open a Magritte editor on
> aParent, I get a button "Add" to add a new object to the toMany collection.
> This opens up a Magritte editor on a new instance of whatever class was
> selected from #classes:. My problem is that I don't know how to link this
> new instance up to parent. There doesn't seem to be a hook to partially
> initialize toMany objects...
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Default-depending-on-container-tp4712877p4713437.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
|

Re: Default depending on container

Sean P. DeNigris
Administrator
Ah yes. Thank you. Of course that's exactly where I should've looked! Still sometimes forget that I can dig into any part of a Smalltalk system and find answers for myself ;)


-------- Original message --------
From: "DiegoLont [via Smalltalk]" <[hidden email]>
Date: 10/09/2013 10:35 AM (GMT-05:00)
To: "Sean P. DeNigris" <[hidden email]>
Subject: Re: Default depending on container


Hi Sean,

I think I understand your problem. You need to create your custom ToManyComponent and override the "add" message. The basic implementation is:

add
        self root
                show: (self validatedFormOn: self selected new)
                onAnswer: [ :result |
                        result isNil
                                ifFalse: [ self value: (self value copyWith: result); refresh ] ]

The "self selected new" you want to change into something you want. Perhaps it would be nicer if this is replaced by a hook, having the default implementation of add:

add
        self root
                show: (self validatedFormOn: self newInstance)
                onAnswer: [ :result |
                        result isNil
                                ifFalse: [ self value: (self value copyWith: result); refresh ] ]

newInstance
        ^self selected new

And then override the newInstance. But in all cases you need a custom ToManyComponent that makes sure it creates the correct instance.

Cheers,
Diego

On Oct 9, 2013, at 2:04 PM, Sean P. DeNigris wrote:

> Cameron Sanders wrote
>> Perhaps I am misunderstanding and solving a different problem..
>
> I think so :p The problem I'm having is: when I open a Magritte editor on
> aParent, I get a button "Add" to add a new object to the toMany collection.
> This opens up a Magritte editor on a new instance of whatever class was
> selected from #classes:. My problem is that I don't know how to link this
> new instance up to parent. There doesn't seem to be a hook to partially
> initialize toMany objects...
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Default-depending-on-container-tp4712877p4713437.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/Default-depending-on-container-tp4712877p4713449.html
To unsubscribe from Default depending on container, click here.
NAML
Cheers,
Sean