i disagree: onChange is a user listener method, therefore it means on
user change.
programmatic alteration does not count.

make a new listener and extend textbox to make it listenable.


/** Calls onContentChange whenever the text changes */
public class ChangeTextBox extends TextBox {

        private static final int CHANGE_EVENTS =
                Event.KEYEVENTS | Event.ONCHANGE | Event.ONCLICK | 
Event.ONDBLCLICK;

        private ContentChangeListenerCollection contentChangeListeners;

        private String content = "";

        public void checkContent(){
                String text = getText();
                if(contentChangeListeners != null && !content.equals(text))
                        contentChangeListeners.fireContentChange(this);
                content = text;
        }
        public void onBrowserEvent(Event evt){
                if((evt.getTypeInt() & CHANGE_EVENTS) != 0)
                        checkContent();
                super.onBrowserEvent(evt);
        }
        public void setText(String text){
                checkContent();
                super.setText(text);
        }

        public void addContentChangeListener(ContentChangeListener listener){
                if (contentChangeListeners == null)
                        contentChangeListeners = new 
ContentChangeListenerCollection();
                contentChangeListeners.add(listener);
        }

        public void removeContentChangeListener(ContentChangeListener
listener){
                if (contentChangeListeners != null)
                        contentChangeListeners.remove(listener);
        }
}


On Aug 30, 10:54 pm, Marcelo Emanoel <[EMAIL PROTECTED]> wrote:
> I agree... a change is still a change doesn't matter from where it
> came :) The currently implementation uses the browser event to fire
> the change... but it can be easily done overriding the setText()
> method... but then I got a new problem... every time  that a new
> component based on the original one is built I have a new problem...
> and have to extend the new class to use the correct behavior... and
> even more... I have to explicitly tell the user to use my new
> component... like instead of creating a TextBox with "new TextBox()"
> you'll have to create with "new XXTextBox()" on any component....
>
> On Aug 30, 10:51 am, al0 <[EMAIL PROTECTED]> wrote:
>
> > It was made difficult of ... false purpose. Change is change -
> > regardless of its origins. Otherwise you mix unrelated concepts-.
>
> > On Aug 29, 3:44 pm, walden <[EMAIL PROTECTED]> wrote:
>
> > > It's been made difficult...on purpose.  Change events are user
> > > gestures.  If you want to notify listeners on your TextBoxes of an
> > > event you define, then extend TextBox and implement the Observer
> > > Pattern for your custom event.  Don't pollute the meaning of
> > > "onChange".
>
> > > Walden
>
> > > On Aug 29, 9:14 am, Marcelo Emanoel <[EMAIL PROTECTED]> wrote:
>
> > > > Is it possible?
>
> > > > On 29 ago, 09:43, Marcelo Emanoel <[EMAIL PROTECTED]> wrote:
>
> > > > > What I was looking for was something to fire the listeners without
> > > > > knowing them... just like happens when I press a key on the TextBox
> > > > > that is already on the screen...
>
> > > > > On 29 ago, 09:37, Marcelo Emanoel <[EMAIL PROTECTED]> wrote:
>
> > > > > > I already know of the changeListeners and so on... but that's wasn't
> > > > > > what I'm looking for.... :(
>
> > > > > > But I've manage another way to do what I need :)
>
> > > > > > Thanks Anyway
>
> > > > > > On 29 ago, 08:53, "Ian Bambury" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > ChangeListener listener = new ChangeListener()
> > > > > > > {
> > > > > > >     public void onChange(Widget sender)
> > > > > > >     {
> > > > > > >     }};
>
> > > > > > > TextBox t = new TextBox();
> > > > > > > t.addChangeListener(listener);
> > > > > > > t.setText("blah blah blah");
> > > > > > > listener.onChange(t);
>
> > > > > > > 2008/8/29 Marcelo Emanoel <[EMAIL PROTECTED]>
>
> > > > > > > > Hi guys I was wondering if anyone knows how to fire up an event 
> > > > > > > > on a
> > > > > > > > widget like TextBox or ListBox for example...
>
> > > > > > > > If I do
>
> > > > > > > > <code>
> > > > > > > >      TextBox t = new TextBox();
> > > > > > > >      t.addChangeListener(new ChangeListener(){
> > > > > > > >            //implement a listener for changing...
> > > > > > > >      });
>
> > > > > > > >     t.setText("blah blah blah");
> > > > > > > > </code>
>
> > > > > > > > the listener won't be called :'(
> > > > > > > > Is there a way to fire up the listener throw code?
>
> > > > > > > > Thanks in Advance :)
>
> > > > > > > --
> > > > > > > Ian
>
> > > > > > >http://examples.roughian.com-Hidequotedtext -
>
> > > > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to