MVP: ComboBox with Editable Value...

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

MVP: ComboBox with Editable Value...

Christopher J. Demers
Does someone know the right way using MVP to handle an editable combo box
such that it's aspect gets updated if text is entered in the text portion?
It seems to work for selections, but not text that is entered.  I am using
the ChoicePresenter, is there a more appropriate presenter to use?  If not I
guess I should build one.

I have read Louis's thread (Date: 2000-12-15 03:47:25 PST, Subject:
#onKeyPressed:)  about a related ComboBox issue.  I am thinking that I may
have to use the method that was added (#editView)  as a result of that
thread in order to make it work the way I want.  It looks like there may be
some kinks to work around.

Any ideas?

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Louis Sumberg
Chris,

The approach to implementing an editable combo box in part six of the
personal money extended tutorial might be the ticket.  I do remember that
experience, including trying to use the #editView method, as being very
interesting but very frustrating as well.  Not that I want to dissuade you
from building a presenter that does it right *s*, but if the code in the
tutorial does what you want to do, it might save you a bunch of hours.

... Louis

"Christopher J. Demers" <[hidden email]> wrote in
message news:9cvhnu$g2ke2$[hidden email]...
> Does someone know the right way using MVP to handle an editable combo box
> such that it's aspect gets updated if text is entered in the text portion?
> It seems to work for selections, but not text that is entered.  I am using
> the ChoicePresenter, is there a more appropriate presenter to use?  If not
I
> guess I should build one.
>
> I have read Louis's thread (Date: 2000-12-15 03:47:25 PST, Subject:
> #onKeyPressed:)  about a related ComboBox issue.  I am thinking that I may
> have to use the method that was added (#editView)  as a result of that
> thread in order to make it work the way I want.  It looks like there may
be
> some kinks to work around.
>
> Any ideas?
>
> Chris
>
>


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Ian Bartholomew
In reply to this post by Christopher J. Demers
Chris,

> Does someone know the right way using MVP to handle an editable combo box
> such that it's aspect gets updated if text is entered in the text portion?
[..]
> Any ideas?

It's a bit kludgy [1] but you might try positioning a TextEdit on top of the
text part of the ComboBox so that it obscures the entry field but leaves the
drop down button and list portion visible. You would then have to use two
presenters, a TextPresenter for the TextEdit and a ListPresenter for the
partially hidden ComboBox, and do the updating between the widgets yourself.

I haven't actually tried this you understand (!) but it might be an easy way
of making a pseudo ComboBox that behaves in exactly the way you want.

Ian

[1] I'm thinking of using this as my middle name, I seem to be using it a
lot lately <g>


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Christopher J. Demers
In reply to this post by Louis Sumberg
Louis Sumberg <[hidden email]> wrote in message
news:9cvs17$fogfg$[hidden email]...
> The approach to implementing an editable combo box in part six of the
> personal money extended tutorial might be the ticket.  I do remember that
> experience, including trying to use the #editView method, as being very
> interesting but very frustrating as well.  Not that I want to dissuade you
> from building a presenter that does it right *s*, but if the code in the
> tutorial does what you want to do, it might save you a bunch of hours.

Thank you for mentioning this, I had not seen part 6.  I am very impressed
by what you have done with the combo box.  I think some of these events you
have added should find their way into the official Dolphin image as they
could be most useful.  You were right about the problems with using
editView.  I think I found a way to make an improved presenter for a
ComboBox without adding to system methods.  I will post my code soon, it is
one class with three methods.

Let me also take this opportunity to thank you for your wonderful Personal
Money tutorial extensions.  You have taken the rather simple Personal Money
tutorial and turned it into a much more comprehensive tutorial that looks
more like a real application.  I have referred to it a number of times when
I was trying to do things "the right MVP way".  Excellent work!
(For those who do not have the URL:
http://www.sirius.com/~lsumberg/PersonalMoney/ )

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Christopher J. Demers
In reply to this post by Ian Bartholomew
Ian Bartholomew <[hidden email]> wrote in message
news:C5QI6.33559$[hidden email]...
> Chris,
>
> > Does someone know the right way using MVP to handle an editable combo
box
> > such that it's aspect gets updated if text is entered in the text
portion?
> [..]
> > Any ideas?
>
> It's a bit kludgy [1] but you might try positioning a TextEdit on top of
the
> text part of the ComboBox so that it obscures the entry field but leaves
the
> drop down button and list portion visible. You would then have to use two
> presenters, a TextPresenter for the TextEdit and a ListPresenter for the
> partially hidden ComboBox, and do the updating between the widgets
yourself.
...

That is an interesting idea, it would probably avoid the problems with the
editView method.  Actually I think I have a solution, its one class with
three methods.  I will post the code shortly.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Christopher J. Demers
In reply to this post by Christopher J. Demers
I have a working ChoiceTextPresenter (Is this a good name?).  It is one
class with three methods, it sublcasses ChoicePresenter.  I will past it
bellow, but you can also download the class file from my site here
http://www.mitchellscientific.com/smalltalk/ .

Feedback is welcome and appreciated.

Chris
===========Start=========
"Filed out from Dolphin Smalltalk 2000 release 4.01"!

ChoicePresenter subclass: #ChoiceTextPresenter
 instanceVariableNames: ''
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
ChoiceTextPresenter comment: 'CJD 5-7-2001 This Presenter will support
ComboBoxes that can have text values that do not
 exist in their list part.'!

ChoiceTextPresenter guid: (GUID fromString:
'{9D59FAFB-A585-440D-9C92-9F9703A8CA39}')!

!ChoiceTextPresenter categoriesForClass!Unclassified! !
!ChoiceTextPresenter methodsFor!

createSchematicWiring

 "CJD 5-7-2001 Add the focusLost event, this is not a great event to use,
  but I did not see anything better that was available in the base system."

 super createSchematicWiring.
 self when: #focusLost send: #updateFromEditView to: self.
!

updateChoice
 "Private - The value has been changed in the receiver's model.
 Transfer the value to the list view's selection.
 CJD 5-7-2001  Modified to avoid trying to select text if it is not in the
list ."

 | val |

 val := self value.
 (val notNil and: [self view list includes: val]) ifFalse: [^nil].
 ^super updateChoice. !

updateFromEditView

 "CJD 5-7-2001  Update the value based on the text value."

 self value: self view text.
 ! !
!ChoiceTextPresenter categoriesFor:
#createSchematicWiring!*-unclassified!public! !
!ChoiceTextPresenter categoriesFor: #updateChoice!*-unclassified!private! !
!ChoiceTextPresenter categoriesFor:
#updateFromEditView!*-unclassified!public! !
===========Stop=========


Reply | Threaded
Open this post in threaded view
|

Re: ComboBox with Editable Value...

Louis Sumberg
In reply to this post by Christopher J. Demers
Chris,

If I could blush, I'd be blushing at your kind words.  I'm glad you've found
the tutorials helpful.

I took a quick look at your ChoiceTextPresenter, plugged it into
PersonalMoney for instance, and it seems to work fine.  Very clever work,
especially the override of updateChoice!

In my last post I made reference to part six of the tutorial, but actually
it's part 5 where I made the combobox editable, using 2 methods very similar
to what you came up.  Part six was where I added all that stuff that lets
you type a key and it finds a matching entry.

Bottom line is that with all this effort, and after all this time, we
finally have a combobox that does pretty much what we'd like it to do.  All
for one and one for all!

Louis

"Christopher J. Demers" <[hidden email]> wrote in
message news:9d779i$ggrfr$[hidden email]...
> Louis Sumberg <[hidden email]> wrote in message
> news:9cvs17$fogfg$[hidden email]...
> > The approach to implementing an editable combo box in part six of the
> > personal money extended tutorial might be the ticket.  I do remember
that
> > experience, including trying to use the #editView method, as being very
> > interesting but very frustrating as well.  Not that I want to dissuade
you
> > from building a presenter that does it right *s*, but if the code in the
> > tutorial does what you want to do, it might save you a bunch of hours.
>
> Thank you for mentioning this, I had not seen part 6.  I am very impressed
> by what you have done with the combo box.  I think some of these events
you
> have added should find their way into the official Dolphin image as they
> could be most useful.  You were right about the problems with using
> editView.  I think I found a way to make an improved presenter for a
> ComboBox without adding to system methods.  I will post my code soon, it
is
> one class with three methods.
>
> Let me also take this opportunity to thank you for your wonderful Personal
> Money tutorial extensions.  You have taken the rather simple Personal
Money
> tutorial and turned it into a much more comprehensive tutorial that looks
> more like a real application.  I have referred to it a number of times
when
> I was trying to do things "the right MVP way".  Excellent work!
> (For those who do not have the URL:
> http://www.sirius.com/~lsumberg/PersonalMoney/ )
>
> Chris
>
>