2012-04-13 4 views
5

エディタが編集中のプロキシを取得する方法はありますか?GWTエディタフレームワーク

通常のワークフローは次のようになります。私は、同じプロキシのsubeditor

public class AntoherClass implements Editor<Proxy>{ 
    someMethod(){ 
    // method to get the editing proxy ? 
    } 
} 

を得た場合

public class Class implments Editor<Proxy>{ 
    @Path("") 
    @UiField AntoherClass subeditor; 


    void someMethod(){ 
    Proxy proxy = request.create(Proxy.class); 
    driver.save(proxy); 
    driver.edit(proxy,request); 
} 
} 

は今、はい私はちょうどsetProxy(児エディタにプロキシを設定することができます知っています)を作成した後、HasRequestContextのようなものがあるかどうかを知りたいのですが、編集されたプロキシのためです。

これは、たとえばUI以外のオブジェクトでListEditorを使用する場合に便利です。

ありがとうございます。

答えて

7

与えられたエディタが作業しているオブジェクトへの参照を取得するには、2通りの方法があります。まず、いくつかの単純なデータや簡易エディタ:まず

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のようなものを作るために始めているように見える、実装しました見てみます同じプロキシのsubeditor

public class AntoherClass implements Editor<Proxy>{ 
    someMethod(){ 
    // method to get the editing proxy ? 
    } 
} 

このsubeditorはValueAwareEditor<Proxy>代わりのEditor<Proxy>を実装することができ、そしてそのsetValueメートルことが保証さを得ました編集開始時にProxyインスタンスでethodが呼び出されます。

+0

はい、それは動作しますが、私はちょうどValueAwareEditor を実装し、setValueのは自動的にプロキシを設定する必要があります。 APIから "編集中の値に基づいて動作が変更される編集者は、このインターフェースを実装します。"それは私の場合です。 =) –

+0

このヘルプのためのコリンありがとうございました。(私は@Path( "")のためにespacially:@Path( "this")をやるように誘惑されましたが、特別な扱いが必要でした...) データ値に応じてエディタから別のエディタに切り替える方法を知っている。フォームを変更する必要のある選択ボックスがあります(多くの一般的なフィールドがありますが、レイアウトやいくつかのフィールドがappaer/disappear)。私は各タイプのUiBinderを持っていますが、私はユーザーの選択で1つから別のものに切り替えたいと思います。私はそれらをすべて作り、状況に応じてそれらを見えるようにするという考えが好きではありません。新しいエディタを作成してそれを属性にしたい –

0

This is the only solution I found。ドライバの編集を呼び出す前にコンテキスト編集を呼び出す必要があります。次に、後で操作するプロキシがあります。

2

子エディタクラスでは、別のインタフェースTakesValueを実装するだけで、編集用プロキシをsetValueメソッドで取得できます。

ValueAwareEditorも機能しますが、あなたが本当に必要としない余分な方法があります。

関連する問題