Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Restoring View Positions(How can I restore views at a dedicated position)
Restoring View Positions [message #808014] Mon, 27 February 2012 09:45 Go to next message
Andreas K is currently offline Andreas KFriend
Messages: 3
Registered: June 2011
Junior Member
Hi,

my RCP application creates and disposes views programmatically. This means that I shut down my views before the workbench performs a shutdown. Restoring the views by the workbench makes no sense to me, because important context information needs to be passed to the view, that the workbench does not know.

My question: If the user drags a view to a specific position, how can I get that position information, store it, and pass this information to the view on the next start of the view, to obtain the same position again?

Could anyone give me a hint, how that could be achieved? Actually the workbench somehow does the same with standard views.

Thanks and regards,

Andreas
Re: Restoring View Positions [message #811346 is a reply to message #808014] Fri, 02 March 2012 08:18 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 211
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi Andreas,
I am not sure if it really makes sense to do something on your own that the workbench would do for you anyway. Maybe it is because I do not see the problem with the context information. Is it that you are not able to provide this context information while the workbench is comming up? Then you could as well display some temporary content in your views and update the content when the context is available.
Anyway - my experience is, that the workbench stores the viewposition also if you close the view manually. I have checked that with the two simple actions below. Wherever you drag the outline view, after closing it, next time it is opened at the last position. So maybe you don't even have to store the information yourself?

Regards,
Thorsten

public class CloseOutlineView implements IWorkbenchWindowActionDelegate {

@Override
public void run(IAction action) {
	
	IWorkbenchPage page = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage();
	IViewReference[] viewRefs = page.getViewReferences();
	if (viewRefs != null) {
		for (IViewReference ref : viewRefs) {
			if (IPageLayout.ID_OUTLINE.equals(ref.getId())) {
				page.hideView(ref);
			}
		}
	}
}

@Override
public void selectionChanged(IAction action, ISelection selection) {
	// TODO Auto-generated method stub

}

@Override
public void dispose() {
	// TODO Auto-generated method stub

}

@Override
public void init(IWorkbenchWindow window) {
	// TODO Auto-generated method stub

}

}


public class OpenOutlineView implements IWorkbenchWindowActionDelegate {

	@Override
	public void run(IAction action) {
		try {
			PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(IPageLayout.ID_OUTLINE);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init(IWorkbenchWindow window) {
		// TODO Auto-generated method stub

	}

}
Re: Restoring View Positions [message #815202 is a reply to message #811346] Wed, 07 March 2012 10:55 Go to previous message
Andreas K is currently offline Andreas KFriend
Messages: 3
Registered: June 2011
Junior Member
Thorsten,

thank you for your prompt reply. Actually your answer and code example pointed me into the right direction. What I did not wrote in my description caused the problem in my application. I pass the view context information by using a secondary view id. This secondary view id was always different from the last time I opened the view. I now found out, that the workbench stores the view position in a file called workbench.xml under the plugin org.eclipse.ui.workbench. Here the view identifier is stored together with the secondary identifier. If they do not match, the view position is assumed unknown and therefore the view is started with default position.

I now changed my secondary identifier handling to be reproducible on opening the view. And it works perfectly.

Thanks again, this gives a usablity boost to my application!

best regards

Andreas

additional remark to others who might read this:
To enable restoring in general you need to overwrite the following method in class ApplicationWorkbenchAdvisor of your RCP application

	@Override
	public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
		configurer.setSaveAndRestore(true);
	}

Previous Topic:Dynamic contribution to the Tabbed property view
Next Topic:Plugin extensions save failed
Goto Forum:
  


Current Time: Sun Dec 21 12:17:12 GMT 2014

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

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