Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » SavePerspectiveAction does not work in eclipse 4.2
SavePerspectiveAction does not work in eclipse 4.2 [message #1066648] Wed, 03 July 2013 10:43 Go to next message
Eclipse UserFriend
I am trying to migrate my RCP app from eclipse 3.6 to 4.2.
I focus on the feature "Save perspective as ..." and try to use SavePerspectiveAction class.

Following code is the part of my implementation in view action.
This code worked fine in eclipse 3.6 but does not work in eclipse 4.2.

org.eclipse.ui.internal.SavePerspectiveAction savePerspective = new org.eclipse.ui.internal.SavePerspectiveAction(window);
savePerspective.run();


I analyzed eclipse source code,
and I found that the method 'run' in SavePerspectiveAction is not implemented (comment out) in eclipse 4.2.

org.eclipse.ui.internal.SavePerspectiveAction (eclipse 4.2)
    /* (non-Javadoc)
     * Method declared on PerspectiveAction.
     */
    protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) {
        PerspectiveDescriptor desc = (PerspectiveDescriptor) persp;
        if (desc != null) {
			// saveNonSingleton(page, desc);
        }
    }


org.eclipse.ui.internal.SavePerspectiveAction (eclipse 3.6)
    /* (non-Javadoc)
     * Method declared on PerspectiveAction.
     */
    protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) {
        PerspectiveDescriptor desc = (PerspectiveDescriptor) persp;
        if (desc != null) {
            if (desc.isSingleton()) {
                saveSingleton(page);
            } else {
                saveNonSingleton(page, desc);
            }
        }
    }


Please tell me how to implement the feature "Save perspective as ..." in eclipse 4.2.
Re: SavePerspectiveAction does not work in eclipse 4.2 [message #1067275 is a reply to message #1066648] Mon, 08 July 2013 03:56 Go to previous message
Eclipse UserFriend
I tried to implement this feature and write following code.
In my environment, this code works fine.

This is a quick note to report.

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
	@Override
	public void run(IAction action) {
		//org.eclipse.ui.internal.SavePerspectiveAction savePerspective = new org.eclipse.ui.internal.SavePerspectiveAction(
		//		window);
		//savePerspective.run();

		IWorkbenchPage page = window.getActivePage();
		PerspectiveDescriptor descriptor = (PerspectiveDescriptor) page.getPerspective();
		
		// Get reg.
		PerspectiveRegistry reg = (PerspectiveRegistry) WorkbenchPlugin.getDefault()
				.getPerspectiveRegistry();

		// Get persp name.
		SavePerspectiveDialog dlg = new SavePerspectiveDialog(window.getShell(),
				reg);
		// Look up the descriptor by id again to ensure it is still valid.
		IPerspectiveDescriptor description = reg.findPerspectiveWithId(descriptor.getId());
		dlg.setInitialSelection(description);
		if (dlg.open() != IDialogConstants.OK_ID) {
			return;
		}

		// Create descriptor.
		PerspectiveDescriptor newDesc = (PerspectiveDescriptor) dlg.getPersp();
		if (newDesc == null) {
			String name = dlg.getPerspName();
			newDesc = reg.createPerspective(name, (PerspectiveDescriptor) description);
			if (newDesc == null) {
				MessageDialog.openError(dlg.getShell(),
						WorkbenchMessages.SavePerspective_errorTitle,
						WorkbenchMessages.SavePerspective_errorMessage);
				return;
			}
		}

		// Save state.
		page.savePerspectiveAs(newDesc);
	}

Previous Topic:How do I add a Problem filter?
Next Topic:[Kepler] saveState and restoreState of WorkbenchAdvisor not called
Goto Forum:
  


Current Time: Tue Apr 15 03:32:08 EDT 2025

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

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

Back to the top