use of org.eclipse.ui.internal.registry.PerspectiveRegistry in project netxms by netxms.
the class ApplicationActionBarAdvisor method importPerspective.
/**
* Import perspective
* @param window
*/
private void importPerspective(final IWorkbenchWindow window) {
FileDialog fd = new FileDialog(window.getShell());
// $NON-NLS-1$ //$NON-NLS-2$
fd.setFilterExtensions(new String[] { "*.xml", "*.*" });
fd.setFilterNames(new String[] { Messages.get().ApplicationActionBarAdvisor_XMLFiles, Messages.get().ApplicationActionBarAdvisor_AllFiles });
fd.setText(Messages.get().ApplicationActionBarAdvisor_ImportPerspective);
final String fileName = fd.open();
if (fileName == null)
return;
if (!MessageDialogHelper.openConfirm(window.getShell(), Messages.get().ApplicationActionBarAdvisor_ConfirmRestart, Messages.get().ApplicationActionBarAdvisor_RestartConfirmationMessage))
return;
new ConsoleJob(Messages.get().ApplicationActionBarAdvisor_ImportPerspective, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
FileReader reader = null;
try {
reader = new FileReader(fileName);
final XMLMemento memento = XMLMemento.createReadRoot(reader);
runInUIThread(new Runnable() {
@Override
public void run() {
try {
Perspective p = ((WorkbenchImplementation) Tweaklets.get(WorkbenchImplementation.KEY)).createPerspective(null, (WorkbenchPage) window.getActivePage());
p.restoreState(memento);
PerspectiveRegistry reg = (PerspectiveRegistry) window.getWorkbench().getPerspectiveRegistry();
PerspectiveDescriptor pd = reg.createPerspective(p.getDesc().getLabel(), (PerspectiveDescriptor) p.getDesc());
WorkbenchPage page = (WorkbenchPage) window.getActivePage();
page.savePerspectiveAs(pd);
p = page.findPerspective(pd);
p.restoreState(memento);
p.restoreState();
window.getWorkbench().showPerspective(pd.getId(), window);
page.savePerspective();
PlatformUI.getWorkbench().restart();
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Exception in importPerspective", e);
MessageDialogHelper.openError(window.getShell(), Messages.get().ApplicationActionBarAdvisor_Error, Messages.get().ApplicationActionBarAdvisor_PerspectiveImportFailed);
}
}
});
} finally {
if (reader != null)
reader.close();
}
}
@Override
protected String getErrorMessage() {
return Messages.get().ApplicationActionBarAdvisor_PerspectiveImportFailed;
}
}.start();
}
Aggregations