View typeconverter:

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

View typeconverter:

Mark Wilden
I'm trying to set a presenter's typeconverter in code, rather than in VC[1].
The trouble is that the presenter/model is read-only, yet setting its view's
typeconverter sends value: back to the model.

XProjectShell>>createComponents
 super createComponents.
 storiesDurationToday := self add: TimePresenter new name:
'storiesDurationToday'.

XProjectShell>>model: aProject
 super model: aProject.
 storiesDurationToday model: (self model aspectValue:
#storiesDurationToday).

XProjectShell>>somewhere??
storiesDurationToday view typeconverter: XProjectDurationToText new
showZero.

The trouble is that if "somewhere" is after model:, then
View>>typeconverter: will update the model, and the value doesn't have a
setter (it's read-only). If "somewhere" is before model:, then usually the
presenter's view is just DeafObject.

I could add a dummy setter in the model. Or I could create the typeconverter
in VC and set showZeros there. But what I'd prefer is to set the
typeconverter in code without sending a change back to the model.

Does that make any sense? :)

[1]. You can't refactor objects--only classes.


Reply | Threaded
Open this post in threaded view
|

Re: View typeconverter:

Christopher J. Demers
"Mark Wilden" <[hidden email]> wrote in message
news:[hidden email]...
> I'm trying to set a presenter's typeconverter in code, rather than in
VC[1].
> The trouble is that the presenter/model is read-only, yet setting its
view's
> typeconverter sends value: back to the model.
...
> The trouble is that if "somewhere" is after model:, then
> View>>typeconverter: will update the model, and the value doesn't have a
> setter (it's read-only). If "somewhere" is before model:, then usually the
> presenter's view is just DeafObject.

I wonder if typeconverter: should perhaps be overridden in
StaticViewAbstract so that it uses displayValue: rather than value:?

There are two tricks you could use to force the system to work the way you
want it to.  Neither looks elegant to me, and both seem to be fighting the
current.  In my example I am using the size of an array to simulate your
situation.  See bellow.

"Create and set model."
te := TextEdit show.
te model: (#() aspectValue: #size).

"1st Way"
tmp := te model.
te model: nil.
te typeconverter: NumberToText new.
te model: tmp.

"2nd Way (this could be expanded to check the actual message to avoid
handling an unanticipated error)"
[te typeconverter: NumberToText new] on: MessageNotUnderstood do: [:err | ].

Chris


Reply | Threaded
Open this post in threaded view
|

Re: View typeconverter:

Mark Wilden
"Christopher J. Demers" <[hidden email]> wrote in
message news:b87enm$76e9m$[hidden email]...
>
> "1st Way"
> tmp := te model.
> te model: nil.
> te typeconverter: NumberToText new.
> te model: tmp.

Thought of that, but #model: might be complicated, so I don't want to call
it more times than necessary.

> "2nd Way (this could be expanded to check the actual message to avoid
> handling an unanticipated error)"
> [te typeconverter: NumberToText new] on: MessageNotUnderstood do: [:err
| ].

That's what I want. It's so obvious when you know what you're doing...:)

Thanks, Chris!


Reply | Threaded
Open this post in threaded view
|

Re: View typeconverter:

Mark Wilden
In reply to this post by Christopher J. Demers
"Christopher J. Demers" <[hidden email]> wrote in
message news:b87enm$76e9m$[hidden email]...
>
> "1st Way"
> tmp := te model.
> te model: nil.
> te typeconverter: NumberToText new.
> te model: tmp.

Actually, I take back what I said--I was thinking of setting the whole model
to nil. Just setting the textedit's model to nil seems like it would be
fine.