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:
classStringStorageextendsPlatformObject
implementsIStorage...{
privateStringstring;
StringStorage(Stringinput)...{this.string=input;}
publicInputStreamgetContents()throwsCoreException...{
returnnewByteArrayInputStream(string.getBytes());
}
publicIPathgetFullPath()...{returnnull;}
publicStringgetName()...{
intlen=Math.min(5,string.length());
returnstring.substring(0,len).concat("...");
}
publicbooleanisReadOnly()...{returntrue;}
}
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:
classStringInputextendsPlatformObject
implementsIStorageEditorInput...{
privateIStoragestorage;
StringInput(IStoragestorage)...{this.storage=storage;}
publicbooleanexists()...{returntrue;}
publicImageDescriptorgetImageDescriptor()...{returnnull;}
publicStringgetName()...{
returnstorage.getName();
}
publicIPersistableElementgetPersistable()...{returnnull;}
publicIStoragegetStorage()...{
returnstorage;
}
publicStringgetToolTipText()...{
return"String-basedfile:"+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:
IWorkbenchWindowwindow=...;
Stringstring="Thisisthetextfilecontents";
IStoragestorage=newStringStorage(string);
IStorageEditorInputinput=newStringInput(storage);
IWorkbenchPagepage=window.getActivePage();
if(page!=null)
page.openEditor(input,"org.eclipse.ui.DefaultTextEditor");
分享到:
相关推荐
Method: In this paper, we carried out an empirical study to explore the logging practice in open source software projects so as to establish a basic understanding on how logging practice is applied ...
Do you believe that a technical book can’t be serious if JavaScript code is anthropomorphized? 3 This book makes a great sequel to Head First HTML with CSS & XHTML, so definitely check it out if you ...
1.2.1 How can I get/set an environment variable from a program? 1.2.2 How can I read the whole environment? 1.3 How can I sleep for less than a second? 1.4 How can I get a finer-grained version of...
This is an example of how to return all of the files on a users system. This can be easily edited to be close to the normal Windows’ Find File or Folder Dialog.
3. That is a fat sheep. 改为:Is that a fat sheep? 肯定回答:Yes, it is. 4. She is a good girl. 改为:Is she a good girl? 肯定回答:Yes, she is. 5. They are boys. 改为:Are they boys? 肯定回答:Yes, ...
Heres an example on how to make a single game chunk that draws with the paint object. Kinda like a little more advanced hello world制作简单的游戏
I do not have the background you might expect from the usual computer security specialist, a profession that is becoming commonplace today. I have never received any formal computer science education,...
Python is an excellent programming language that allows to write applications quickly. But how do you make those applications scale for thousands of users and requests? It takes years of practice, ...
We are often asked if it is possible to run an UltraEdit macro or script on a file from the command line. The answer is yes - and it's not only possible, it's extremely simple! Using find/replace ...
Not exactly a self-aware Skynet, but it does technically qualify as Machine Learning (it has actually learned so well that you seldom need to flag an email as spam anymore). It was followed by ...
Do not forget that a -inl.h file requires a #define guard just like any other header file. Function Parameter Ordering link ▶When defining a function, parameter order is: inputs, then outputs. ...
1 "Lu Yi: How do you do? Dick: How do you do? Lu Yi: My name is Lu Yi. Dick: I'm Richard Green. Please call me Dick. Lu Yi: Glad to meet you. Dick: Nice to meet you, too." 2 "Zhou Ming: Excuse me, ...
If that does not help your problem, place the file to your system directory. By default, this is C:\Windows\System (Windows 95/98/Me), C:\WINNT\System32 (Windows NT/2000), or C:\Windows\...
No, but there is a document that tries to indicate how to properly draw DGN elements given the structures returned by DGNLib. The OGR layer re-interprets the drawing information into OGR Feature Style...
How do I run Turbo C? A. After you have installed Turbo C, type "TC" from the DOS prompt and you're ready to go. Chapter 2 (Getting Started) of the Turbo C User's Guide will guide you through your...
PAM-MySQL is licensed under GNU Public License and I heard that GPL requires the program that links to a GPL'ed shared binary object at runtime also being covered by GPL. Is it safe to use PAM-MYSQL ...
Thousands of programmers want to provide applications on the iPhone, and this book shows you how to achieve the spectacular effects that made the device an immediate hit. You'll learn how to use an ...
Do not open manual file from a network path or directly from the package otherwise help pages may not be displayed due to security restrictions. Copy the file to a local drive before opening. Please ...