callback between classes

A

a

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.
}

}
 
S

Stefan Ram

a said:
//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;

.)
 
L

Lew

a said:
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.
 
M

markspace

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.
 
A

a

markspace said:
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 );
...
}
}




private ModelObserver view;

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

final CatContainer localModel = CatContainer.this;
if( localModel.view != null) {
localModel.view.refresh();
}
implements ModelObserver
{

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top