Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to monitor ViewPart close button event
How to monitor ViewPart close button event [message #899469] Wed, 01 August 2012 05:01 Go to next message
Timm Baumeister is currently offline Timm BaumeisterFriend
Messages: 14
Registered: July 2012
Junior Member
I am using an rcp application build on 3.72. I have a custom menu with checkitems for each of my views. The user can close views either by unckecking them in the menu or by using the close widget of the view.

My problem is that I need to update the state of the checkitems when the close widget is used, so I need to monitor this event. I looked at IPartListener2, but the partClosed never gets called. Instead partDeactivated and partHidden get called, which however also get called in many different situations so I can't use them. I can't believe that such a central user interface concept has no api exposure.

I am willing to simply iterate through all my views and check for their state but the next problem is that I can't figure out how to get this state. Apparently eclipse keeps the views open in the background even if they are not any longer visible in the tabfolder. Is there a way to distinguish this state (not closed but not visible) from hidden but with the title of the view still visible in the tabfolder?

Any suggestions would be welcome.

Timm
Re: How to monitor ViewPart close button event [message #899476 is a reply to message #899469] Wed, 01 August 2012 06:03 Go to previous message
Timm Baumeister is currently offline Timm BaumeisterFriend
Messages: 14
Registered: July 2012
Junior Member
I found the answer in a bug report.

IPartListener2 shows some strange behavior:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=54559

The suggested workaround is to use findViewReference in partDeactivated or partHidden. Unfortunately it isn't working either because it returns a non null value if used within these functions. It's necessary to wait a little before doing the call, i.e. package it in a runnable which waits for 200ms.


final id = /** ID of my view **/
IPartListener2 listener = new IPartListener2() {

	@Override
	public void partActivated(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partBroughtToTop(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partClosed(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partDeactivated(final IWorkbenchPartReference partRef) {
		if (!id.equals(partRef.getId()))
			return;
		if (!(partRef.getPart(false) instanceof IViewPart))
		    return;
		final IViewPart vp = (IViewPart)partRef.getPart(false);
		Display.getDefault().asyncExec(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
				}
				if (vp.getSite()!=null && vp.getSite().getPage()!=null) {
					if (vp.getSite().getPage().findViewReference(partRef.getId())==null)
						/******  MY VIEW REALLY GOT CLOSED! ******/;
				}
			}
		});
	}

	@Override
	public void partOpened(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partHidden(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partVisible(IWorkbenchPartReference partRef) {
	}

	@Override
	public void partInputChanged(IWorkbenchPartReference partRef) {
	}

};
page.addPartListener(listener);


[Updated on: Wed, 01 August 2012 12:14]

Report message to a moderator

Previous Topic:[SOLVED] java was started but returned exit code=13
Next Topic:Java Training
Goto Forum:
  


Current Time: Fri Mar 29 15:23:57 GMT 2024

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

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

Back to the top