2012-05-05 31 views
0

我用ListEditor,讓孩子的編輯列表,我做的一切,就像我在一些examples.The僅從例子區別看到的是,我想小部件編輯孩子添加爲標籤到一些TabLayoutPanel添加列表子編輯器標籤面板

問題是我想給這個新標籤一個標題,這個標題不是常量,而是取決於新創建的子編輯器編輯的對象(所以讓標題爲child.getName()),我不知道里面有EditorSource#create()方法。

ListEditor<ChildProxy, ChildPanel> children = ListEditor 
     .of(new EditorSource<ChildPanel>() { 

      @Override 
      public ChildPanel create(int index) { 
       ChildPanel tab = new ChildPanel(); 
       //here's a problem, how I can get tabHeader here? 
       tabPanel.add(tab,tabHeader); 
      } 

     }); 

我如何可以設置選項卡通過create()創造價值依賴頭?任何幫助/解決方法將不勝感激。

回答

0

對我而言,通過tabPanelindex到新創建的ChildPanel()並使其成爲ValueAwareEditor。然後在setValue()上,我在tabPanel設置標題,給定index

0

請問這種方法對你的工作:

public class ChildrenEditor extends Composite implements 
     IsEditor<ListEditor<Child, ChildInTabEditor>> { 


    ListEditor<Child, ChildInTabEditor> editor; 

    public ChildrenEditor() { 
     initWidget(uiBinder.createAndBindUi(this)); 
     editor = ListEditor.of(new ChildInTabEditorSource()); 
    } 


    private class ChildInTabEditorSource extends EditorSource<ChildInTabEditor> { 

      public ChildInTabEditor create(int index) { 
       ChildInTabEditor tab = new ChildInTabEditor(); 
       // here's the trick : 
       Child child = editor.getList().get(index); 
       tabPanel.add(tab,child.getTabTitle()); 
       return tab; 
      } 

     } 

    @Override 
    public ListEditor<Child, ChildInTabEditor> asEditor() { 
     return editor; 
    } 


} 

ChildInTabEditor必須是那麼實現Editor<Child>過一個標籤!

+0

奇怪,但'editor.getList()'似乎爲空:-( –

+0

請查看:http://code.google.com/p/google-web-toolkit/source/browse/trunk /user/src/com/google/gwt/editor/client/adapters/ListEditor.java?r=9666#66似乎這個首次調用'EditorSource#create()'是在'list'字段初始化之前完成的:(。所以我越來越'NullPointerException'試圖'create'訪問此列表:(。 –

+1

好了,我的錯,那麼,你可以做一個ChildInTabEditor和ValueAwareEditor設置其自己的標題呢? – koma