Non-restorable views

Yesterday I was hit with the requirement to not restore/set to be hidden certain views after workbench restart. Unfortunately this isn’t supported in the current (latest) incarnation of the org.eclipse.ui.views EP, though it shouldn’t be too hard to extend the EP schema. But since changing org.eclipse.ui code isn’t a short term solution anyway, I reverted to a poor mans version of an EP (btw. thanks to pwebster for inspiration). Basically the RCP checks for a given substring in all secondary ids of open ViewReferences in the WorkbenchWindowAdvisor#postWindowCreate startup hook. The implementation is pretty much straight forward:

// do not restore certain views whose secondary view ID contains "NO_RESTORE"
IWorkbenchPage[] pages = getWindowConfigurer().getWindow().getPages();
for(int i = 0; i < pages.length; i++) {
	IWorkbenchPage workbenchPage = pages[i];
	IViewReference[] viewReferences = workbenchPage.getViewReferences();
	for(int j = 0; j < viewReferences.length; j++) {
		IViewReference viewReference = viewReferences[j];
		String secondaryId = viewReference.getSecondaryId();
		if(secondaryId != null && secondaryId.contains("NO_RESTORE")) {
			workbenchPage.hideView(viewReference);
		}
	}
}

To define a view to be non-restorable is done by concatenating "NO_RESTORE" into the secondary view id string.

Hard coding the view id in WorkbenchWindow#postWindowCreate is a bad alternative, because it unnecessarily separates the view properties from the bundle hosting the view. Also it makes the RCP bundle specific for certain views. It's IMO simply the wrong location. Personally I find this functionality important enough to be included, so I've create Bug #215797. If you agree, please give it a vote.

The next item on my todo list, is to get rid of unwanted “Show View” shortcuts, because leaning back waiting for 3.4 to hit the road unfortunately isn’t an option. :(

5 Responses to Non-restorable views »»


comments

  1. Comment by Remy Chi Jian Suen | 2008/01/18 at 17:50:06

    You should be able to replace the PlatformUI.getWorkbench().getActiveWorkbenchWindow() call with the slightly cleaner getWindowConfigurer().getWindow().

  2. Comment by Tom Schindl | 2008/01/18 at 21:19:54

    Why no doing it the other way round (closing them before the workbench exists)

  3. Comment by markus | 2008/01/18 at 21:22:11

    I’ve thought about that too but came to the conclusion that an abnormal workbench shutdown wouldn’t close them correctly. Thus it’s simply safer to hide them at startup.

  4. Comment by Tom Schindl | 2008/01/18 at 21:52:08

    … I’m not sure that’s a problem when the workbench exits abnormally the View-State isn’t save anyway, not?

  5. Comment by markus | 2008/01/20 at 12:33:29

    What happens if one saves the perspective manually? It would be necessary to extend that code too, to not safe the non-restorable views.


leave a reply »»