Last active
September 16, 2015 18:38
-
-
Save nabil-hassan/8fda1d5cf981a2b85dcf to your computer and use it in GitHub Desktop.
GWT ValueAwareEditor Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.nabilh.gwtsandbox.client.widgets.form.name; | |
| import com.google.gwt.core.client.GWT; | |
| import com.google.gwt.editor.client.EditorDelegate; | |
| import com.google.gwt.editor.client.ValueAwareEditor; | |
| import com.google.gwt.uibinder.client.UiBinder; | |
| import com.google.gwt.uibinder.client.UiField; | |
| import com.google.gwt.user.client.ui.Composite; | |
| import com.google.gwt.user.client.ui.TextBox; | |
| import com.google.gwt.user.client.ui.ValueListBox; | |
| import com.google.gwt.user.client.ui.Widget; | |
| import net.nabilh.gwtsandbox.shared.dto.NameDTO; | |
| import net.nabilh.gwtsandbox.shared.enums.Title; | |
| import java.util.Arrays; | |
| import java.util.logging.Logger; | |
| /** | |
| * Widget that allows user to enter title, forename, and surname <br/> <br/> | |
| * | |
| * N.B. when we call driver.edit() from the driver in the primary editor, we must make sure that we intialise | |
| * the corresponding property for the NameField on the primary editor's back object, as the driver will not descend | |
| * into sub-editors that are null. <br/> <br/> | |
| * | |
| * For example, if our primary editor is backed by CustomerDTO and the NameField sub-editor is represented by the NameDTO property "name":<br/> <br/> | |
| * | |
| * CustomerDTO value = new CustomerDTO();<br/> | |
| * value.setName(new NameDTO()); <br/> | |
| * driver.edit(value); <br/><br/> | |
| * | |
| * Author: Nabil Hassan<br/> | |
| * Date: 16/09/2015 18:37 | |
| */ | |
| public class NameField extends Composite implements ValueAwareEditor<NameDTO> { | |
| public static final Logger LOG = Logger.getLogger(NameField.class.getName()); | |
| interface Binder extends UiBinder<Widget, NameField> {} | |
| private static Binder uiBinder = GWT.create(Binder.class); | |
| private EditorDelegate<NameDTO> delegate; | |
| @UiField | |
| TextBox forename, surname; | |
| @UiField | |
| ValueListBox<Title> title; | |
| public NameField() { | |
| initWidget(uiBinder.createAndBindUi(this)); | |
| title.setAcceptableValues(Arrays.asList(Title.values())); | |
| } | |
| @Override | |
| public void flush() { | |
| LOG.finest("flush() called"); | |
| } | |
| @Override | |
| public void onPropertyChange(String... paths) { | |
| LOG.warning("onPropertyChange() called. This method is not supported by this widget."); | |
| } | |
| @Override | |
| public void setValue(NameDTO name) { | |
| forename.setValue(name == null ? null : name.getForename()); | |
| surname.setValue(name == null ? null :name.getSurname()); | |
| title.setValue(name == null ? null :name.getTitle()); | |
| } | |
| @Override | |
| public void setDelegate(EditorDelegate<NameDTO> delegate) { | |
| this.delegate = delegate; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' | |
| xmlns:g='urn:import:com.google.gwt.user.client.ui'> | |
| <ui:style> | |
| .marginLeft {margin-left:2em;} | |
| </ui:style> | |
| <g:HorizontalPanel> | |
| <g:Label text="Title"/> | |
| <g:ValueListBox ui:field="title" addStyleNames="{style.marginLeft}"/> | |
| <g:Label text="Forename" addStyleNames="{style.marginLeft}"/> | |
| <g:TextBox ui:field="forename" addStyleNames="{style.marginLeft}"/> | |
| <g:Label text="Surname" addStyleNames="{style.marginLeft}"/> | |
| <g:TextBox ui:field="surname" addStyleNames="{style.marginLeft}"/> | |
| </g:HorizontalPanel> | |
| </ui:UiBinder> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment