PDA

View Full Version : Help



DrogoNevets
26 Nov 2009, 5:12 AM
I have the follwoing view class


package gwt.client;

import gwt.client.model.GwtContact;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.DataProxy;
import com.extjs.gxt.ui.client.data.JsonReader;
import com.extjs.gxt.ui.client.data.ListLoadConfig;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.ScriptTagProxy;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.LoadListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.util.Padding;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.ListView;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.*;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.CenterLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowData;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout.VBoxLayoutAlign;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class ManageContacts implements EntryPoint {

private DataProxy<ListLoadResult<ModelData>> _proxy;
private BaseListLoader<ListLoadResult<ModelData>> _loader = null;
private ListStore<GwtContact> _store;
private ListView<GwtContact> lv = null;

private TextField<String> addName = new TextField<String>();
private TextField<String> addNumber = new TextField<String>();

private TextField<String> editName = new TextField<String>();
private TextField<String> editNumber = new TextField<String>();
private ContentPanel contactPanel;

/**
* Creates and configures the list view that displays the message summaries
* to the user
*
* @return ListView
*/
private ListView<GwtContact> getListView() {
if(lv == null) {
lv = new ListView<GwtContact>();
}

lv.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
lv.setStore(getStore());
lv.setBorders(false);
lv.setSimpleTemplate("<span style=\"font-weight:bold;font-size:12pt;border-bottom: 1pt;color:grey\">{name} {number}</span>");
return lv;
}

/**
* Returns a data proxy to load data from the server.
*
* Create the proxy if it has not been created.
*
* @return data proxy for searching
*/
private DataProxy<ListLoadResult<ModelData>> getProxy() {
if (_proxy == null) {
String url = "http://localhost:8080/SpringWithExtGWTTest/listContact.json";
_proxy = new ScriptTagProxy<ListLoadResult<ModelData>>(url);
}
return _proxy;
}

/**
* W The loader to load records from the server that match the search data.
*
* The records return from the server will be in JSON format. The string
* returned is a representation of the XXX class.
*
* @return paging load for data returned from search
*/
private BaseListLoader<ListLoadResult<ModelData>> getLoader() {
if (_loader == null) {
ModelType type = new ModelType();
type.setRoot("_root");
type.addField("name", "_name");
type.addField("number", "_number");

JsonReader<ListLoadConfig> reader = new JsonReader<ListLoadConfig>(type) {
@Override
protected ModelData newModelInstance() {
return new GwtContact();
}
};

_loader = new BaseListLoader<ListLoadResult<ModelData>>(getProxy(), reader);
}
return _loader;
}

/**
* Get the data store which contains the records received.
*
* @return a list store of model data
*/
private ListStore<GwtContact> getStore() {
if (_store == null) {
ListStore<GwtContact> store = new ListStore<GwtContact>(getLoader());
_store = store;
}
return _store;
}

public void onModuleLoad() {
ContentPanel lcwest;
ContentPanel lccenter;
LayoutContainer container = new LayoutContainer();
VBoxLayoutData vBoxData = new VBoxLayoutData(5, 5, 5, 5);

ContentPanel panel = new ContentPanel();
panel.setHeading("Manage Contacts");
panel.setSize(800, 200);
panel.setLayout(new BorderLayout());

lcwest = new ContentPanel();
lcwest.setHeaderVisible(false);
lcwest.setLayout(new AccordionLayout());
lcwest.setBodyBorder(false);
BorderLayoutData west = new BorderLayoutData(LayoutRegion.WEST, 300, 100, 250);
west.setSplit(true);

VBoxLayout addFormLayout = new VBoxLayout();
addFormLayout.setPadding(new Padding(5));
addFormLayout.setVBoxLayoutAlign(VBoxLayoutAlign.STRETCH);

VBoxLayout editFormLayout = new VBoxLayout();
editFormLayout.setPadding(new Padding(5));
editFormLayout.setVBoxLayoutAlign(VBoxLayoutAlign.STRETCH);

ContentPanel addContact = new ContentPanel();
addContact.setLayout(addFormLayout);
addContact.setHeading("Add Contact");
addName.setFieldLabel("Name");
addNumber.setFieldLabel("Number");
addContact.add(addName, vBoxData);
addContact.add(addNumber, vBoxData);
ButtonGroup addButtons = new ButtonGroup(2);
addContact.add(addButtons, vBoxData);
addButtons.add(new Button("Add Contact", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
// We are adding a new contact!
String url = "http://localhost:8080/SpringWithExtGWTTest/addContact.json?name="+addName.getValue()+"&number="+addNumber.getValue();
ScriptTagProxy<ListLoadResult<ModelData>> addProxy = new ScriptTagProxy<ListLoadResult<ModelData>>(url);

BaseListLoader<ListLoadResult<ModelData>> addLoader = new BaseListLoader<ListLoadResult<ModelData>>(addProxy);
addLoader.load();
addName.setValue("");
addNumber.setValue("");
}
}));
addContact.collapse();

ContentPanel editContact = new ContentPanel();
editContact.setLayout(editFormLayout);
editContact.setHeading("Edit Contact");
editName.setFieldLabel("Name");
editNumber.setFieldLabel("Number");
editContact.add(editName, vBoxData);
editContact.add(editNumber, vBoxData);
editContact.collapse();

lcwest.add(addContact);
lcwest.add(editContact);

panel.add(lcwest, west);

contactPanel = new ContentPanel();
contactPanel.setBodyBorder(false);
contactPanel.setBorders(false);
contactPanel.setHeaderVisible(false);
contactPanel.add(getListView());
contactPanel.setScrollMode(Scroll.AUTO);
getLoader().load();

lccenter = new ContentPanel();
lccenter.setHeaderVisible(false);
lccenter.setLayout(new FitLayout());
lccenter.add(contactPanel);
BorderLayoutData center = new BorderLayoutData(LayoutRegion.CENTER);
center.setMargins(new Margins(5));

panel.add(lccenter, center);

container.add(panel, new FlowData(10));
container.setLayout(new CenterLayout());

RootPanel.get().add(container);
}
}
But when i click the "Add Contact button, i need the list on the right to update to show the new results. I'm new to GWT and EXT so its probably really simple but been struggling for a good 3 hours now :(

I know i need to run

getLoader().load();
getListView().refresh();
After the loader has finished, but my current trys with a loadListener have failed to fire after the addLoader.load() finishes.

Any ideas?

please help!