PDA

View Full Version : Help, How I may selec ListItem in ListView???



kazeev
24 May 2012, 9:46 AM
lv = new ListView<ModelData>(); lv.setSize(300, 200); lv.setStore(store); lv.setDisplayProperty("name"); lv.getSelectionModel().setSelectionMode(SelectionMode.MULTI); ListViewSelectionModel<ModelData> lsm = new ListViewSelectionModel<ModelData>(); lsm.select(1, true); lv.setSelectionModel(lsm);
add(lv); lsm.selectAll();

lsm.select(1, true);
and
lsm.selectAll();
didn't work.
Help please!!!!

sven
24 May 2012, 9:55 AM
These method should work. Have you verified that your store is filled when you are calling these methods?

kazeev
24 May 2012, 10:19 AM
setted template


private native String getFlagTemplate(String base) /*-{ return [ '<tpl for=".">', '<div class="countries"><img width="16px" height="11px" src="' + base + 'images/icons/flags/{locale}.png">&nbsp;{name}</div>', '</tpl>' ].join(""); }-*/;

listView work.
listener work too


lv.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<ModelData>>() { public void handleEvent(SelectionChangedEvent<ModelData> be) { UrlBuilder ub = Window.Location.createUrlBuilder(); ub.setParameter("locale", (String)be.getSelectedItem().get("locale")); Window.Location.replace(ub.buildString()); } });

but
lv.getSelectionModel().slectAll() not work :(

sven
24 May 2012, 10:37 AM
Sorry, what i mean is if your store contains models when calling these methods?

kazeev
24 May 2012, 11:15 AM
public SetLocaleDialog() {
FormLayout layout = new FormLayout();
layout.setLabelWidth(90);
layout.setDefaultWidth(155);
setLayout(layout);

setButtonAlign(HorizontalAlignment.LEFT);
setButtons("");
setHeading(constants.language());
setModal(true);
setAutoHeight(true);
setAutoWidth(true);
setResizable(false);
setClosable(false);

// defines the xml structure
ModelType type = new ModelType();
type.setRoot("countries");
type.setRecordName("country");
type.addField("name");
type.addField("locale");

// Determine if Explorer or Example for XML path
String path = GWT.getHostPageBaseURL() + (Utils.isExplorer() ? "" : "../../") + "etc/Countries.xml";
// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
HttpProxy<String> proxy = new HttpProxy<String>(builder);
// need a loader, proxy, and reader
XmlLoadResultReader<ListLoadResult<ModelData>> reader = new XmlLoadResultReader<ListLoadResult<ModelData>>(type);
final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy,
reader);
ListStore<ModelData> store = new ListStore<ModelData>(loader);

loader.load();

lv = new ListView<ModelData>();
lv.setItemSelector("div.countries");
lv.setTemplate(getFlagTemplate(Utils.isExplorer() ? "" : "../../"));
lv.setSize(300, 200);
lv.setStore(store);
lv.setDisplayProperty("name");
lv.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
lv.getSelectionModel().addListener(Events.SelectionChange,
new Listener<SelectionChangedEvent<ModelData>>() {
public void handleEvent(SelectionChangedEvent<ModelData> be) {
UrlBuilder ub = Window.Location.createUrlBuilder();
ub.setParameter("locale", (String)be.getSelectedItem().get("locale"));
Window.Location.replace(ub.buildString());
}
});

add(lv);

getButtonBar().add(new FillToolItem());
next = new Button(constants.next());
next.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
Settings set = new Settings();
set.setLocale(Window.Location.getParameter("locale"));
Registry.register("settings", set);
SetLocaleDialog.this.hide();
Dispatcher.forwardEvent(InstallEvents.LicenseAgreement);
}
});
getButtonBar().add(next);
}

private native String getFlagTemplate(String base) /*-{
return [
'<tpl for=".">',
'<div class="countries"><img width="16px" height="11px" src="' + base + 'images/icons/flags/{locale}.png">&nbsp;{name}</div>',
'</tpl>'
].join("");
}-*/;

It's full listing of program.
How I Can select some item(s) programmable????
Help please!
Thanks.

sven
24 May 2012, 11:24 AM
Your data is loaded async. This means you can first select the items when they are loaded and added to the store. You need to listen to the loader Load event. In this event you can select the items.

kazeev
24 May 2012, 11:29 AM
Thanks!!!!!!!!!!!!!!!
I forgot it. 8-|