Properties not displayed in property page [message #484953] |
Wed, 09 September 2009 17:20  |
Eclipse User |
|
|
|
I have an editor for which I'd like to display a few properties in the
default property page. I was following the advice here
http://wiki.eclipse.org/FAQ_How_do_I_use_property_pages%3F
to get me started. My case seems simpler than most. When the user
acquires focus in my editor, I'd like a few properties to be displayed
in the property view.
I added a clause to my editor's getAdapter method to include the case
where the input class is IPropertySource, and returned my
IPropertySource. I was following the model for returning an Outline
View Page. But alas my editor's getAdapter method was never invoked
with an IPropertySource request. After printing out what does get
requested, I saw a few requests for IPropertySheetPage. But I was
hoping I only needed to implement IPropertySource.
I tried creating an instance of PropertySheetPage in response for
IPropertySheetPage requests. I provided it with an
IPropertySourceProvider which always returned my original
IPropertySource. I can't explain the resulting behavior. I click
around for a while and see nothing in the property view. Then, after
about 10 seconds of clicking around, the properties appear in the
property view with bogus values. Moreover, the properties only appear
when clicking in my Outline View (but not at first !!).
The API doc for IPropertySource recommends the client (an editor in my
case) register an adapter factory with the adapter manager. I can do
that. But wouldn't that be for adapting to clients that don't implement
IAdaptable?
|
|
|
|
Re: Properties not displayed in property page [message #489480 is a reply to message #485222] |
Sat, 03 October 2009 14:14  |
Eclipse User |
|
|
|
If you just want to display properties without implementing a page yourself, then just have your editable objects (the stuff that can be selected in your editor) subclass IPropertySource. Whenever one of these object gets selected, any existing PropertiesPage will call getSelection() and display its properties.
public class MyEditableObject implements IPropertySource {
...
}
If your editor superclass already adapts IPropertySheetPage, then you'd be all set. If not, have the editor return the standard implementation.
public Object getAdapter(Class type) {
if (type == IPropertySheetPage.class) {
PropertySheetPage page = new PropertySheetPage();
return page;
}
}
If, for some reason, your objects cannot implement IPropertySource themselves, pass the page a provider.
public Object getAdapter(Class type) {
if (type == IPropertySheetPage.class) {
PropertySheetPage page = new PropertySheetPage();
page.setPropertySourceProvider(new IPropertySourceProvider() {
public IPropertySource getPropertySource(Object object) {
if(object instanceof MyEditableObject)
return new MyPropertySource(object);
return null;
}
});
return page;
}
}
This is how I did it. Hope this helps someone.
Cheers,
Gerrit
|
|
|
Powered by
FUDForum. Page generated in 0.03419 seconds