有两种方法可以获取给定编辑器正在处理的对象的引用。首先,一些简单的数据和简单编辑:
public class MyModel {
//sub properties...
}
public class MyModelEditor implements Editor<MyModel> {
// subproperty editors...
}
第一:无需实现Editor
的,我们可以挑选也延伸编辑器,但允许子编辑器的另一个接口(LeafValueEditor
不允许亚编辑)。让我们试着ValueAwareEditor
:
public class MyModelEditor2 implements ValueAwareEditor<MyModel> {
// subproperty editors...
// ValueAwareEditor methods:
public void setValue(MyModel value) {
// This will be called automatically with the current value when
// driver.edit is called.
}
public void flush() {
// If you were going to make any changes, do them here, this is called
// when the driver flushes.
}
public void onPropertyChange(String... paths) {
// Probably not needed in your case, but allows for some notification
// when subproperties are changed - mostly used by RequestFactory so far.
}
public void setDelegate(EditorDelegate<MyModel> delegate) {
// grants access to the delegate, so the property change events can
// be requested, among other things. Probably not needed either.
}
}
这需要你实现的各种方法,如上面的例子,但主要一个你感兴趣的将是setValue
。你不需要自己调用这些,他们将被司机及其代表调用。如果您打算更改对象,那么flush
方法也很好用 - 在刷新之前进行这些更改意味着您要在预期的驱动程序生命周期之外修改对象 - 而不是世界末日,但可能会在稍后出现意外。
二:使用SimpleEditor
副主编:
public class MyModelEditor2 implements ValueAwareEditor<MyModel> {
// subproperty editors...
// one extra sub-property:
@Path("")//bound to the MyModel itself
SimpleEditor self = SimpleEditor.of();
//...
}
利用这一点,你可以调用self.getValue()
读出电流值是什么。
编辑:看着你已经实现了AnotherEditor
,它看起来像你已经开始做类似的GWT SimpleEditor
类,尽管你可能在想其他子编辑器,以及:如果我
现在得到了相同的代理服务器的副主编
public class AntoherClass implements Editor<Proxy>{
someMethod(){
// method to get the editing proxy ?
}
}
这个副主编可以实现ValueAwareEditor<Proxy>
代替Editor<Proxy>
,并保证其setValue
米编辑开始时,将使用Proxy实例调用ethod。
是的它的工作原理,我只需要实现ValueAwareEditor和setValue自动设置代理。从API“编辑器的行为会根据所编辑的值进行更改,以实现此界面。”那是我的情况。 =) –
2012-04-14 00:12:24
感谢Colin的帮助(特别是@Path(“”):我被诱惑做了@Path(“this”),但那需要特殊的处理......) 现在我想知道如何根据数据值从编辑器切换到另一个编辑器。我有一个选择框应该改变形式(许多常见的领域,但布局和一些领域appaer /消失)。我为每种类型都有一个UiBinder,我想在用户选择时从一个切换到另一个。我不喜欢根据情况创建它们并使其可见或不可见的想法。我想创建一个新的编辑器并对其进行归类 – 2014-06-12 10:09:21