Activities does not get de-registered..

2011-06-30 Thread El bassistos
I am doing a small test application and I am using Activities and
Place but can't make it work as I expect..

I have 2 Views, Activities and Places. DefaultView calls Example1View
and Vice Versa ..

In the Example1Activity I override mayStop() so that it returns a
String asking if user wants to go to Default. It works the first
time - when I hit go to Default, it ask if I am sure, and then I
press  'OK'  - that works, it swaps out the Example1View/Activity and
swap in the DefaultView/Activity.

But when I hit the go to Example1 from the DefaultView/Activity, it
ALSO ask the question. I can see in the Debugger that first the
DefaultActivity is called, and that it behaves as expected (the
mayStop() returns null), but the ExampleView's mayStop() method is
ALSO called?? Even though it is no in focus - it is about to come
in Focus .. So it seems as the previous Example1Activity is NOT
deregistered on the EventBus, after I hit the OK (which calles the
onClose() method and should cause the ActivityManager to de-registere
the Activity..)

Any Ideas ???

Rehgards Jesper - Running GWT 2.2.1 and it is same behavior on FF,
Chrome and Safari


Here is my code:

DefaultPlace.java:
public class DefaultPlace extends Place {}

DefaultView.java:
public class DefaultView extends Composite implements IsWidget{
HorizontalPanel hp = new HorizontalPanel();
Button b = new Button(Go To Example1);

public DefaultView() {
hp.add(b);
initWidget(hp);

}

HasClickHandlers getButton() {
return b;
}
}

DefaultActivity.java
public class DefaultActivity extends AbstractActivity implements
Activity {

ClientFactory clientFactory;
DefaultView defaultView;

public DefaultActivity(DefaultPlace place, ClientFactory
clientFactory) {
this.clientFactory = clientFactory;
}

public void start(AcceptsOneWidget panel, EventBus eventBus) {
defaultView = clientFactory.getDefaultView();
defaultView.getButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
clientFactory.getPlaceController().goTo(new
Example1Place());
}
});
panel.setWidget(defaultView.asWidget());
}
}

Example1Place.java:
public class Example1Place extends Place{}

Example1View
public class Example1View extends Composite implements IsWidget{
HorizontalPanel hp = new HorizontalPanel();
Button b = new Button(Go To Default);

public Example1View() {
hp.add(b);
initWidget(hp);
}

HasClickHandlers getButton() {
return b;
}
}

Example1Activity.java
public class Example1Activity extends AbstractActivity implements
Activity {

ClientFactory clientFactory;
Example1View example1View;

public Example1Activity(Example1Place place, ClientFactory
clientFactory) {
this.clientFactory = clientFactory;

}

public void start(AcceptsOneWidget panel, EventBus eventBus) {
example1View = clientFactory.getExample1View();
example1View.getButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
clientFactory.getPlaceController().goTo(new
DefaultPlace()
);
}
});
panel.setWidget(example1View.asWidget());
}

@Override
public String mayStop() {
return you sure??;
}
}


AppActivityMapper.java:
public class AppActivityMapper implements ActivityMapper {
private ClientFactory clientFactory;

public AppActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}

public Activity getActivity(Place place) {
if (place instanceof DefaultPlace)
return new DefaultActivity((DefaultPlace) place,
clientFactory);
else if (place instanceof Example1Place)
return new Example1Activity((Example1Place) place,
clientFactory);
return null;
}
}

ClientFactory.java:
public interface ClientFactory {

DefaultView getDefaultView();
Example1View getExample1View();
EventBus getEventBus();
PlaceController getPlaceController();

}

ClientFactoryImpl.java:
public class ClientFactoryImpl implements ClientFactory {

private final DefaultView DEFAULT_VIEW = new DefaultView();
private final Example1View EXAMPLE_1_VIEW = new Example1View();
private final EventBus EVENT_BUS = new ResettableEventBus(new
SimpleEventBus());
private final PlaceController PLACE_CONTROLLER = new
PlaceController(EVENT_BUS);

public DefaultView getDefaultView() {
return DEFAULT_VIEW;
}

public Example1View getExample1View() {
return EXAMPLE_1_VIEW;
}

public EventBus getEventBus() {
return EVENT_BUS;
}

public PlaceController getPlaceController() {
return PLACE_CONTROLLER;
}
}

MVP.java
public class MVP implements EntryPoint {

public void onModuleLoad() {


Re: Activities does not get de-registered..

2011-06-30 Thread Thomas Broyer


On Thursday, June 30, 2011 2:06:22 PM UTC+2, El bassistos wrote:

 I am doing a small test application and I am using Activities and 
 Place but can't make it work as I expect.. 

 I have 2 Views, Activities and Places. DefaultView calls Example1View 
 and Vice Versa .. 

 In the Example1Activity I override mayStop() so that it returns a 
 String asking if user wants to go to Default. It works the first 
 time - when I hit go to Default, it ask if I am sure, and then I 
 press  'OK'  - that works, it swaps out the Example1View/Activity and 
 swap in the DefaultView/Activity. 

 But when I hit the go to Example1 from the DefaultView/Activity, it 
 ALSO ask the question. I can see in the Debugger that first the 
 DefaultActivity is called, and that it behaves as expected (the 
 mayStop() returns null), but the ExampleView's mayStop() method is 
 ALSO called?? Even though it is no in focus - it is about to come 
 in Focus .. So it seems as the previous Example1Activity is NOT 
 deregistered on the EventBus, after I hit the OK (which calles the 
 onClose() method and should cause the ActivityManager to de-registere 
 the Activity..) 

 Any Ideas ??? 

 Rehgards Jesper - Running GWT 2.2.1 and it is same behavior on FF, 
 Chrome and Safari 


 Here is my code: 

 DefaultPlace.java: 
 public class DefaultPlace extends Place {} 

 DefaultView.java: 
 public class DefaultView extends Composite implements IsWidget{ 
 HorizontalPanel hp = new HorizontalPanel(); 
 Button b = new Button(Go To Example1); 

 public DefaultView() { 
 hp.add(b); 
 initWidget(hp); 

 } 

 HasClickHandlers getButton() { 
 return b; 
 } 
 } 

 DefaultActivity.java 
 public class DefaultActivity extends AbstractActivity implements 
 Activity { 

 ClientFactory clientFactory; 
 DefaultView defaultView; 

 public DefaultActivity(DefaultPlace place, ClientFactory 
 clientFactory) { 
 this.clientFactory = clientFactory; 
 } 

 public void start(AcceptsOneWidget panel, EventBus eventBus) { 
 defaultView = clientFactory.getDefaultView(); 
 defaultView.getButton().addClickHandler(new ClickHandler() { 
 public void onClick(ClickEvent event) { 
 clientFactory.getPlaceController().goTo(new 
 Example1Place()); 
 } 
 });


Beware! you have a leak here! your view is a singleton but your activity is 
disposable: you should remove the ClickHandler from onStop and onCancel 
otherwise the button keeps references to all the activities ever started!
This is why you experience a slowdown when you remove your mayStop override.

I'm afraid it's not the cause of your issue with mayStop but it's a start…

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/hOZUbep85PIJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Activities does not get de-registered..

2011-06-30 Thread Mauro Bertapelle
Well, actually that is the cause of the problem. Just remove the click
handler in the onStop and onCancel otherwise disposed activities will
continue to receive click events

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.