Custom property page does not work for compilation units in Package Explorer [message #534392] |
Tue, 18 May 2010 20:59  |
Eclipse User |
|
|
|
I'm developing a plugin that adds a custom property page to all Java files. My extension code looks like this:
<extension point="org.eclipse.ui.propertyPages">
<page
id="com.example.MyPropertyPage"
name="My Property Page"
class="com.example.MyPropertyPage"
nameFilter="*.java">
<enabledWhen>
<instanceof
value="org.eclipse.core.resources.IFile">
</instanceof>
</enabledWhen>
</page>
</extension>
It works for *.java files in the Package Explorer but only if they're located at the root of the project. It does not work for files in the source directory. Eclipse simply does not show my property page for those files.
"The Java Developer's Guide to Eclipse" (Chapter 16) offers a possible explanation:
Quote: |
The Package Explorer view does not display files but displays objects (IJavaElement) as defined in JDT's Java model. For example, what appears to be a simple .java file (an instance of IFile) in the Package Explorer view is actually part of the JDT model, an instance of ICompilationUnit.
|
Indeed, my extension is enabled for instances of IFile, not ICompilationUnit, which explains the behavior I am seeing.
The book goes on to say:
Quote: |
If you only wanted your page to be added to the Properties dialog opened from the Package Explorer view, the objectClass attribute would identify org.eclipse.jdt.core.ICompilationUnit.
|
Sure enough, when I change my extension's instanceof value from IFile to ICompilationUnit, the property page is suddenly enabled for files in the source directory (but of course no longer for those in the root directory).
However, when I click on my property page, an exception is thrown because my property page class calls getElement(), which now returns an instance of type ICompilationUnit, instead of the expected IResource.
So... what now? How can I get my property page to work for compilation units in the Package Explorer?
(The book goes on to mention something about setting the extension page's "adaptable" attribute to true, but this had no effect for me.)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01985 seconds