Since 3.3 you can use the new EFS support to open an text editor on a file outside the workspace:
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()) 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);
发表于 @ 2008年03月03日 10:52:00|评论(loading...)|编辑