GWT编辑器框架 [英] GWT Editor framework

查看:138
本文介绍了GWT编辑器框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



正常的工作流程是:

有没有办法获得编辑器正在编辑的代理? pre> 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);




$ b现在如果我得到了相同代理的子编辑器

  public class AntoherClass implements Editor< Proxy> {
someMethod(){
//获得编辑代理?


$ / code>

是的,我知道我可以将代理设置为使用setProxy()创建后的子编辑器,但是我想知道是否有类似于HasRequestContext的内容,但是用于编辑后的代理。



当您使用ListEditor



谢谢。

您可以获取给定编辑器正在处理的对象的引用。首先,一些简单的数据和一个简单的编辑器:

  public class MyModel {
// sub properties ...

}

公共类MyModelEditor实现了Editor< MyModel> {
//子属性编辑器...

}

首先:我们可以选择另一个扩展Editor的接口,而不是实现 Editor ,但允许子编辑器( LeafValueEditor 不允许子编辑器)。让我们试试 ValueAwareEditor

  public class MyModelEditor2实现了ValueAwareEditor< MyModel> {
//子属性编辑器...

// ValueAwareEditor方法:
public void setValue(MyModel value){
//这将会自动调用当
// driver.edit被调用时的当前值。
} $ b $ public void flush(){
//如果你打算做任何修改,请在这里执行,当驱动程序刷新时,这称为
//。
}
public void onPropertyChange(String ... paths){
//在你的情况下可能不需要,但允许通知
//当子属性更改时 - 主要到目前为止由RequestFactory使用。
}
public void setDelegate(EditorDelegate< MyModel> delegate){
//授予对委托的访问权限,所以属性更改事件可以被请求,其中包括。可能不需要。




$ b $ p
$ b

这要求你实现各种方法,如上面的例子,但你感兴趣的主要是 setValue 。你不需要自己调用这些,他们将被司机及其代表调用。如果您计划对对象进行更改,则 flush 方法也很适用 - 在刷新之前进行这些更改意味着您正在修改预期的驱动程序生命周期之外的对象第二:使用 SimpleEditor 子编辑器 - 不是世界末日,但可能会让你感到惊讶。

  public class MyModelEditor2实现了ValueAwareEditor< MyModel> {
//子属性编辑器...

//一个额外的子属性:
@Path()//绑定到MyModel本身
SimpleEditor self = SimpleEditor.of();

// ...
}

你可以调用 self.getValue()来读出当前值是什么。



编辑: AnotherEditor 你已经实现了,看起来你已经开始像GWT类 SimpleEditor 一样,尽管你可能会还需要其他子编辑器:


现在,如果我得到了相同代理的子编辑器,那么

  public class AntoherClass implements Editor< Proxy> {
someMethod(){
//获取编辑代理的方法?
}
}


编辑器可以实现 ValueAwareEditor< Proxy> 而不是 Editor< Proxy> ,并保证它的 setValue 方法将在编辑开始时使用代理实例调用。


Is there a way to get the proxy that editor is editing?

The normal workflow would be:

 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 got a subeditor of the same proxy

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

Yes i know i can just set the proxy to the Child editor with setProxy() after its creation, but i want to know if there is something like HasRequestContext but for the edited proxy.

This usefull when you use for example ListEditor in non UI objects.

Thank you.

解决方案

Two ways you can get a reference to the object that a given editor is working on. First, some simple data and a simple editor:

public class MyModel {
  //sub properties...

}

public class MyModelEditor implements Editor<MyModel> {
  // subproperty editors...

}

First: Instead of implementing Editor, we can pick another interface that also extends Editor, but allows sub-editors (LeafValueEditor does not allow sub-editors). Lets try 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.
  }
}

This requires that you implement the various methods as in the example above, but the main one you are interested in will be setValue. You do not need to invoke these yourself, they will be called by the driver and its delegates. The flush method is also good to use if you plan to make changes to the object - making those changes before flush will mean that you are modifying the object outside of the expected driver lifecycle - not the end of the world, but might surprise you later.

Second: Use a SimpleEditor sub-editor:

public class MyModelEditor2 implements ValueAwareEditor<MyModel> {
  // subproperty editors...

  // one extra sub-property:
  @Path("")//bound to the MyModel itself
  SimpleEditor self = SimpleEditor.of();

  //...
}

Using this, you can call self.getValue() to read out what the current value is.

Edit: Looking at the AnotherEditor you've implemented, it looks like you are starting to make something like the GWT class SimpleEditor, though you might want other sub-editors as well:

Now if i got a subeditor of the same proxy

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

This sub-editor could implement ValueAwareEditor<Proxy> instead of Editor<Proxy>, and be guaranteed that its setValue method would be called with the Proxy instance when editing starts.

这篇关于GWT编辑器框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆