Thursday, December 22, 2011

Re: ListEditor with inheritance

Thomas,

Thank you for your quick response. I do have a semi working
solution that does support inheritance, still has some bugs that are
probably caused by my lack of generics in the EditorSource. I did see
BobV's response on stackoverflow but wasn't exactly sure it would fix
my problem. Going forward I am going to implement your solution using
ValueAwareEditor, use instanceof to construct subeditors and manually
flush the changes to the corresponding object. Thank you again for
all your work helping the GWT community.

I am attaching a partial solution that is adding a SqlDataProvider
entity but is not persisting the values. In the solution I could use
the EditorSource to construct a sub editor of a specific type based on
the instanceof DataProvider in the asEditor().getList() of my
DataProviderEditor. I imagine that there is a problem persisting my
values because the EditorSource does not know what kind of
Editor<Entity> it is editing so this will probably never work
correctly. Please let me know if you agree.

I have implemented the SqlDataProviderEditor as a ValueAwareEditor
instead of Editor as a way to do debugging.


// NOTE THIS CODE SAMPLE DOES NOT WORK CORRECTLY.
public class DataProviderListEditor extends Composite implements
IsEditor<ListEditor<DataProviderProxy, Editor<DataProviderProxy>>> {

private static final Logger logger =
Logger.getLogger(DataProviderListEditor.class.getName());

private class DataProviderSource extends EditorSource<Editor> {

@Override
public Editor create(int index) {

SqlDataProviderEditor editor = new
SqlDataProviderEditor();
container.insert(editor, index);
// Editor<DataProviderProxy> retEditor =
(Editor<DataProviderProxy>)
// editor;

return editor;
}

/**
* Call this to remove an editor from the view.
*
* @Override public void dispose(Editor<DataProviderProxy>
editor) {
* editor.removeFromParent(); }
* @Override public void setIndex(Editor<DataProviderProxy>,
int index)
* { container.insert(editor, index); }
*/
}

public static class SqlDataProviderEditor extends Composite
implements ValueAwareEditor<SqlDataProviderProxy> {

private SqlDataProviderProxy value = null;

@UiField
TextBox variableName;

@UiField
TextArea sqlStatement;

public SqlDataProviderEditor() {
initWidget(GWT.<Binder>
create(Binder.class).createAndBindUi(this));
}

@Override
public void setDelegate(EditorDelegate<SqlDataProviderProxy>
delegate) {
// TODO Auto-generated method stub
}

@Override
public void flush() {
logger.info("calling flush on my value editor");
value.setSqlStatement(sqlStatement.getValue());
logger.info("Setting variable name to be " +
variableName.getValue());
value.setVariableName(variableName.getValue());
}

@Override
public void onPropertyChange(String... paths) {

}

@Override
public void setValue(SqlDataProviderProxy value) {
logger.info("Value of object is " + value);
this.value = value;
logger.info("Value being assigned is " +
value.getVariableName());
}
}

/**
* This is the default view for our widgets.
*
* @author chinshaw
*
*/
@UiTemplate("DataProviderEditor.ui.xml")
public interface Binder extends UiBinder<Widget,
SqlDataProviderEditor> {
}

/**
* This is the parent container panel that contains all other
editors
*/
private final FlowPanel container = new FlowPanel();
private final ListEditor<DataProviderProxy,
Editor<DataProviderProxy>> editor = ListEditor.of(new
DataProviderSource());

/**
* Default constructor takes an index of the Editor objects
location. The
* index is used to delete this object.
*
* @param index
*/
public DataProviderListEditor(Resources resources) {
initWidget(container);
}

@Override
public ListEditor<DataProviderProxy, Editor<DataProviderProxy>>
asEditor() {
return editor;
}
}


On Dec 22, 10:56 am, Thomas Broyer <t.bro...@gmail.com> wrote:
> First, have you seenhttp://code.google.com/p/google-web-toolkit/issues/detail?id=6719?
>
> In your case, I think you could do it quite easily by:
>
>    1. not having the TextArea as a sub-editor
>    2. implementing ValueAwareEditor to push to the TextArea and make it
>    visible when the value is a SqlDataProvider in setValue, and pull from it
>    and push to the value in flush(); and similar things for other kinds of
>    values.
>
> That unfortunately won't scale very well as you add other DataProvider
> subclasses.
>
> FWIW, in a similar scenario, we chose to not use the Editor framework and
> handle everything "by hand" instead (but we had another challenge: some
> structures are recursive; i.e. we could have a DataProvider that would
> contain other DataProvider).

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate