Summary: | [Editor Mgmt] Make IEditorReference adaptable | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] Platform | Reporter: | Jared Burns <jared_burns> | ||||
Component: | UI | Assignee: | Eduardo Pereira <eduardo_pereira> | ||||
Status: | RESOLVED WORKSFORME | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | n.a.edgar | ||||
Version: | 2.0 | ||||||
Target Milestone: | --- | ||||||
Hardware: | Other | ||||||
OS: | All | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Jared Burns
2002-08-30 10:20:21 EDT
I'd be happy to contribute the code for this change. Having this bug up in the air is preventing me from sharing the latest editor view code. Created attachment 1927 [details]
editoradapter.patch - A patch containing the change
A slight change to my request: Since the API on IEditorReference says that it is not intended to be implemented by clients, making it extend IAdaptable actually doesn't break any API rules. Instead of adding IAdaptable on the private editor reference implementation, it would be better to add it to the IEditorReference declaration. I undestand it is a simple change and it would take me 30 seconds to apply and release it but I am not convinded yet it is a good change. I now it enables you to add a "cool" feature to the editors view but I am concerned about the feature as well and I would like to test the view since it may become part of the platform and then address this PR again. I don't undestand IAdaptable 100% but the idea of implementing IAdaptable in one class so some other component may register adaptable for that object does not look right. Questions: 1) What happens if I have an editor that edits a set (> 1) of resources. 2) What happens if it does not edit a resource. Is my submission not being integrated because of a problem? If so, please let me know so I can address it. If you prefer to provide the adapter for IResource directly in the editor implementation, let me know and I'll change the submission. We are analising the editor managment again and we hope to get to a conclusion soon. So I am not doing any work on any PR related to the editors view. About this PR: There is not a map "1 to 1" between editors and resources so making it adaptable may not be the right answer. I mean "what happens if may editor edits more that one file at the same time". So adding the Team menu to the editors view may not have a easy solution but if you realy want it you can wrap the IEditorReference with some adaptable object before adding them to your view. IEditorReference cannot provide an adapter to IResource for three reasons: 1. the editor may present multiple files (as Eduardo points out above) 2. the editor may not be materialized yet, so the reference doesn't even know the editor input 3. the basic workbench support should not have dependencies on Core Resources However, note that IEditorInput already supports IAdaptable. Both getAdapter (IFile.class) and getAdapter(IResource.class) work for FileEditorInputs. Currently you could wrap the editor reference with your own object that delegates getAdapter to the editor's input. However, for this to work the editor has to already be materialized. Noted, thanks. Marking as worksforme. I'll try out the suggestions here. Actually, I'm curious as to how you got it to work at all with the code snippet in your original request. Here you're looking up adapters registered against EditorManager$Editor, which implements IEditorReference. So this will find adapters that register against IEditorReference. But nobody does this. Or did you do something else? I registered the adapter from my code. In case you're curious, here's the registration code: // TODO: Remove this code which checks for the IAdaptable // interface on IEditorReference once Bug 23032 is resolved. Class classes[]= IEditorReference.class.getInterfaces(); for (int i= 0, numClasses= classes.length; i < numClasses; i++) { if (classes[i].equals(IAdaptable.class)) { // Only needs to be run once - Belongs in UI Plugin startup()? Platform.getAdapterManager().registerAdapters(new EditorAdapterFactory(), IEditorReference.class); } } And here's the adapter code: /** * The adapter factory which the editor list view uses to get the IResource * associated with an IEditorReference. */ public class EditorAdapterFactory implements IAdapterFactory { public Object getAdapter(Object adaptableObject, Class adapterType) { if (adaptableObject instanceof IEditorReference) { if (IResource.class.equals(adapterType)) { IEditorPart part = ((IEditorReference)adaptableObject).getEditor(true); if (part != null) { IEditorInput input = part.getEditorInput(); if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile(); } } } } return null; } public Class[] getAdapterList() { return new Class[] { IResource.class }; } } |