Eclipse selection and when to process or not

I heard from a user of the Attachment Viewer today that when a large ZIP was selected the client appeared to hang.  He explained that the attachment viewer was not even showing yet it looks like it still processed the selection.  Well, he was right.  After looking at the code, it was actually processing the ZIP file every time – whether the viewer was showing or not.  So I made a simple change and he is checking it out (testing it for me).  I did my small unit tests but I figured giving him a patch and testing his large ZIP file attachment would also be good – a second set of tests is always welcome in software.  🙂

So what did I do?

In the selectionChanged() event I had to determine if the view was visible or open.  This was an interesting problem because the view itself does not contain this state.  What I had to do was register the view with the workbench as an IPartListener2.  Why the “2” and not just IPartListener?  The key event we need is actually partHidden()!

The description of the event is here:

Notifies this listener that the given part is hidden or obscured by another part.

What I do is have a class level property named “_closed” and set it to true or false in the different events for IPartListener2.  This allows me to not process the selection if its “_closed” and just return out of the selectionChanged() callback.

I scoured the SWT and Eclipse world and I could not see another way to do this so if anyone has any input please let me know.  I will be updated the OpenNTF project with the fix in a few days.  I am sure one of the Eclipse guru’s reading would know if this is correct or not.

4 thoughts on “Eclipse selection and when to process or not

  1. Hi Bob,

    I had the same issue of too much processing happening on selection in an RCP application, again due to views that were not currently visible. However, we solved it with a similar approach, but different calls:

    getSite().getPage().isPartVisible(viewPart)

    In our case we stash the last selection we are notified about so that when the view is reactivated we can update the display accordingly.

    Cheers!

    James

    Like

  2. Pingback: The power of a community » Balfes.net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s