Eclipse Scout回调,用于在字段中输入值 [英] Eclipse Scout callback for entering value in fields

查看:232
本文介绍了Eclipse Scout回调,用于在字段中输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当用户在字段中设置值时是否启动一个函数,而在字段中程序设置值时是否触发该函数.

I would like to know if there is a function that fires up when user set value in field but not if program set value in field.

如此功能:

user click on field 'myField and change value -> method fires up
in program : myField.setValue = SomeValue; -> method doesn't fires up.

问题在于循环检测.如果您的逻辑是您有4个字段,并尝试检测这些字段中是否有任何更改,然后触发更改这些字段中某些值的方法:

problem is with loop detection. If your logic is that you have 4 field and try to detect if any of those fields are changed and then fire method for change some values inside those fields :

@Override
protected void execChangedValue() throws ProcessingException {
  super.execChangedValue();
  valueFieldsChange(this);
}

protected void valueInPriceBoxFieldsChange(AbstractValueField field) {
    ... calculate some values in those fields....
}

我得到:

!MESSAGE org.eclipse.scout.rt.client.ui.form.fields.AbstractValueField.setValue(AbstractValueField.java:338) Loop detection in...

所以我知道方法execChangedValue()不是我想要的.是否有类似的方法具有解释的行为?

So I know the method execChangedValue() are not what I am looking for. Is there similar method with explained behavior ?

Marko

推荐答案

让我们先说循环检测在90%的情况下很有用. 当您位于execChangedValue()中并尝试更新同一字段的值时,将显示警告.

Let start to say that loop detection is useful in 90% of the cases. The warning is displayed when you are inside an execChangedValue() and you try to update the value of the same field.

如果我正确地理解了您的示例,那么您的字段内有

If I understand your example correctly you have inside your field:

public class FirstField extends AbstractStringField {

  @Override
  protected void execChangedValue() throws ProcessingException {
    calculateNewValues();
  }
}

方法:

public void calculateNewValues() {
  //some logic to compute the new values: value1, value2, value3

  getFirstField().setValue(value1);
  getSecondField().setValue(value2);
  getThirdField().setValue(value3);
}

这时,您确实需要确保当用户将FirstField中的值设置为某些值时,您可能希望实用地将其更改为其他值.这可能会使用户感到困惑.

At this point, you really need to be sure that when the user sets the value in the FirstField to something, you might want to change it pragmatically to something else. This might be really confusing for the user.

如果您确定需要更新值,则可以使用一种方法来设置值而无需在字段上触发execChangedValue().我已经提出了一种新方法:Eclipse Scout表单上的setValueWithoutChangedValueTrigger(T value):

If you are sure that you need to update the value, there is a way to set a value without triggering execChangedValue() on the field. I have proposed a new method: setValueWithoutChangedValueTrigger(T value) on the Eclipse Scout Form: Controlling if execChangedValue() is called or not.

在论坛上,您会找到一个片段,您可以将其添加到您的字段中(或在通用模板中:AbstractMyAppStringField).

On the forum you will find a snippet that you can add to your field (or in a common template: AbstractMyAppStringField).

public class FirstField extends AbstractStringField {

  @Override
  protected void execChangedValue() throws ProcessingException {
    calculateNewValues();
  }

  public void setValueWithoutValueChangeTrigger(String value) {
    try {
      setValueChangeTriggerEnabled(false);
      setValue(value);
    }
    finally {
      setValueChangeTriggerEnabled(true);
    }
  }
}

您将可以使用它:

public void calculateNewValues() {
  //some logic to compute the new values: value1, value2, value3

  getFirstField().setValueWithoutChangedValueTrigger(value1);
  getSecondField().setValueWithoutChangedValueTrigger(value2);
  getThirdField().setValueWithoutChangedValueTrigger(value3);
}

我希望这会有所帮助.

这篇关于Eclipse Scout回调,用于在字段中输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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