There are a few posts asking about Editor's discussing inheritance
this but no responses as of yet. Please keep in mind that I have
search
google.com/codesearch, GWT issue tracker and google groups
looking for some kind of solution to using Editor's with inheritance.
// This is my base data provider class that all other implementations
will inherit from.
@ProxyFor(value = DataProvider.class, locator =
DatastoreObjectLocator.class)
public interface DataProviderProxy extends ValueProxy {
public enum DataProviderType {
SQL, R_Command
}
public String getVariableName();
public void setVariableName(String variableName);
}
// This is a simple example that inherits from DataProvider and adds a
single sql statement.
@ProxyFor(value = SqlDataProvider.class, locator =
DatastoreObjectLocator.class)
public interface SqlDataProviderProxy extends DataProviderProxy {
public String getSqlStatement();
public void setSqlStatement(String sqlStatement);
}
// This is the class that I am editing.
@ProxyFor(value = Report.class, locator =
DatastoreObjectLocator.class)
public interface ReportProxy extends DatastoreObjectProxy {
...
/**
* List of all data providers for this report.
* @return
*/
public List<DataProviderProxy> getDataProviders();
/**
* Setter for all data providers.
* @param dataProviders
*/
public void setDataProviders(List<DataProviderProxy>
dataProviders);
...
}
// My report editor that is editing my List of DataProvider objects.
public class ReportBuilderViewImpl extends ViewImpl implements
ReportBuilderView, Editor<ReportProxy> {
...
/**
* Editor for the data provider object contained in the {@link
ReportProxy}.
*/
@UiField
@Path("dataProviders")
DataProviderListEditor dataProviderEditor;
...
}
// This class is a work in progress but essentially what I am trying
to do is to Edit a list of DataProviderProxy
// objects, but when I get to an object of type SqlDataProvider I want
to show the user the optional TextArea that
// they can past their sql statement. In the same editor if the
DataProvider is an instanceof RDataProvider ( not // shown above) I
would want to give the user the option of editing an R command and not
the sqlStatement. I
// have tried adding Generics but ran into compilation issues when
Editor validation was running.
Is there any kind of elegant solution to the problem I am trying to
solve?
public class DataProviderListEditor extends Composite implements
IsEditor<ListEditor<DataProviderProxy, DataProviderEditor>> {
private class DataProviderSource extends
EditorSource<DataProviderEditor> {
@Override
public DataProviderEditor create(int index) {
DataProviderEditor editor = new DataProviderEditor();
container.insert(editor, index);
return editor;
}
/**
* Call this to remove an editor from the view.
*/
@Override
public void dispose(DataProviderEditor editor) {
editor.removeFromParent();
}
@Override
public void setIndex(DataProviderEditor editor, int index) {
container.insert(editor, index);
}
}
/**
* This is the default view for our widgets.
*
* @author chinshaw
*
*/
@UiTemplate("DataProviderEditor.ui.xml")
public interface Binder extends UiBinder<Widget,
DataProviderEditor> {
}
/**
* This is the actual widget that edits our data provider proxy.
It will
* handle flushing and so forth.
*
* @author chinshaw
*
*/
public static class DataProviderEditor extends Composite
implements ValueAwareEditor<DataProviderProxy> {
private DataProviderProxy value = null;
@UiField
TextBox variableName;
@UiField
TextArea sqlStatement;
public DataProviderEditor() {
initWidget(GWT.<Binder>
create(Binder.class).createAndBindUi(this));
}
@Override
public void setDelegate(EditorDelegate<DataProviderProxy>
delegate) {
// TODO Auto-generated method stub
}
/**
* Indicates that the Editor cycle is finished. This method
will be
* called in a depth-first order by the EditorDriver, so
Editors do not
* generally need to flush their sub-editors.
*/
@Override
public void flush() {
}
/**
* Notifies the Editor that one or more value properties have
changed.
* Not all backing services support property-based
notifications.
*
* @param paths
* a list of String paths
*/
@Override
public void onPropertyChange(String... paths) {
}
/**
* Called by the EditorDriver to set the object the Editor is
peered
* with
* <p>
* ValueAwareEditors should preferentially use sub-editors to
alter the
* properties of the object being edited.
*
* @param value
* a value of type T
*/
@Override
public void setValue(DataProviderProxy value) {
this.value = value;
}
}
/**
* This is the parent container panel that contains all other
editors
*/
private final FlowPanel container = new FlowPanel();
private final ListEditor<DataProviderProxy, DataProviderEditor>
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, DataProviderEditor>
asEditor() {
return editor;
}
}