Bug 21414 - Cannot use org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor as a page in a MultiPageEditor
Summary: Cannot use org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor as a ...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 enhancement with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 40282 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-07-09 14:26 EDT by Joseph Remes CLA
Modified: 2008-03-25 11:31 EDT (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Remes CLA 2002-07-09 14:26:06 EDT
Release 2.0

I obtained an instance of the Java Editor in the documented way...
   I have an IFile that points to a .java file.
   ICompilationUnit cu = JavaCore.createCompilationUnitFrom(javaIFile);
   IEditorPart javaEditor = javaUI.openInEditor(cu);

So far so good. Then in my MultiPageEditorPart I call addPage(javaEditor, 
input);

That's when it hits the fan. Somewhere inside the CompilationUnitEditor, 
setTitleImage() is called. This fires a property change 
(IWorkbenchPart.PROP_TITLE)
Then the platform calls org.eclipse.ui.internal.EditorWorkbook.updateEditorTab
(IEditorPart part).
The first line of this method calls getSite() on the IEditorPart and casts the 
return value to (EditorSite). The only problem with this is that the returned 
site, in this case, is NOT an EditorSite but a MultiPageEditorSite.
A ClassCastException happens.

Perhaps this is all in vain because the JavaEditor was never intended to be 
used as part of a multi-page editor???
Comment 1 Nick Edgar CLA 2002-07-09 16:15:13 EDT
The problem is that openInEditor not only instantiates the editor, but actually 
opens it as a regular top-level editor.  Then you're trying to add it as a page 
inside a MultiPageEditorPart, which is also a top-level editor.
So the editor's site gets bashed with the MultiPageEditorSite.  
The workbench's assumption that the site is an EditorSite is reasonable, since 
it creates the site for all top-level editors.

You will need separate API from JDT-UI to create an editor without actually 
opening it.  You can then add it to the multipage editor.  Its site will then 
only be assigned once, to a MultiPageEditorSite, and the site of the top-level 
MultiPageEditor will be an EditorSite.
You will also need to provide your own EditorActionBarContributor for your 
subclass of MultiPageEditorPart.  It will probably need to delegate to the Java 
editor's EditorActionBarContributor when that page is active, so you will need 
API for that as well.

Moving to JDT for consideration of these APIs.
Comment 2 Dani Megert CLA 2005-11-10 09:11:11 EST
Nick,

what you describe in comment 1 is essential the goal of bug 71125 right?
Comment 3 Dani Megert CLA 2005-11-10 09:13:08 EST
Or in better words: it's the goal of bug 71125 to make this work seamlessly for
all kinds of views and editors without doing what's suggested in comment 1.
Comment 4 Dani Megert CLA 2005-11-10 09:31:49 EST
I assume that at the end to make it correctly work we would duplicate lots of
work started for bug 71125.
Comment 5 Nick Edgar CLA 2005-11-10 09:58:28 EST
Yes, bug 71125 is for making it possible to nest parts inside each other.
Note however that this work is not on the plan for 3.2.
Comment 6 Dani Megert CLA 2005-11-10 10:11:30 EST
*** Bug 40282 has been marked as a duplicate of this bug. ***
Comment 7 Nick Edgar CLA 2005-11-10 10:38:17 EST
I believe that many of the scenarios for editor nesting not only require the
ability to nest an editor (as it normally appears at top level) inside some
other editor, but also require some form of customization of the editor such as:
- removing or adding actions or customizing their behaviour
- having a custom presentation (e.g. showing only source for a specific method)
- hardwiring configurations (e.g. force folding off)

These would all require extra support even if we did have the supporting
infrastructure for general part nesting.

It's hard to know exactly what is required without more details about the
concrete scenarios in this request and its dups.
Comment 8 Tom Stamm CLA 2006-06-16 13:04:57 EDT
Hi, I'm working on a similar problem and wanted to chime in on this. We have most of the menu bar actions working correctly by having our editor's action bar contributor delegate to a CompilationUnitEditorActionContributor, but there are still a handful of things that don't work right.

One category of things is the set of functionality that uses the SelectionListenerWithASTManager and ASTProvider classes. These classes ultimately cache and send events related to an AST built on the contents of the current editor. The problem is that they no-op if the current editor is not a JavaEditor. I can't use the same id as the CompilationUnitEditor, because then all java files will use my editor; and I don't think there's a way to say that my editor is "equivalent".

Another category of things does an explicit check for the current editor being an ITextEditor, or one of its extensions. (for example the JavaAutoIndentStrategy) I could have my multipage editor implement this, and delegate to the CompilationUnitEditor, but I'm not sure if this is safe, since only one page of the multi page editor is actually a text editor. Also we have a use-case where we might want multiple java source tabs, for different files, in the same multi-page editor.
Comment 9 Tod Creasey CLA 2007-08-10 08:55:04 EDT
Please consider for 3.4.
Comment 10 Dani Megert CLA 2007-08-21 04:41:13 EDT
There are no plans to copy/duplicate the work that has been started for bug 46207.
Comment 11 Alexander Mitin CLA 2008-03-25 11:17:30 EDT
Does this mean that the JavaEditor will move into public API? If so, in which version?

In order to pass RFRS by Instantiations WindowBuilder product we should exclude
the usage of internal API, but the key feature of WindowBuilder is the multipage editor (java editor <-> designer editor) and it can't be impelemented using public API. Now we are using the org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor class as the base class of multipage editor.
Comment 12 Dani Megert CLA 2008-03-25 11:31:00 EDT
>Does this mean that the JavaEditor will move into public API? If so, in which
>version?
4.0. Most likely you will be able to nest the part via ID. For now you have to stick to internal code or create your own page using a SourceViewer with JavaSourceViewerConfiguration.