I need to customize my RCP Application and the usage of perspectives a bit. In particular, I want to provide a custom menu item that lets the user save the current perspective, but WITHOUT showing the built-in Dialog:
So I don't want to use the default eclipse way to register the "Save Perspective" Action and put it into the menu. Ie, I don't want to do that:
@Override
protected void makeActions(IWorkbenchWindow window)
{
// ...
register(ActionFactory.SAVE_PERSPECTIVE.create(window));
// ...
}
@Override
protected void fillMenuBar(IMenuManager menuBar)
{
// ...
windowMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));
// ...
}
So, if I write a custom Action, what do I need to do there to save the current perspective?
It's fairly simple. In the custom Action I do the following to save the perspective:
IWorkbenchPage page = window.getActivePage();
IPerspectiveRegistry perspectiveRegistry = window.getWorkbench()
.getPerspectiveRegistry();
IPerspectiveDescriptor personalPerspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
if (page != null && personalPerspectiveDescriptor != null) {
// ... other stuff like different confirm dialogs
page.savePerspectiveAs(personalPerspectiveDescriptor);
}
A nice example of how to use perspectives for letting the user customize their layouts without showing too much of the built-in perspective functionality can be found here:
http://www.subshell.com/en/subshell/blog/article-Eclipse-RCP-Change-Your-Perspective100.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.