0

I am working on an eclipse RCP project. It has several views with TreeViewer and I use selectionChanged() method to handle selection events. However, at times I need to set selection programmatically.For this, in selectionChanged() method, I invoke setSelection() method of TreeViewer to set the desired selection. This method fires selectionChanged() method of all views thus resulting in cyclic calls to selectionChanged().

How can I select an item from the TreeViewer or StructuredViewer without firing selectionChanged() for other views?

Baz
  • 36,440
  • 11
  • 68
  • 94
SaurabhJinturkar
  • 554
  • 7
  • 20
  • Any feedback to my answer? – Baz Jun 18 '14 at 15:05
  • 1
    @Baz Good to know there are people facing similar problems. I thought I am doing something wrong. I have used similar structure in my application. Since it has many views handling selections using booleans becomes quite unmanageable. Eclipse should take a note of this. – SaurabhJinturkar Jun 20 '14 at 04:58

1 Answers1

3

Well, creating an event that triggers the Listener you're currently in is always a tricky situation. What I usually do is something along those lines:

Listener listener = new Listener()
{
    private boolean ignore = false;

    @Override
    public void handleEvent(Event e)
    {
        if(ignore)
            return;

        ignore = true;
        doPotentiallyCyclicStuff();
        ignore = false;
    }
};

It's not a very pretty solution, but it does work.


Looking forward to alternative solutions here, since this has been bothering me for a while now.

Baz
  • 36,440
  • 11
  • 68
  • 94