Skip to content

Instantly share code, notes, and snippets.

@tbroyer
Created January 15, 2011 00:29
Show Gist options
  • Save tbroyer/780560 to your computer and use it in GitHub Desktop.
Save tbroyer/780560 to your computer and use it in GitHub Desktop.
Before/after GWT 2.1 Editors
package net.ltgt.gwt.samples.editors.shared;
public class Address {
private String street;
private String city;
private String zip;
private String state;
public String getStreet() { return this.street; }
public void setStreet(String street) { this.street = street; }
public String getCity() { return this.city; }
public void setCity(String city) { this.city = city; }
public String getZip() { return this.zip; }
public void setZip(String zip) { this.zip = zip; }
public String getState() { return this.state; }
public void setState(String state) { this.state = state; }
}
package net.ltgt.gwt.samples.editors.client;
import net.ltgt.gwt.samples.editors.shared.Address;
public class AddressEditor extends Composite implements Editor<Address> {
interface Binder extends UiBinder<Widget, AddressEditor> {}
private static final Binder BINDER = GWT.create(Binder.class);
@UiField TextBox street;
@UiField TextBox city;
@UiField TextBox zip;
@UiField ValueListBox<String> state;
public AddressEditor() {
initWidget(BINDER.createAndBindUi(this));
}
}
package net.ltgt.gwt.samples.editors.shared;
public class Person {
private String id;
private String firstName;
private String lastName;
private final Address address = new Address();
public String getId() { return this.id; }
public void setId(String id) { this.id = id; }
public String getFirstName() { return this.firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return this.lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public Address getAddress() { return this.address; }
}
package net.ltgt.gwt.samples.editors.client;
import net.ltgt.gwt.samples.editors.shared.Person;
public class PersonEditor extends Composite implements Editor<Person> {
interface Binder extends UiBinder<Widget, PersonEditor> {}
private static final Binder BINDER = GWT.create(Binder.class);
@UiField TextBox firstName;
@UiField TextBox lastName;
@UiField AddressEditor address;
public PersonEditor() {
initWidget(BINDER.createAndBindUi(this));
}
}
package net.ltgt.gwt.samples.editors.client;
import net.ltgt.gwt.samples.editors.shared.Person;
public class PersonView extends Composite {
interface Binder extends UiBinder<Widget, PersonView> {}
interface EditorDriver extends SimpleBeanEditorDriver<Person, PersonEditor> {}
private final Binder BINDER = GWT.Create(Binder.class);
private final PersonServiceAsync RPC = GWT.create(PersonService.class);
private final EditorDriver editorDriver = GWT.create(EditorDriver.class);
@UiField PersonEditor editor;
@UiField Button save;
@UiField Button cancel;
public PersonView() {
initWidget(BINDER.createAndBindUi(this));
}
public void edit(String id) {
RPC.getPerson(id, new AsyncCallback<Person>() {
@Override
public void onSuccess(Person person) {
editorDriver.edit(person);
}
@Override
public void onFailure(Throwable e) {
// ...handle failure...
}
});
}
@UiHandler("save")
void onSaveClick(ClickEvent event) {
Person person = editorDriver.flush();
RPC.savePerson(this.value, new AsyncCallback<Void>() {
@Override
public void onSuccess(Person person) {
// ...navigate... (e.g. back to list of persons)
}
@Override
public void onFailure(Throwable e) {
// ...handle failure...
}
});
}
@UiHandler("cancel")
void onCancelClick() {
// ...navigate... (e.g. back to list of persons)
}
}
@ychumak
Copy link

ychumak commented Jun 15, 2011

Hello, is there an example of using the ListEditor or any kind editor intended for working with List data? Thank.

@saadp
Copy link

saadp commented Aug 2, 2011

Simply amazing. Thanks for publishing this. It's pretty clear to me in how I can introduce Editors into my MVP implementation.

@slugmandrew
Copy link

Thanks a lot for this. Really useful. I have one question though - is there a way of moving the RPC call part into the Presenter instead of having the logic in the View? I'm using GWTP and my action being there means I have to inject DispatchAsync and PlaceManager into the View as well as the Presenter - something I would rather not do. Is there a way around this?

@confile
Copy link

confile commented Jan 29, 2016

The link is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment