2015-01-10 15 views
2

편집자를 사용하여 수동으로 위젯을 구문 분석하는 데 사용했던 POJO를 바인딩하여 gwt 프로젝트의 코드를 개선하고 싶습니다. 그러나 나는 을 아직 참조하지 않았기 때문에 대부분 documentation이 혼동 스럽다.UiBinder가없는 GWT 편집기 사용

UI 바인더가없는 편집기를 사용하는 것이 합리적입니까? My ParentDTO에는 여러 개의 childDTO가 포함되어 있습니다. 내가 둥지에 내 ParentEditor에 텍스트 영역 확장 일부 ChildEditors을 시도하고 방법 다음 코드 예제 (필수 요소로 아래로 제거하려고) :

public class MyEditorPage { 

    // editors 
    class ParentDTOEditor implements Editor<ParentDTO> { 
     Integer dataBaseId; 
     List<ChildDTOEditor> childs; 

     public void attach(RootPanel rootPanel) { 
      for (ChildDTOEditor widget : childs) { 
       rootPanel.add(widget); 
      } 
     } 
    } 
    class ChildDTOEditor implements Editor<ChildDTO> extends TextArea {} 

    // driver 
    interface Driver extends SimpleBeanEditorDriver<ParentDTO, ParentDTOEditor> {} 
    Driver driver = GWT.create(Driver.class); 

    // load set widgets to the root panel 
    public void loadPage(RootPanel rootPanel) { 

     // get pojos from server 
     myService.getSuff(... 
      ... 
      public void onSuccess(ParentDTO result) { 
       ParentDTOEditor editor = new ParentDTOEditor(); 
       driver.initialize(editor); 
       driver.edit(result); 
       editor.attach(rootPanel);     
      } 
    } 

    // save 
    public void save() { 
     ParentDTO dto = driver.flush(); 
     ... // call myService.saveStuff(dto,... 
    } 
} 

내가 심지어 별도의 편집자 또는 형식 ListEditor 단지 부모 편집기가 필요하십니까 자식 dtos를 직접 보유하고 있습니까?

답변

1

ui 바인더가없는 편집기를 사용하는 것이 합리적입니까?

예, 기능은 독립적이며 각각 다른 기능없이 사용할 수 있습니다.

별도의 편집기가 필요하거나 ListEditor의 상위 편집기 만 자식 dtos를 직접 보유합니까?

당신은 direcly ListEditor 구현을 만들 수 있습니다,하지만 당신이 괜찮은 예를 here이야하지만 '를 만드는 방법을 말해 EditorSource<ChildDTOEditor>을 확장하고 ListEditor.of(new YourChildDTOEditorSourceImpl())

를 사용하여 Editor<ChildDTO>을 파괴하면 GWT는 당신을 위해 할 수있는 여기에 최소한의 구현이 필요합니다.

public class FooEditor extends Composite implements Editor<Foo> { 

    // Implement one of uibinder+fields, fields, methods, or LeafValueEditor.set/getValue() 

    public FooEditor() { 
     initWidget(/* root widget or call to uiBinder.createAndBindUi(this) */) 
    } 

} 

public class FooListEditor extends Composite implements IsEditor<ListEditor<Foo, FooEditor>> { 

    private class FooEditorSource extends EditorSource<FooEditor> { 
     @Override 
     public FooEditor create(int index) { 
      FooEditor subEditor = new FooEditor(); 

      // any additional per-item config can go here, e.g wiring up delete handler 

      listPanel.insert(subEditor, index); 

      return subEditor; 
     } 

     @Override 
     public void dispose(FooEditor subEditor) { 
      subEditor.removeFromParent(); 
     } 

     @Override 
     public void setIndex(FooEditor subEditor, int index) { 
      listPanel.insert(subEditor, index); 
     } 
    } 

    // FlowPanel or anything else you want to use to hold the sub-editors. 
    // Instantiated explicitly or through uibinder. 
    FlowPanel listPanel = new FlowPanel(); 


    // Let GWT handle the ListEdiotr implementation 
    ListEditor<Foo, FooEditor> editor = ListEditor.of(new FooEditorSource()); 

    public FooListEditor() { 
     initWidget(listPanel /* or uiBinder.createAndBindUi(this) */); 
    } 

    @Override 
    public ListEditor<Foo, FooEditor> asEditor() { 
     return editor; 
    } 

} 

이제 편집기 드라이버를 만들고 일반 편집기처럼 사용할 수 있지만 대신 목록을 전달하십시오.

interface Driver extends SimpleBeanEditorDriver<List<Foo>, ListEditor<Foo, FooEditor>> {} 
Driver driver = GWT.create(Driver.class); 
FooListEditor fooListEditor = new FooListEditor(); 

/* snip */ 

driver.initialize(FooListEditor); 
driver.edit(someListOfFoo);