Search code examples
eclipseeclipse-rcpjfaceeclipse-pde

How to tell user events from synthetic events?


I have a JFace editor that is mostly made up of a TreeViewer. This is hooked up to a ContentOutlinePage to bring the Outline view to life.

When either one receives a SelectionChangedEvent they call the others setSelection() method ... and therein lies the problem. setSelection() generates another SelectionChangedEvent ... and thus the infinite loop is joined.

Is there a means of telling if the SelectionChangedEvent was created by actual user interaction rather than by another object calling setSelection()?

Is there a better means still of stopping this sort of deadly-embrace?

Clues welcomed.


Solution

  • Generally, you would check a flag in the beginning of the routine to check to see if you are in the middle of the event handler. If the flag is set, then you exit without processing.

    If the flag is not set, you set the flag, process, then set the flag back.