Jump to: navigation, search

Difference between revisions of "FAQ How do I open an editor programmatically?"

(See Also:)
(See Also:)
Line 16: Line 16:
 
*[[FAQ How do I find the active workbench page?]]
 
*[[FAQ How do I find the active workbench page?]]
 
*[[FAQ How do I open an editor on a file in the workspace?]]
 
*[[FAQ How do I open an editor on a file in the workspace?]]
 +
*[[FAQ Can I make a job run in the UI thread?]]
  
 
{{Template:FAQ_Tagline}}
 
{{Template:FAQ_Tagline}}

Revision as of 23:49, 24 October 2006

Use the openEditor methods on org.eclipse.ui.IWorkbenchPage to open an editor on a given input. The openEditor methods require you to supply the ID of the editor to open. You can use the editor registry to find out what editor ID is appropriate for a given file name, using the getDefaultEditor method on IEditorRegistry. In Eclipse 3.0, the editor opening methods that were specific to IFile were moved to the IDE class.

   IWorkbenchPage page = ...;
   IFile file = ...;
   IEditorDescriptor desc = PlatformUI.getWorkbench().
      getEditorRegistry().getDefaultEditor(file.getName());
   page.openEditor(
      new FileEditorInput(file),
      desc.getId());

This code needs to run on the UI thread and result from getActiveWorkbenchWindow() and getActivePage() need to be checked against null.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.