`
Dollyn
  • 浏览: 168684 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

How do I open an editor on something that is not a file?

 
阅读更多

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");


分享到:
评论

相关推荐

    How is logging implemented in OSS?

    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 ...

    深入浅出javascript

    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 ...

    UNIX编程常见问题解答

    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 us

    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.

    三年级英语句型专项练习.pdf

    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 dra

    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制作简单的游戏

    silence on the wire

    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,...

    Hacker's Guide to Scaling Python

    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, ...

    UE(官方下载)

    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 ...

    Hands-On Machine Learning with Scikit-Learn and TensorFlow PDF

    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 ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    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. ...

    大学体验英语答案(完整版)level 3

    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, ...

    libgcc_s_dw2-1.dll另一种版本

    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\...

    Intergraph Standard File Formats (Element Structure)

    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...

    tc英文版,c语言的经典学习工具,1M而已

    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_0.7RC1

    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 ...

    iPhone Open Application Development.chm

    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 ...

Global site tag (gtag.js) - Google Analytics