// Get reg.
PerspectiveRegistry reg = (PerspectiveRegistry) WorkbenchPlugin
.getDefault().getPerspectiveRegistry();
// Get persp name.
SavePerspectiveDialog dlg = new SavePerspectiveDialog(page.getWorkbenchWindow()
.getShell(), reg);
// Look up the descriptor by id again to ensure it is still valid.
IPerspectiveDescriptor description = reg.findPerspectiveWithId(oldDesc.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;
}
}