Note that there are some explanatory texts on larger screens.

plurals
  1. POGWT Editors - how to add N sub-editors of the same type based on a Collection
    text
    copied!<p>I have an object, <code>Supply</code>, that can either be an <code>ElecSupply</code> or <code>GasSupply</code> (<a href="https://stackoverflow.com/questions/13346308/how-to-implement-gwt-editors-for-subclasses-of-a-type">see related question</a>).</p> <p>Regardless of which subclass is being edited, they all have a list of <code>BillingPeriod</code>s.</p> <p>I now need to instantiate N number of <code>BillingPeriodEditor</code>s based on the contents of that list, and am pretty baffled as to how I should do it.</p> <p>I am using GWTP. Here is the code of the <code>SupplyEditor</code> I have just got working:</p> <pre><code>public class SupplyEditor extends Composite implements ValueAwareEditor&lt;Supply&gt; { private static SupplyEditorUiBinder uiBinder = GWT.create(SupplyEditorUiBinder.class); interface SupplyEditorUiBinder extends UiBinder&lt;Widget, SupplyEditor&gt; { } @Ignore final ElecSupplyEditor elecSupplyEditor = new ElecSupplyEditor(); @Path("") final AbstractSubTypeEditor&lt;Supply, ElecSupply, ElecSupplyEditor&gt; elecSupplyEditorWrapper = new AbstractSubTypeEditor&lt;Supply, ElecSupply, ElecSupplyEditor&gt;( elecSupplyEditor) { @Override public void setValue(final Supply value) { setValue(value, value instanceof ElecSupply); if(!(value instanceof ElecSupply)) { showGasFields(); } else { showElecFields(); } } }; @Ignore final GasSupplyEditor gasSupplyEditor = new GasSupplyEditor(); @Path("") final AbstractSubTypeEditor&lt;Supply, GasSupply, GasSupplyEditor&gt; gasSupplyEditorWrapper = new AbstractSubTypeEditor&lt;Supply, GasSupply, GasSupplyEditor&gt;( gasSupplyEditor) { @Override public void setValue(final Supply value) { setValue(value, value instanceof GasSupply); if(!(value instanceof GasSupply)) { showElecFields(); } else { showGasFields(); } } }; @UiField Panel elecPanel, gasPanel, unitSection; public SupplyEditor() { initWidget(uiBinder.createAndBindUi(this)); gasPanel.add(gasSupplyEditor); elecPanel.add(elecSupplyEditor); } // functions to show and hide depending on which type... @Override public void setValue(Supply value) { if(value instanceof ElecSupply) { showElecFields(); } else if(value instanceof GasSupply) { showGasFields(); } else { showNeither(); } } } </code></pre> <p>Now, as the list of BillingPeriods is a part of any Supply, I presume the logic for this should be in the SupplyEditor.</p> <p>I got some really good help on the thread <a href="https://groups.google.com/forum/?fromgroups=#!topic/gwt-platform/PWJTu1il2VY" rel="nofollow noreferrer"><strong>How to access PresenterWidget fields when added dynamically</strong></a>, but that was before I had implemented the Editor Framework at all, so I think the logic is in the wrong places.</p> <p>Any help greatly appreciated. I can post more code (Presenter and View) but I didn't want to make it too hard to read and all they do is get the Supply from the datastore and call edit() on the View.</p> <p>I have had a look at some <a href="http://c.gwt-examples.com/home/ui/listeditor" rel="nofollow noreferrer">examples of ListEditor</a> but I don't really get it!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload