【发布时间】:2012-11-16 15:45:55
【问题描述】:
我有一个对象Supply,它可以是ElecSupply 或GasSupply (see related question)。
无论正在编辑哪个子类,它们都有一个BillingPeriods 列表。
我现在需要根据该列表的内容实例化 N 个 BillingPeriodEditors,但我不知道该怎么做。
我正在使用 GWTP。这是我刚刚开始工作的SupplyEditor 的代码:
public class SupplyEditor extends Composite implements ValueAwareEditor<Supply>
{
private static SupplyEditorUiBinder uiBinder = GWT.create(SupplyEditorUiBinder.class);
interface SupplyEditorUiBinder extends UiBinder<Widget, SupplyEditor>
{
}
@Ignore
final ElecSupplyEditor elecSupplyEditor = new ElecSupplyEditor();
@Path("")
final AbstractSubTypeEditor<Supply, ElecSupply, ElecSupplyEditor> elecSupplyEditorWrapper = new AbstractSubTypeEditor<Supply, ElecSupply, ElecSupplyEditor>(
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<Supply, GasSupply, GasSupplyEditor> gasSupplyEditorWrapper = new AbstractSubTypeEditor<Supply, GasSupply, GasSupplyEditor>(
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();
}
}
}
现在,由于 BillingPeriods 列表是任何 Supply 的一部分,我认为其逻辑应该在 SupplyEditor 中。
我在线程 How to access PresenterWidget fields when added dynamically 上得到了一些非常好的帮助,但那是在我完全实现编辑器框架之前,所以我认为逻辑在错误的地方。
非常感谢任何帮助。我可以发布更多代码(Presenter 和 View),但我不想让它太难阅读,他们所做的只是从数据存储中获取 Supply 并在 View 上调用 edit()。
我看过一些examples of ListEditor,但我真的不明白!
【问题讨论】:
标签: java gwt gwt-editors