Skip to main content



      Home
Home » Eclipse Projects » Eclipse Scout » MessageBox shows with quite a delay
MessageBox shows with quite a delay [message #1384202] Wed, 28 May 2014 07:46 Go to next message
Eclipse UserFriend
Hi folks

I discovered an issue with a slow loading MessageBox. It takes about 3s to show the dialog.
The questionable part about the whole thing is, that the same MessageBox will show "normally" fast when opened through a slightly different way.

Description of the issue:

The ominous MessageBox is called within an execValidateValue method inside a Field of a Form.
The value can be changed by user input or programmatically while opening the Form from a TablePage.
If the value of the Field is changed through user input, the MessageBox will show with quite a delay.
Though when the value of the Field is changed programmatically when opening the Form, the MessageBox will show without any delay.

I wrote some sample code, so it might be easier to track the issue down. The order of the events is almost equal to the production code, though very simplified but with the same ominous results.

The Form:
public class TestForm extends AbstractForm {

  private Integer data;

  public TestForm() throws ProcessingException {
    super();
  }

  public void startModify() throws ProcessingException {
    startInternal(new ModifyHandler());
  }

  public MainBox getMainBox() {
    return getFieldByClass(MainBox.class);
  }

  public NummerField getNummerField() {
    return getFieldByClass(NummerField.class);
  }

  @Order(10.0)
  public class MainBox extends AbstractGroupBox {

    @Order(10.0)
    public class NummerField extends AbstractIntegerField {

      @Override
      protected Integer execValidateValue(Integer rawValue) throws ProcessingException {
        MessageBox.showYesNoCancelMessage("theres", "nothingto", "seehere");
        return rawValue;
      }
    }

    @Order(20.0)
    public class CancelButton extends AbstractCancelButton {
    }
  }

  public class ModifyHandler extends AbstractFormHandler {
    @Override
    protected void execLoad() throws ProcessingException {
      importData();
    }
  }

  public void setData(Integer data) {
    this.data = data;
  }

  private void importData() {
    getNummerField().setValue(data);
  }
}


The calling method from the TablePage:
    @Order(20.0)
    public class BearbeitenMenu extends AbstractMenu {

      ...

      @Override
      protected void execAction() throws ProcessingException {
        TestForm form = new TestForm();
        form.setData(2);
        form.startModify();
        form.waitFor();
      }
    }


Thanks in advance for any help.

Best wishes,
Pascal
Re: MessageBox shows with quite a delay [message #1384327 is a reply to message #1384202] Wed, 28 May 2014 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Welcome on the scout forum and tanks for your question.

I could reproduce the problem you are describing (Luna-RC1, SWT and Swing UI, Windows 7).
I did also try it in the execChangedValue() method of the IntegerField [what would be a much more common pattern in a Scout Application] and I did also notice the delay.

It needs more investigations.

Re: MessageBox shows with quite a delay [message #1384662 is a reply to message #1384327] Fri, 30 May 2014 02:19 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jeremie,

Thanks a lot for your fast reply and also for looking into it.
We have this issue with scout 3.9, SWT and Windows7.

Best wishes,
Pascal
Re: MessageBox shows with quite a delay [message #1419132 is a reply to message #1384662] Mon, 08 September 2014 02:17 Go to previous messageGo to next message
Eclipse UserFriend
Bug 443421 was created
Re: MessageBox shows with quite a delay [message #1514395 is a reply to message #1419132] Wed, 17 December 2014 04:03 Go to previous messageGo to next message
Eclipse UserFriend
Ok - you faced one of Scout's holy code parts.
The reason for this behavior is to have kind of a well ordered event flow. The UI (SWT and others) write their value back to the model async on any change (see org.eclipse.scout.rt.ui.swt.form.fields.SwtScoutBasicFieldComposite.handleSwtInputVerifier(). This is usually triggered by a focus traverse event. If now the value change triggers a disable/enable of the next field in the tab order (focus order) the cursor would be traversed to the next enabled field before the value change of the first field is executed. What ends up in having the focus on wrong fields or even worse on disabled fields. So Scout decided to make the UI waiting for a certain time (2345 ms) to ensure the value change is executed at least in 99% of all cases. The reason for not waiting for ever is to provide a cancellation support.
Now the link to your issue is that you are adding a message box to the desktop during a value change execution. The message box gets immediately added to the desktop and fires an event which is handled of the UI. Since the UI thread is waiting for the value changed execution a delay of 2345ms occurs.

Nevertheless I was taking a serious look at your issue and I'm not able to provide a fix for this behavior without changing some base concepts of Scout which is obviously not an option since you will have tons of other issues after.

As a workaround/solution the message box must be shown async after the validation has finished. This is achieved using a ClientSyncJob. Furthermore on the first run of the validation the original value is returned to not enforce too many property change events. After the message box is shown the value is set to the model using the setValue method. The fancy part with the valueChangeInternal method override to make the value accessible during the validation process will be obsolete with the Luna SR2 release.

@Order(10.0)
public class IntegerField extends AbstractIntegerField {

  private Integer m_localValue;
  /**
   * The guard is used to ensure the message box is not shown in an infinite loop
   */
  private AtomicBoolean m_guard = new AtomicBoolean(false);

  /**
   * This method is currently needed since the getValue is blocked during a validation process.
   */
  @Override
  protected void valueChangedInternal() {
    super.valueChangedInternal();
    m_localValue = getValue();
  }

  @Override
  protected Integer execValidateValue(final Integer rawValue) throws ProcessingException {
    if (!m_guard.get()) {
      new ClientSyncJob("", ClientSyncJob.getCurrentSession()) {
        @Override
        protected void runVoid(IProgressMonitor monitor) throws Throwable {
          if (MessageBox.showYesNoCancelMessage("theres", "nothingto", "seehere") == IMessageBox.YES_OPTION) {
            try {
              m_guard.set(true);
              setValue(rawValue);
            }
            finally {
              m_guard.set(false);
            }
          }
        }
      }.schedule();

      // ensure the old value is returned
      return m_localValue;
    }
    return rawValue;
  }
}


Hope I was able to help you...
/andreas
Re: MessageBox shows with quite a delay [message #1547207 is a reply to message #1384202] Mon, 05 January 2015 04:45 Go to previous message
Eclipse UserFriend
First of all, happy new year! Smile

Thanks a lot for your commitment on this issue!
When I applied this solution to our application, i'll report back if it works as intended in our environment.

Best regards,
Pascal
Previous Topic:Mars version: Make 'bean based TableData' the new default for table fields.
Next Topic:Perspectives
Goto Forum:
  


Current Time: Thu Jul 03 11:53:17 EDT 2025

Powered by FUDForum. Page generated in 0.08162 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top