为什么80%的码农都做不了架构师?>>>   

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


转载于:https://my.oschina.net/dollyn/blog/360634

How do I open an editor on something that is not a file?相关推荐

  1. 紫光同创国产FPGA学习之Physical Constraint Editor

    从紫光的参考书拷贝的.很详细.他们要写那么详细,好辛苦啊. 一.       功能介绍 (一)   PCE简介 该文档详细描述了Physical Constraint Editor(以后简称PCE)的 ...

  2. ueditor与七牛云存储结合

    2019独角兽企业重金招聘Python工程师标准>>> 摘要:  ueditor与七牛云存储结合,主要是表单api. ueditor上传图片到七牛云存储 ueditor结合七牛传图片 ...

  3. Fckeditor常见漏洞的挖掘与利用整理汇总

    查看编辑器版本号 FCKeditor/_whatsnew.html ------------------------------------------------------------- 2. V ...

  4. phpstorm 10 修改背景图片和字体

    修改menu:File ~ Settings ~ Appearance & Behavior ~ Appearance ~ Theme 改成 Darcula即成黑色背景 menu字体大小: 编 ...

  5. 如何配置Keil 外部编辑器?

    是否可以对Keil配置使用外部的编辑器呢? How to use vscode as the external editor of Keil 5? The latest version of Keil ...

  6. [No000077]打造自己的Eclipse

    下载官网的Eclipse IDE for Java EE Developers 在根目录下的eclipse.ini文件中添加"-Dfile.encoding=UTF-8", 作用: ...

  7. Sublime Text 2 和 Verilog HDL

    Sublime Text 2 和 Verilog HDL Date  Fri 04 July 2014 Tags Sublime Text / Vivado Sublime Text 代码编辑器之于程 ...

  8. Linux内核如何装载和启动一个可执行程序

    李洋  原创作品转载请注明出处 <Linux内核分析>MOOC课程 首先简单介绍一下相关背景:ELF(Executable and Linking Format)是一种对象文件的格式,用于 ...

  9. Linux下的ELF可执行文件学习总结

    Linux下的ELF可执行文件的格式解析 http://blog.csdn.net/xuchao1229/article/details/8915831 目录(?)[+] ELF(Executable ...

最新文章

  1. 2011寒假-操作系统学习笔记
  2. FPGA设计者的5项基本功
  3. dw替换多个html标签,DW查找替换的技巧
  4. oracle32位客户端安装教程,Win7系统32位Oracle11g客户端安装详述
  5. 应用层协议:HTTPS
  6. 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序。假设压入栈的所有数字均不相等。
  7. 经验分享 | ENVI app store
  8. 如何用计算机基础知识提问,职业学校《计算机应用基础》课的提问策略
  9. 【编程题】【Scratch四级】2021.03 程序优化
  10. EasyRTMPLive:RTMP流媒体直播软件应用解决方案流媒体直播软件应用
  11. winform程序内存不足或假死的问题
  12. 【2022】年度总结——彼此当年少 莫负好时光
  13. 完美兼容MIC5203-3.3BM5的高压LDO-CSM5133SE/CSM5130SE
  14. python装饰器带参数函数二阶导数公式_SICP Python 描述 1.6 高阶函数
  15. 清华数据女神评选结果:第一竟然是叉院大神...?
  16. STM32入门开发: 制作红外线遥控器(智能居家-万能遥控器)
  17. C# 递归的应用 TreeView递归绑定数据
  18. 黑马程序员Javaweb学习笔记01
  19. 中机云告诉你,云计算有这10大好处|中机智库
  20. 本科以下请注意!在职低学历直升本科!免试入学,无需到校,灵活在岗就读,名额有限,速看!...

热门文章

  1. 记录一次阿里架构师全程手写Spring MVC
  2. tcp和udp的区别?
  3. AJAX的post请求与上传文件
  4. 为 Hyper-V 配置外部网络
  5. 计蒜客 时间复杂度 (模拟) 洛谷 P3952 时间复杂度
  6. tomcat和resin的安装配置
  7. Jersey 入门与Javabean
  8. Mac 新建unix可执行文件
  9. dll窗体的创建与调用
  10. 2011软件设计大赛