0

I use ListEditor to allow editing list of chilren and I do everything just like I saw in some examples.The only difference from examples is that I want widgets editing children to be added as a tabs to some TabLayoutPanel.

The problem is that I want to give a header to this new tab and this header is not constant but depends on object being edited by newly created sub-editor (so let the header be child.getName()) which I don't know inside EditorSource#create() method.

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);
            }

        });

How can I set value-dependent headers to tabs created by create()? Any help/workaround would be greatly appreciated.

Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70

2 Answers2

0

Does this approach work for you :

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 must be a Tab that implements Editor<Child> then too!

koma
  • 6,486
  • 2
  • 27
  • 53
  • Please, take a look at: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/editor/client/adapters/ListEditor.java?r=9666#66 . It seems that this first invocation of `EditorSource#create()` is done before initialization of `list` field :(. Hence I'm getting `NullPointerException` trying to access this list in `create` :(. – Piotr Sobczyk May 05 '12 at 22:42
  • 1
    Ok, my fault then. You could make the ChildInTabEditor a ValueAwareEditor and set its own title then ? – koma May 05 '12 at 23:16
  • yeah, I did exactly this. Probably there is no cleaner way. Thanks for commitment! – Piotr Sobczyk May 06 '12 at 06:39
0

What worked for me was passing tabPanel and index to newly created ChildPanel() and make it ValueAwareEditor. Then on setValue() I was setting header on tabPanel reference at given index.

Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70