Last week I posted an entry about Eclipse selection and when a view part should or should not process the selection. I showed a pattern to use the IPartListener2 model as described in my post. James Fry (no link provided) showed what now believe to be a much cleaner way to do this. The reason its cleaner is because you are not on the part listener list and called every time and its a one liner! No overhead of a boolean and your code to evaluate in the listener callback is now gone. Much nicer!
Here was the code I ended up using:
if (viewer.getSite().getPage().isPartVisible(viewer) == false)
You should see this in the next release of the Attachment Viewer on OpenNTF.
Thanks James for being a reader and more importantly adding value to my blog!
One thing you may want to consider is when your view is re-opened or maximized you might want to restore the last selection so having a listener may be your only option in the end.