ListEditor Help

74 views
Skip to first unread message

Lars

unread,
Mar 8, 2012, 1:48:28 PM3/8/12
to google-we...@googlegroups.com
So trying to wrap my head around the Editor Framework and ListEditor in particular...

I have a class that basically has 1 property, an ArrayList:

public class ArticlePaginator implements Iterable<ArticlePage> {
   
    ArrayList<ArticlePage> articlePages = new ArrayList<ArticlePage>();

    public ArticlePaginator(ThriftWidget tw) {
       
        for (ThriftWidget subTw : tw.getSubWidgets()) {
            articlePages.add(new ArticlePage(subTw));
        }
       
    }

    @Override
    public Iterator<ArticlePage> iterator() {
        Iterator<ArticlePage> iterator = articlePages.iterator();
        return iterator;
    }
   
    public void setArticlePages(ArrayList<ArticlePage> articlePages) {
        this.articlePages = articlePages;
    }
   
    public ArrayList<ArticlePage> getArticlePages() {
        return articlePages;
    }

}

Since I'd like my users to be able to add/remove the sub-widgets (in this case "ArticlePage" objects which have their own standard editor "ArticlePageEditor") I figured (correctly?) I needed to use the ListEditor adaptor class as my Editor.  I'm not sure if I have this correct conceptually, b/c when I try to run in dev mode I get the following error:
Caused by: java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from ArticlePaginator to List

Why is it trying to convert my ArticlePaginator to a List???

Any insight would be greatly appreciated.

Here's my attempted implementation of the ListEditor:

public class ArticlePaginatorEditor extends Composite implements IsEditor<ListEditor<ArticlePage, ArticlePageEditor>> {
   
    private static ArticlePaginatorEditorUiBinder uiBinder = GWT.create(ArticlePaginatorEditorUiBinder.class);
   
    interface ArticlePaginatorEditorUiBinder extends UiBinder<Widget, ArticlePaginatorEditor> {}

   
    @UiField
    VerticalPanel container;
   
    private class ArticlePageEditorSource extends EditorSource<ArticlePageEditor> {

        @Override
        public ArticlePageEditor create(int index) {
            ArticlePageEditor subEditor = new ArticlePageEditor();
            container.add(subEditor);
            return subEditor;
        }
       
        @Override
        public void dispose(ArticlePageEditor subEditor) {
          subEditor.removeFromParent();
         
        }

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

    }

   
    private ListEditor<ArticlePage, ArticlePageEditor> editor = ListEditor.of(new ArticlePageEditorSource());
   
    public ArticlePaginatorEditor() {
       
        initWidget(uiBinder.createAndBindUi(this));
       
    }

    @Override
    public ListEditor<ArticlePage, ArticlePageEditor> asEditor() {
        return editor;
    }



    @UiHandler("add")
    void onClickAdd(ClickEvent e) {
       
        ThriftWidget newMeta = new ThriftWidget(29, new String[]{}, null, new int[]{1, 2, 3});
        newMeta.subwidgets = new ThriftWidget[] {
            new ThriftWidget(41, new String[]{"huh?"}, null, null),
            new ThriftWidget(41, new String[]{""}, null, null),
            new ThriftWidget(41, new String[]{""}, null, null)
        };
       
        ThriftWidget newPage = new ThriftWidget(1, null, null, new int[]{1});
        newPage.subwidgets = new ThriftWidget[] { newMeta };
       
        ArticlePage ap = new ArticlePage(newPage);
       
        editor.getList().add(ap);

       
    }


}

Brandon Donnelson

unread,
Mar 10, 2012, 5:22:06 PM3/10/12
to google-we...@googlegroups.com
Hmm.. Maybe this could help: http://c.gwt-examples.com/home/ui/listeditor - I have some ListEditor examples here.
 

Lars

unread,
Mar 12, 2012, 11:16:05 AM3/12/12
to google-we...@googlegroups.com
Thanks. This looks helpful.

Lars
Reply all
Reply to author
Forward
0 new messages