GWT Editor Basics

Is there any way to get the proxy editable by the editor?

Normal workflow:

 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);
 }
}

Now, if I have a sub-editor of the same proxy

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

Yes, I know that I can just set the proxy for the Child editor using setProxy () after creating it, but I want to know if there is something like HasRequestContext, but for the edited proxy.

This is useful if you use, for example, ListEditor in objects without an interface.

Thank.

+5
source share
3 answers

Two ways to get a link to the object that this editor is working on. Firstly, some simple data and a simple editor:

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 .

+7

TakesValue, - setValue.

ValueAwareEditor , , .

+2

This is the only solution I have found . It includes a context edit call before you invoke driver editing. Then you have a proxy for later manipulation.

0
source

All Articles