Home‎ > ‎UI‎ > ‎

ListEditor


Basic String List Editor

I use this to collect emails for a person entity object. 

Another more extensive list editor is in my Places demo. Places

The List 

This is a basic list editor using a String. 
import org.gonevertical.client.app.editors.events.EditorDeleteEvent;
import org.gonevertical.client.app.editors.events.EditorDeleteEventHandler;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.IsEditor;
import com.google.gwt.editor.client.adapters.EditorSource;
import com.google.gwt.editor.client.adapters.ListEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;

public class EmailsListEditor extends Composite implements IsEditor<ListEditor<String, EmailsItemEditor>> {

 
private static StringListEditorUiBinder uiBinder = GWT.create(StringListEditorUiBinder.class);
 
 
interface StringListEditorUiBinder extends UiBinder<Widget, EmailsListEditor> {}
 
 
private class StringItemEditorSource extends EditorSource<EmailsItemEditor> {
   
@Override
   
public EmailsItemEditor create(final int index) {
     
EmailsItemEditor subEditor = new EmailsItemEditor();
      googleEmails
.insert(subEditor, index);
      subEditor
.addDeleteHandler(new EditorDeleteEventHandler() {
       
public void onDeleteEvent(EditorDeleteEvent event) {
          remove
(index);
       
}
     
});
     
return subEditor;
   
}    
   
@Override
   
public void dispose(EmailsItemEditor subEditor) {
      subEditor
.removeFromParent();
   
}
   
@Override
   
public void setIndex(EmailsItemEditor editor, int index) {
      googleEmails
.insert(editor, index);
   
}
 
}  

 
private ListEditor<String, EmailsItemEditor> editor = ListEditor.of(new StringItemEditorSource());

 
@UiField
 
FlowPanel pWidget;
 
 
@UiField
 
PushButton bAdd;
 
 
@UiField
 
FlowPanel googleEmails;
 
 
@UiField
  HTML listName
;

 
public EmailsListEditor() {
    initWidget
(uiBinder.createAndBindUi(this));
 
}
 
 
public void setName(String s) {
   
if (s == null) {
      listName
.setHTML("");
   
} else {
      listName
.setHTML(s);
   
}
 
}
 
 
@UiHandler("bAdd")
 
void onBAddClick(ClickEvent event) {
    add
();
 
}

 
private void add() {
   
String s = "";
    editor
.getList().add(s);
 
}

 
@Override
 
public ListEditor<String, EmailsItemEditor> asEditor() {
   
return editor;
 
}

 
private void remove(final int index) {
    editor
.getList().remove(index);
 
}
 
}

List's Item

import org.gonevertical.client.app.editors.events.EditorDeleteEvent;
import org.gonevertical.client.app.editors.events.EditorDeleteEventHandler;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class EmailsItemEditor extends Composite implements LeafValueEditor<String> {
 
 
interface StringItemEditorUiBinder extends UiBinder<Widget, EmailsItemEditor> {}

 
private static StringItemEditorUiBinder uiBinder = GWT.create(StringItemEditorUiBinder.class);
 
 
@UiField
 
TextBox tbvalue;
 
 
@UiField
 
PushButton bDelete;

 
public EmailsItemEditor() {
    initWidget
(uiBinder.createAndBindUi(this));
 
}

 
@UiHandler("bDelete")
 
void onBDeleteClick(ClickEvent event) {
    fireDeleteEvent
();
 
}

 
private void fireDeleteEvent() {
    fireEvent
(new EditorDeleteEvent());
 
}
 
 
public final HandlerRegistration addDeleteHandler(EditorDeleteEventHandler handler) {
   
return addHandler(handler, EditorDeleteEvent.TYPE);
 
}

 
@Override
 
public void setValue(String value) {
    tbvalue
.setValue(value);
 
}

 
@Override
 
public String getValue() {
   
return tbvalue.getValue().trim();
 
}

}







Comments