callback between classes

Discussion in 'Java' started by a, Nov 12, 2010.

  1. a

    a Guest

    Hi

    I have 2 classes. The CatContainer extends the HorizontalPanel. The
    CatContainer should be updated when the CatWidget receives updated data from
    database by GWT RPC.
    How can I implement the update of the CatContainer?

    Thanks

    class CatContainer extends HorizontalPanel{
    private CatWidget catWidget=new CatWidget(1);
    //how can I implement the following to update the GUI?
    catWidget.refresh( new CallBackFunc()
    {
    onSuccess()
    {
    //Update GUI
    }
    }

    }

    class CatWidget{
    private data;

    void refresh()
    {
    //Call GWT async to retrieve data from database, and update the data.
    }

    }
     
    a, Nov 12, 2010
    #1
    1. Advertising

  2. a

    Stefan Ram Guest

    "a" <> writes:
    >//how can I implement the following to update the GUI?


    Assuming the Views are registered as listeners in the model
    and the property change support from »java.beans« is used,
    the model can update the views - for example - as in:

    this.listeners.firePropertyChange
    ( new java.beans.PropertyChangeEvent
    ( this, "example", example0, example1 ));

    . (Assuming

    javax.swing.event.SwingPropertyChangeSupport listeners;

    .)
     
    Stefan Ram, Nov 12, 2010
    #2
    1. Advertising

  3. a

    Lew Guest

    a wrote:
    > I have 2 classes. The CatContainer extends the HorizontalPanel. The
    > CatContainer should be updated when the CatWidget receives updated data
    > from database by GWT RPC.
    > How can I implement the update of the CatContainer?
    >
    > Thanks
    >
    > class CatContainer extends HorizontalPanel{
    > private CatWidget catWidget=new CatWidget(1);
    > //how can I implement the following to update the GUI?
    > catWidget.refresh( new CallBackFunc()
    > {
    > onSuccess()
    > {
    > //Update GUI
    > }
    > }
    >
    > }
    >
    > class CatWidget{
    > private data;
    >
    > void refresh()
    > {
    > //Call GWT async to retrieve data from database, and update the data.
    > }
    >
    > }


    Read up on Model-View-Controller (MVS) and listeners.

    In outline, have the data for the screen represented in an in-memory structure
    - the model. When an input alters the data, pass the new data to the model.
    When the model changes, have it fire an event to the controller to update the
    view. The controller calls the asynchronous view method. The view queries
    the model (makes lookup calls) and fills its widgets with the answers.

    --
    Lew
     
    Lew, Nov 12, 2010
    #3
  4. a

    markspace Guest

    On 11/12/2010 3:44 AM, a wrote:
    > Hi
    >
    > I have 2 classes. The CatContainer extends the HorizontalPanel. The
    > CatContainer should be updated when the CatWidget receives updated data
    > from
    > database by GWT RPC.
    > How can I implement the update of the CatContainer?



    As mentioned, MVC will help you out here. The idea is to introduce a
    third object, the controller, which knows about both objects and can
    bind them at run time.

    public class InitializationController {

    public void init() {
    CatContainer model = new CatContainer();
    CatWidget view = new CatWidget();
    model.addChangeListener( view );
    ...
    }
    }



    > class CatContainer extends HorizontalPanel{
    > private CatWidget catWidget=new CatWidget(1);


    private ModelObserver view;

    public void addChangeListener( ModelObserver obs ) {
    view = obs;
    }

    > //how can I implement the following to update the GUI?
    > catWidget.refresh( new CallBackFunc()
    > {

    final CatContainer localModel = CatContainer.this;
    > onSuccess()
    > {
    > //Update GUI

    if( localModel.view != null) {
    localModel.view.refresh();
    }
    > }
    > }
    >
    > }
    >
    > class CatWidget

    implements ModelObserver
    {
    > private data;
    >
    > void refresh()
    > {
    > //Call GWT async to retrieve data from database, and update the data.
    > }
    >
    > }


    public interface ModelObserver {
    void refersh();
    }


    Nothing here was compiled, double check my syntax.

    I don't like the comment you have in "CatWidget". The view should not
    know about any database. It should have a simple interface for a model
    and that's it. Update the model from the database, then inform the view
    that the model has changed. However, I'll leave design issues like that
    one to you.
     
    markspace, Nov 12, 2010
    #4
  5. a

    a Guest

    "markspace" <> ¦b¶l¥ó
    news:ibjrpt$ri0$-september.org ¤¤¼¶¼g...
    > On 11/12/2010 3:44 AM, a wrote:
    >> Hi
    >>
    >> I have 2 classes. The CatContainer extends the HorizontalPanel. The
    >> CatContainer should be updated when the CatWidget receives updated data
    >> from
    >> database by GWT RPC.
    >> How can I implement the update of the CatContainer?

    >
    >
    > As mentioned, MVC will help you out here. The idea is to introduce a
    > third object, the controller, which knows about both objects and can
    > bind them at run time.
    >
    > public class InitializationController {
    >
    > public void init() {
    > CatContainer model = new CatContainer();
    > CatWidget view = new CatWidget();
    > model.addChangeListener( view );
    > ...
    > }
    > }
    >
    >
    >
    >> class CatContainer extends HorizontalPanel{
    >> private CatWidget catWidget=new CatWidget(1);

    >
    > private ModelObserver view;
    >
    > public void addChangeListener( ModelObserver obs ) {
    > view = obs;
    > }
    >
    >> //how can I implement the following to update the GUI?
    >> catWidget.refresh( new CallBackFunc()
    >> {

    > final CatContainer localModel = CatContainer.this;
    >> onSuccess()
    >> {
    >> //Update GUI

    > if( localModel.view != null) {
    > localModel.view.refresh();
    > }
    >> }
    >> }
    >>
    >> }
    >>
    >> class CatWidget

    > implements ModelObserver
    > {
    >> private data;
    >>
    >> void refresh()
    >> {
    >> //Call GWT async to retrieve data from database, and update the data.
    >> }
    >>
    >> }

    >
    > public interface ModelObserver {
    > void refersh();
    > }
    >
    >
    > Nothing here was compiled, double check my syntax.
    >
    > I don't like the comment you have in "CatWidget". The view should not
    > know about any database. It should have a simple interface for a model
    > and that's it. Update the model from the database, then inform the view
    > that the model has changed. However, I'll leave design issues like that
    > one to you.
    >



    Hi

    Besides MVC, any other solution?
    It is an event escalation question.
    I dont mind to retrieve data base from view at this moment.

    Thanks a lot






















    >
    >
     
    a, Nov 14, 2010
    #5
  6. a

    Roedy Green Guest

    Roedy Green, Nov 15, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,004
    David
    Jul 22, 2005
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,286
    VisionSet
    Nov 13, 2003
  3. Razvan
    Replies:
    5
    Views:
    11,365
    Dale King
    Jul 27, 2004
  4. Johannes Röckert
    Replies:
    5
    Views:
    499
    Johannes Röckert
    Sep 30, 2006
  5. Trevoke
    Replies:
    10
    Views:
    213
    Brian Candler
    Jul 22, 2009
Loading...

Share This Page