特定のエディターが作業しているオブジェクトへの参照を取得する2つの方法。まず、いくつかの単純なデータと単純なエディター:
public class MyModel {
//sub properties...
}
public class MyModelEditor implements Editor<MyModel> {
// subproperty editors...
}
まず、を実装する代わりにEditor、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メソッドは、オブジェクトに変更を加える予定がある場合にも使用できます。フラッシュの前にこれらの変更を行うと、予想されるドライバーのライフサイクルの外でオブジェクトを変更することになります。世界の終わりではありませんが、後で驚かれる可能性があります。
2番目: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インスタンスで呼び出されることが保証されます。