转自EclipseFAQ
Since 3.3 you can use the new EFS support to open an text editor on a file store that's backed by any kind of EFS using IDE.openEditorOnFileStore(page, fileStore)
.
Most editors will accept as input either an IFileEditorInput or an IStorageEditorInput. The former can be used only for opening files in the workspace, but the latter can be used to open a stream of bytes from anywhere. If you want to open a file on a database object, remote file, or other data source, IStorage is the way to go. The only downside is that this is a read-only input type, so you can use it only for viewing a file, not editing it. To use this approach, implement IStorage so that it returns the bytes for the file you want to display. Here is an IStorage that returns the contents of a string:
class StringStorage extends PlatformObject
implements IStorage ...{
private String string;
StringStorage(String input) ...{this.string = input;}
public InputStream getContents() throws CoreException ...{
return new ByteArrayInputStream(string.getBytes());
}
public IPath getFullPath() ...{return null;}
public String getName() ...{
int len = Math.min(5, string.length());
return string.substring(0, len).concat("...");
}
public boolean isReadOnly() ...{return true;}
}
The class extends PlatformObject to inherit the standard implementation of IAdaptable, which IStorage extends. The getName and getFullPath methods can return null if they are not needed. In this case, we've implemented getName to return the first five characters of the string.
The next step is to create an IStorageEditorInput implementation that returns your IStorage object:
class StringInput extends PlatformObject
implements IStorageEditorInput ...{
private IStorage storage;
StringInput(IStorage storage) ...{this.storage = storage;}
public boolean exists() ...{return true;}
public ImageDescriptor getImageDescriptor() ...{return null;}
public String getName() ...{
return storage.getName();
}
public IPersistableElement getPersistable() ...{return null;}
public IStorage getStorage() ...{
return storage;
}
public String getToolTipText() ...{
return "String-based file: " + storage.getName();
}
}
Again, many of the methods here are optional. The getPersistable method is used for implementing persistence of your editor input, so the platform can automatically restore your editor on start-up. Here, we've implemented the bare essentials: the editor name, and a tool tip.
The final step is to open an editor with this input. This snippet opens the platform's default text editor on a given string:
IWorkbenchWindow window = ...;
String string = "This is the text file contents";
IStorage storage = new StringStorage(string);
IStorageEditorInput input = new StringInput(storage);
IWorkbenchPage page = window.getActivePage();
if (page != null)
page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
分享到:
相关推荐
AdvancedWebBrowser.zip Advanced web browser..something like IE but less options really nice interface..code is very easy to understand..teaches you the basics of using vb.<END><br>54 , iusage.zip...
if you wish to search something on several partitions of a hard disk at the same time, or if a partition is damaged or formatted with a file system unknown to Windows, so Windows is unable to make it ...
<END><br>45,PlayAVI.zip PlayAVI.ocx is an activeX control which allows you to play an AVI file on a form. A sample application is provided with the control. <END><br>46,FldrView.zip The ...
Disassembler/Debug: Fixed the address that is being edited when a breakpoint hits while editing an instruction Assembler: Fixed assembling reg*2/4/8+unquotedsymbol Plugin: Fixed the SDK for C plugins ...
A simulare file can be a included 'include files' but can be also an older version of the script with intact names or some already recoved + manual improved with more meaningful function names. ...
ICS V7 is a stable release that may still be updated for major bugs, but not for new releases of Delphi, latest it supported was XE3. ICS V8 is the current development release which is held in a ...
eric5 contains a plugin system, that is used to extend eric5's functionality. Some plugins are part of eric5. Additional plugins are available via the Internet. Please use the built in plug-in ...
that if something didn't make sense then it didn't deserve a default binding, the user can define these themselves. We also reviewed other editors complete default keybinding sets to find ...
After generating your Xcode project open Info.plist file and right-click on it and click “Add row”. Then enter two required two keys with descriptions. In the end it should look like it: Android ...
messagebox.showinfo("About", "This is a simple example of a window") help_menu.add_command(label="About", command=show_about) ``` #### 八、文件打开、保存与另存 文件操作是任何文本编辑器的基本功能之...
- **示例**:`on error "File not found." number -10000`…`end try`. **8.3 AppleScript中的错误** - **错误类型**:如文件不存在、权限不足等。 - **错误处理**:通过检查错误代码来确定错误原因并采取相应行动...