`
Dollyn
  • 浏览: 165569 次
  • 性别: 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");


分享到:
评论

相关推荐

    Go Modules.docx

    Should I still add a 'go.mod' file if I do not have any dependencies? Should I commit my 'go.sum' file as well as my 'go.mod' file? FAQs — Semantic Import Versioning Why must major version numbers ...

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

    Unix编程常见问题解答 高清PDF含书签目录

    2.4 How can I find out if someone else has a file open? 我怎么知道其他人已经打开一个文件? 2.5 How do I `lock' a file? 我怎样锁定一个文件? 2.6 How do I find out if a file has been updated by another ...

    How to Read and Do Proofs: An Introduction to Mathematical Thought Processes

    How to Read and Do Proofs also explains when each technique is likely to be used, based on certain key words that appear in the problem under consideration. Doing so enables students to choose a ...

    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.

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

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

    (2009 Springer)Software Verification and Analysis:An Integrated, Hands-On Approach

    ) “How to do it right,” I still do not know how to go about it with any degree of certainty! It appears then I probably should stop right now, for who with a modicum of common sense would reach for ...

    大学体验英语答案(完整版)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, ...

    Windows.File.System.Troubleshooting.1484210174

    The Windows file system is large and complex, featuring not only a huge number of essential files and folders for the Windows OS, your software and hardware, but also several different underlying file...

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

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

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

    iphone h.264 live encode 实时 硬编码

    I’ve written an example application that demonstrates how to do this, as part of an RTSP server that streams H264 video from the iPhone or iPad camera to remote clients. The end-to-end latency, ...

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

Global site tag (gtag.js) - Google Analytics