PDA

View Full Version : Which event when ContenPanel becomes visible?



francescoNemesi
10 Aug 2010, 4:21 AM
Hello there,

I need to detect when a ContentPanel becomes visible. The code below has a CP, inside it a VerticalPanel with 10 CPs. To show the CPs at the bottom you need to scroll down and I want to detect when the contained CPs become visible to refresh their content. I have tried Events.Show and BeforeShow without success.

Thanks for any help. F




package com.keinavo.bitools.client;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class ClientVisible implements EntryPoint{

public void onModuleLoad() {

ContentPanel lc = new ContentPanel();
lc.setScrollMode(Scroll.AUTO);
lc.setHeight(300);
lc.setWidth(600);

VerticalPanel vp = new VerticalPanel();
vp.setSpacing(5);

for(int i=0; i<10; i++){

final ContentPanel cp = new ContentPanel();
cp.setHeight(200);
cp.setWidth(500);
cp.setUrl("http://code.google.com/");
cp.setHeading("CP NO : "+i);

cp.addListener(Events.Show, new Listener<BaseEvent>(){
public void handleEvent(BaseEvent be) {
System.out.println("BeforeShow Event for : "+cp.getHeading());
}
});

vp.add(cp);

}

lc.add(vp);

RootPanel.get().add(lc);
}
}

sven
10 Aug 2010, 4:23 AM
There is no event. You can listen to the Events.OnScroll event of the component you are scrolling and than calculate for yourself it the contentpanel is visible or not.

francescoNemesi
10 Aug 2010, 4:33 AM
Thanks Sven, exactly the same workaround I am working on now.

I think "Visible" would be a useful event to add to any component, don't you think?

Regards

francescoNemesi
10 Aug 2010, 4:36 AM
Uhmmmm I have modified the code as below, but the isVisible() method of the CPs always returns true, even if they are hidden....



package com.keinavo.bitools.client;

import java.util.ArrayList;
import java.util.List;

import com.allen_sauer.gwt.log.client.Log;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class ClientVisible implements EntryPoint{

public void onModuleLoad() {

final List<ContentPanel> list = new ArrayList<ContentPanel>();

final VerticalPanel vp = new VerticalPanel();
vp.setSpacing(5);

for(int i=0; i<10; i++){

final ContentPanel cp = new ContentPanel();
cp.setHeight(200);
cp.setWidth(500);
cp.setUrl("http://code.google.com/");
cp.setHeading("CP NO : "+i);

list.add(cp);
}


ContentPanel lc = new ContentPanel();
lc.setScrollMode(Scroll.AUTO);
lc.setHeight(300);
lc.setWidth(600);
lc.addListener(Events.Scroll, new Listener<BaseEvent>(){
public void handleEvent(BaseEvent be) {
Log.debug("Scrolling");
for(ContentPanel cp : list){
Log.debug(cp.getHeading()+ " isVisible ? "+cp.isVisible());
}
}
});

for(ContentPanel cp : list){
vp.add(cp);
}

lc.add(vp);

RootPanel.get().add(lc);
}
}

sven
10 Aug 2010, 4:36 AM
No, it would not. This is too app specific and too cost intensiv to cover every case.

sven
10 Aug 2010, 4:37 AM
Having somesthing scrolled out does not effect visiblity.

francescoNemesi
10 Aug 2010, 4:40 AM
Thanks, so how would I detect is a child cp becomes visible after a scroll of the father cp? Thanks again

sven
10 Aug 2010, 4:52 AM
You have the position and size of the contentpanel and you have the scrollposition. with this you can easily calculate it.

francescoNemesi
10 Aug 2010, 5:11 AM
Thanks, I will work on that, will let you know when it is done.

Regards