Jump to: navigation, search

FAQ How do I open an editor on a file outside the workspace?

Revision as of 15:32, 14 March 2006 by Claffra (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You can open a read-only editor on a file outside the workspace by creating your own implementation of IStorage and IStorageEditorInput for the file. Alternatively, you can create a linked resource in an existing project, which points to a file elsewhere in the file system. This example snippet creates a project called “External Files,” and then prompts the user to select any file in the file system. The code then creates a linked resource in the project to that external file, allowing the platform to open the file in read/write mode in one of the standard editors:

   IWorkspace ws = ResourcesPlugin.getWorkspace();
   IProject project = ws.getRoot().getProject("External Files");
   if (!project.exists())
   if (!project.isOpen())
   Shell shell = window.getShell();
   String name = new FileDialog(shell, SWT.OPEN).open();
   if (name == null)
   IPath location = new Path(name);
   IFile file = project.getFile(location.lastSegment());
   file.createLink(location, IResource.NONE, null);
   IWorkbenchPage page = window.getActivePage();
   if (page != 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.