欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-24 14:26:55
...

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:


  
How do I open an editor on something that is not a file?   class  StringStorage  extends  PlatformObject 
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?    
implements  IStorage  ... {
How do I open an editor on something that is not a file?      
private String string;
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      StringStorage(String input) 
...{this.string = input;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public InputStream getContents() throws CoreException ...{
How do I open an editor on something that is not a file?         
return new ByteArrayInputStream(string.getBytes());
How do I open an editor on something that is not a file?      }

How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public IPath getFullPath() ...{return null;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public String getName() ...{
How do I open an editor on something that is not a file?         
int len = Math.min(5, string.length());
How do I open an editor on something that is not a file?         
return string.substring(0, len).concat("...");
How do I open an editor on something that is not a file?      }

How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public boolean isReadOnly() ...{return true;}
How do I open an editor on something that is not a file?   }

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

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:


  
How do I open an editor on something that is not a file?    class  StringInput  extends  PlatformObject 
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?    
implements  IStorageEditorInput  ... {
How do I open an editor on something that is not a file?      
private IStorage storage;
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      StringInput(IStorage storage) 
...{this.storage = storage;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public boolean exists() ...{return true;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public ImageDescriptor getImageDescriptor() ...{return null;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public String getName() ...{
How do I open an editor on something that is not a file?         
return storage.getName();
How do I open an editor on something that is not a file?      }

How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public IPersistableElement getPersistable() ...{return null;}
How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public IStorage getStorage() ...{
How do I open an editor on something that is not a file?         
return storage;
How do I open an editor on something that is not a file?      }

How do I open an editor on something that is not a file?How do I open an editor on something that is not a file?      
public String getToolTipText() ...{
How do I open an editor on something that is not a file?         
return "String-based file: " + storage.getName();
How do I open an editor on something that is not a file?      }

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

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

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:


  
How do I open an editor on something that is not a file?   IWorkbenchWindow window  =  ...;
How do I open an editor on something that is not a file?   String string 
=   " This is the text file contents " ;
How do I open an editor on something that is not a file?   IStorage storage 
=   new  StringStorage(string);
How do I open an editor on something that is not a file?   IStorageEditorInput input 
=   new  StringInput(storage);
How do I open an editor on something that is not a file?   IWorkbenchPage page 
=  window.getActivePage();
How do I open an editor on something that is not a file?   
if  (page  !=   null )
How do I open an editor on something that is not a file?      page.openEditor(input, 
" org.eclipse.ui.DefaultTextEditor " );
How do I open an editor on something that is not a file?
How do I open an editor on something that is not a file?

 

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