PDA

View Full Version : listview events



jocy
10 May 2010, 4:24 AM
Morning,
I have a listview and i want that when i click on a node there is an event and when i click on a second time the event is repeat without click on another node before.

sven
10 May 2010, 4:27 AM
Listen to Events.Select on the listview. this is also documented.

jocy
10 May 2010, 4:54 AM
i tried it but it doesn't work even the first time !!!

sven
10 May 2010, 4:59 AM
Plese post a fully working testcase that implements EntryPoint

jocy
10 May 2010, 6:00 AM
That is the entrypoint:


import java.util.List;

import cm.inet.iss.application.gwt.client.model.CustumerSessionModel;

import com.extjs.gxt.themes.client.Slate;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.ThemeManager;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HtmlContainer;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.custom.ThemeSelector;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

public class FrmMainForm extends LayoutContainer {

private Viewport viewport;
FrmCenterForm frmCenter;
FrmWestForm frmWest;
FrmEastForm frmEast;
List<CustumerSessionModel> listUsers;

public FrmMainForm() {
DOM.setInnerHTML(RootPanel.get("loading").getElement(), "");
viewport = new Viewport();
viewport.setLayout(new BorderLayout());

getCustumerManagementService().getListCustumers(1,
new AsyncCallback<List<CustumerSessionModel>>() {
@Override
public void onFailure(Throwable caught) {

}
@Override
public void onSuccess(List<CustumerSessionModel> result) {
listUsers = result;

}

});

frmWest = new FrmWestForm(this);
ContentPanel west = (frmWest).getMainContentPanel();
west.setHeading("Main Menu");

frmCenter = new FrmCenterForm(this);
TabPanel centerPan = frmCenter.getMainPanel();

frmEast = new FrmEastForm(this);
ContentPanel east = frmEast.getMainPanel();

BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 150);
westData.setSplit(true);
westData.setCollapsible(true);
westData.setMargins(new Margins(5));

BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
centerData.setSplit(true);
centerData.setMargins(new Margins(5, 0, 5, 0));
centerData.setCollapsible(true);

BorderLayoutData eastData = new BorderLayoutData(LayoutRegion.EAST, 250);
eastData.setSplit(true);
eastData.setCollapsible(true);
eastData.setMargins(new Margins(5));

createNorth();
viewport.add(west, westData);
//viewport.add(centerPan, centerData);
//viewport.add(east, eastData);

add(viewport);

}

private void createNorth() {
StringBuffer sb = new StringBuffer();
sb.append("<div id='demo-header' class='x-small-editor'><div id='demo-theme'></div><div id=demo-title>ISS-Software</div></div>");
HtmlContainer northPanel = new HtmlContainer(sb.toString());
northPanel.setStateful(false);
ThemeManager.register(Slate.SLATE);
ThemeSelector selector = new ThemeSelector();
selector.setWidth(125);
northPanel.add(selector, "#demo-theme");
BorderLayoutData data = new BorderLayoutData(LayoutRegion.NORTH, 33);
data.setMargins(new Margins(5, 5, 0, 5));
viewport.add(northPanel, data);
}

private AccessPointManagementServiceAsync getCustumerManagementService() {
return (AccessPointManagementServiceAsync) GWT
.create(AccessPointManagementService.class);
}
}


and that is the implemented class


import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
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.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;

public class FrmWestForm extends LayoutContainer {

ContentPanel panel;
FrmMainForm frmMain;
FrmAccessPointManagement frmAccessPoint;
FrmCustomersSubscription frmCustumers;
FrmRulesManagement frmRules;
FrmNewProfil frmProducts;
ListView<ModelData> lstViewCust, lstViewProd, lstViewRules;
ModelData model;
ListStore<ModelData> storeViewCust, storeViewProd, storeViewRules;

public FrmWestForm(final FrmMainForm mainFrm) {
this.frmMain = mainFrm;
panel = new ContentPanel();
panel.setHeading("Main Menu");
panel.setBodyBorder(false);

AccordionLayout layout = new AccordionLayout();
panel.setLayout(layout);
final ContentPanel panRules = new ContentPanel();
//panRules.setBodyStyleName("pad-text");
panRules.setHeading("Rules Management");

lstViewRules = new ListView<ModelData>();
lstViewRules.setDisplayProperty("label");
lstViewRules.setAutoHeight(true);
lstViewRules.setBorders(false);
ModelData modelRules = new BaseModelData();
modelRules.set("label", "Show List");

storeViewRules = new ListStore<ModelData>();
storeViewRules.add(modelRules);

lstViewRules.setStore(storeViewRules);

lstViewRules.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<ModelData>>() {

@Override
public void handleEvent(SelectionChangedEvent<ModelData> be) {
int i=0;
Window.alert(""+i++);
}

});

panRules.add(lstViewRules);

panRules.addListener(Events.OnClick, new Listener<BaseEvent>() {

@Override
public void handleEvent(BaseEvent be) {
// TODO Auto-generated method stub

}
});
panel.add(panRules);

panel.setSize(200, 100);
add(panel);
}

public ContentPanel getMainContentPanel() {
return panel;
}
}


and want that on "show list" click there is box shown with the message 0 after 1....

sven
10 May 2010, 6:46 AM
That is not a testcase. Also i dont see where you did what i suggested

jocy
10 May 2010, 6:54 AM
sorry but i don't understand very well what you are talking about.
That is only a part of all my prject witch implement what i am asking

And i done what you suggest me at this level but i remove it because it didn't work



lstViewRules.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<ModelData>>() {

@Override
public void handleEvent(SelectionChangedEvent<ModelData> be) {
int i=0;
Window.alert(""+i++);
}

})

sven
10 May 2010, 8:47 AM
Listen to Events.Select on the listview. this is also documented.

Events.Select != Events.SelectionChange and listview != the selectionmodel

jocy
10 May 2010, 8:58 AM
????? more explication please!!!

micgala
10 May 2010, 11:48 PM
Instead of Using Events.SelectionChange, use Events.Select. Instead of adding the event to the selectionModel, add it to the ListView.
Like this:


lstViewRules.addListener(Events.Select, new Listener<ListViewEvent>>() {
....

jocy
11 May 2010, 12:29 AM
ok thanks that is what i done:


lstViewRules.addListener(Events.Select,
new Listener<ListViewEvent<ModelData>>() {

public void handleEvent(ListViewEvent<ModelData> be) {...

sven
11 May 2010, 5:47 AM
And that is exactly what i told you ;)

micgala
11 May 2010, 6:20 AM
Since the first reply :-)

jocy
11 May 2010, 6:31 AM
sorry sven,
i hadn't make the difference between addlistener on selectionmodel and addlistener directly on the listview.
but now it is ok!!!