Bug 5687 - [Editor Mgmt] [RCP] A generic way to create IEditorInput instances for an IAdaptable
Summary: [Editor Mgmt] [RCP] A generic way to create IEditorInput instances for an IAd...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2001-11-08 17:02 EST by Cagatay Kavukcuoglu CLA
Modified: 2012-06-20 10:44 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cagatay Kavukcuoglu CLA 2001-11-08 17:02:07 EST
In Eclipse, editor inputs are used to represent things that can be opened in an 
editor. However, there is not a well defined, general way of creating an editor 
input instance. As a result, it is not possible write plugins capable of 
opening any type of "input" in an editor programmatically. Most visibly, it is 
not possible to provide a generic "open selection in an editor" functionality 
without resorting to plugin specific API's - see 
org.eclipse.jdt.ui.JavaUI.openInEditor(IJavaElement). It would be better if any 
IAdaptable instance was able to provide a "IEditorInputProvider" instance using 
the adapter mechanism, which would in turn be used to create a new editor 
input. Here is some possible code:

public interface IEditorInputProvider {
    IEditorInput createEditorInput(Object obj);
    String getDefaultEditorId();
}

public class MyInputProvider implements IEditorInputProvider {
  IEditorInput createEditorInput(Object obj) {
      if (!(item instanceof MyItem))
          return;
      return new MyItemInput((MyItem) item);
  }
  
  String getDefaultEditorId() {
      return "my.editor.id";
  }
  

Then, when you have a selection,

IStructuredSelection selection = ...;
IAdaptable element = (IAdaptable) selection.getFirstElement();
IEditorInputProvider provider = (IEditorInputProvider) element.getAdapter(
    IEditorInputProvider.class);
    
IWorkbenchPage page = ...; // get the active page
page.openInEditor(provider.createEditorInput(element), 
provider.getDefaultEditorId());

I hope this makes sense...
Comment 1 Kevin Haaland CLA 2001-11-12 13:55:35 EST
This is an interesting idea. Any implementation for this need to ensure that
plugins do not get eagerly loaded and we do not defeat the resource change 
listeners in Core. 

Agree that this is a P3 enhancement. 
Comment 2 Nick Edgar CLA 2003-12-15 00:21:06 EST
I've been thinking of something along these lines.
I think we need an open-ended mechanism for mapping from an arbitrary object to 
an editor input and/or editor id.
Using IAdaptable as above is one possibility.  An extension point to allow 
pluggable strategies for this is another.
Comment 3 Nick Edgar CLA 2003-12-15 12:30:33 EST
See bug 47600 for an interesting use case.
Comment 4 Nick Edgar CLA 2004-09-20 12:32:51 EDT
See also bug 74263.  It seems like the editor input chosen should be a function
of the editor too.  We can't limit this to just the default editor case.
Comment 5 Nick Edgar CLA 2006-03-15 11:24:09 EST
Reassigning bugs in component areas that are changing ownership.
Comment 6 Boris Bokowski CLA 2009-11-26 16:14:43 EST
Prakash is now responsible for watching bugs in the [RCP] component area.