Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Properties not displayed in property page
Properties not displayed in property page [message #484953] Wed, 09 September 2009 17:20 Go to next message
Paul Glezen is currently offline Paul Glezen
Messages: 59
Registered: July 2009
Member
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 #485222 is a reply to message #484953] Thu, 10 September 2009 16:27 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2251
Registered: July 2009
Senior Member
Paul Glezen wrote:
> 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?

You have to set the object as the input on your property sheet page
for the IPropertySourceProvider to even be asked for the
corresponding IPropertySource. And if the page was just listening
for selection changes from a text editor, there are some
optoimizations in the text viewer that require you to either list to
post selection changes or change the length of the selected text to
send a notification.

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Properties not displayed in property page [message #489480 is a reply to message #485222] Sat, 03 October 2009 14:14 Go to previous message
Gerrit  is currently offline Gerrit
Messages: 30
Registered: July 2009
Member
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
Previous Topic:CNF view activatation
Next Topic:Prevent eclipse launcher from showing splash
Goto Forum:
  


Current Time: Thu Aug 28 03:24:00 EDT 2014

Powered by FUDForum. Page generated in 0.01749 seconds