日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/5/22 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 How do I open an editor on something that is not a file? 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

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


?

轉(zhuǎn)載于:https://my.oschina.net/dollyn/blog/360634

總結(jié)

以上是生活随笔為你收集整理的How do I open an editor on something that is not a file?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。