# HG changeset patch # User dadubrow # Date 1279110685 18000 # Node ID ead82fb31f27545ffe1aff5059b6a28243686410 # Parent 6bd46a8909890c9064c5eaca336928d18b7ac98a add utility to open an editor diff -r 6bd46a890989 -r ead82fb31f27 core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/WorkbenchUtils.java --- a/core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/WorkbenchUtils.java Tue Jul 13 15:35:51 2010 -0500 +++ b/core/com.nokia.cpp.utils.ui/src/com/nokia/cpp/internal/api/utils/ui/WorkbenchUtils.java Wed Jul 14 07:31:25 2010 -0500 @@ -195,6 +195,48 @@ } /** + * Open and provide an editor with the given input and id. + * @param input + * @param editorId + * @return IEditorPart + * @throws PartInitException + */ + public static IEditorPart openEditor(final IEditorInput input, final String editorId) throws PartInitException { + final IEditorPart[] parts = { null } ; + final PartInitException ex[] = { null }; + Display.getDefault().syncExec(new Runnable() { + + public void run() { + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); + if (workbenchWindow == null) { + if (workbench.getWorkbenchWindowCount() == 0) + return; + workbenchWindow = workbench.getWorkbenchWindows()[0]; + } + IWorkbenchPage page = workbenchWindow.getActivePage(); + if (page == null) { + if (workbenchWindow.getPages().length == 0) + return; + page = workbenchWindow.getPages()[0]; + } + IEditorPart editor; + try { + editor = page.openEditor(input, editorId); + } catch (PartInitException e) { + ex[0] = e; + return; + } + parts[0] = editor; + } + + }); + if (ex[0] != null) + throw ex[0]; + return parts[0]; + } + + /** * Open an external browser and go to the given URL. * Note this function must be called in UI thread. *