Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I open an editor on a file outside the workspace?"

 
m
Line 1: Line 1:
''
+
You can open a read-only editor on a file outside the workspace by creating your own implementation of <tt>IStorage</tt> and <tt>IStorageEditorInput</tt> for the file.  Alternatively, you can create a <i>linked resource</i> in an existing project, which points to a file elsewhere in the file system.  This example snippet creates a project called &#147;External Files,&#148; 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:
  
You can open a read-only editor on a file outside the workspace by
 
creating your own implementation of <tt>IStorage</tt> and <tt>IStorageEditorInput</tt>
 
for the file.  Alternatively, you can create a <i>linked resource</i> in an existing
 
project, which points to a file elsewhere in the file system.  This example snippet
 
creates a project called &#147;External Files,&#148; 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:
 
 
<pre>
 
<pre>
 
   IWorkspace ws = ResourcesPlugin.getWorkspace();
 
   IWorkspace ws = ResourcesPlugin.getWorkspace();
Line 29: Line 21:
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ How do I accommodate project layouts that don't fit the Eclipse model?]]
 +
*[[FAQ How do I open an editor programmatically?]]
 +
*[[FAQ How do I open an editor on something that is not a file?]]
  
[[FAQ_How_do_I_accommodate_project_layouts_that_don%26%23146%3Bt_fit_the_Eclipse_model%3F]]
+
{{Template:FAQ_Tagline}}
 
+
[[FAQ_How_do_I_open_an_editor_programmatically%3F]]
+
 
+
[[FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Revision as of 20:01, 29 May 2006

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 &#147;External Files,&#148; 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())
      project.create(null);
   if (!project.isOpen())
      project.open(null);
   Shell shell = window.getShell();
   String name = new FileDialog(shell, SWT.OPEN).open();
   if (name == null)
      return;
   IPath location = new Path(name);
   IFile file = project.getFile(location.lastSegment());
   file.createLink(location, IResource.NONE, null);
   IWorkbenchPage page = window.getActivePage();
   if (page != null)
      page.openEditor(file);

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.

Back to the top