How to show an editable properties view [message #508769] |
Wed, 20 January 2010 09:37 |
Robert Wloch Messages: 109 Registered: July 2009 |
Senior Member |
|
|
Hi all,
for a logical navigation on a domain model I have created a model browser as a tree viewer. On selection of an element in the tree I want to show it in the properties view in to edit its properties just as you can when invoking "show in properties view" from the context menu of an EMF/GMF editor. I got as far as showing the properties view but they are not always editable. Yes, sometimes they are, but I couldn't track down why so far. However, I need the properties view to be always editable.
The model browser works on the same EditingDomain as the editors. So I expected this to work by doing the following:
The browser extends ViewPart and is overriding getAdapter:
public Object getAdapter(Class key) {
if (key.equals(IPropertySheetPage.class)) {
return getPropertySheetPage();
}
return super.getAdapter(key);
}
My BrowserPropertySheetPage extends ExtendedPropertySheetPage and sets its own IPropertySourceProvider:
setPropertySourceProvider(new IPropertySourceProvider() {
public IPropertySource getPropertySource(Object object) {
if (object instanceof IPropertySource) {
return (IPropertySource) object;
} else if (object instanceof TreeObject) {
TreeObject treeElement = (TreeObject) object;
EObject eObject = BrowserUtil.resolveSemanticElement(treeElement);
return BrowserUtil.propertySource(eObject);
} else {
return null;
}
}
});
BrowserUtil.resolveSemanticElement() gets the very same EObject from the shared EditingDomain's ResourceSet the editors are using. BrowserUtil.propertySource() is using the shared EditingDomain's AdapterFactory to create the PropertySource:
public static IPropertySource propertySource(EObject eObject) {
...
AdapterFactory af = adapterFactory(eObject);
if (af != null) {
IItemPropertySource ips = (IItemPropertySource)af.adapt(eObject, IItemPropertySource.class);
if (ips != null) {
return new PropertySource(eObject, ips);
}
}
return null;
}
I'm not sure if my approach from above is the way to go at all. But if it is a way, then I might be missing something to get an editable properties view. The IPropertySource propertySource() method was taken 1:1 from the GMF generated diagram.xxx.sheet.XXXPropertySection.java#propertySource().
Does the properties view make a difference between editors and views as source of its data? If so, how can I force it to accept the editability?
Thanks for help in adavance!
Regards
Robert
[Updated on: Wed, 20 January 2010 09:44] Report message to a moderator
|
|
|
Re: How to show get editable properties view [message #508800 is a reply to message #508769] |
Wed, 20 January 2010 06:32 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Robert,
Comments below.
Robert Wloch wrote:
> Hi all,
>
> for a logical navigation on a domain model I have created a model
> browser as a tree viewer. On selection of an element in the tree I
> want to show it in the properties view in to edit its properties just
> as you can when invoking "show in properties view" from the context
> menu of an EMF/GMF editor. I got as far as showing the properties view
> but they are not always editable. Yes, sometimes they are, but I
> couldn't track down why so far. However, I need the properties view to
> be always editable.
>
> The model browser works on the same EditingDomain as the editors. So I
> expected this to work by doing the following:
>
> The browser extends ViewPart and is overriding getAdapter:
>
> public Object getAdapter(Class key) {
> if (key.equals(IPropertySheetPage.class)) {
> return getPropertySheetPage();
> }
> return super.getAdapter(key);
> }
>
>
> My BrowserPropertySheetPage extends ExtendedPropertySheetPage and sets
> its own IPropertySourceProvider:
>
> setPropertySourceProvider(new IPropertySourceProvider() {
> public IPropertySource getPropertySource(Object object) {
> if (object instanceof IPropertySource) {
> return (IPropertySource) object;
> } else if (object instanceof TreeObject) {
> TreeObject treeElement = (TreeObject) object;
> EObject eObject =
> BrowserUtil.resolveSemanticElement(treeElement);
> return BrowserUtil.propertySource(eObject);
> } else {
> return null;
> }
> }
> });
>
>
> BrowserUtil.resolveSemanticElement() gets the very same EObject from
> the shared EditingDomain's ResourceSet the editors are using.
> BrowserUtil.propertySource() is using the shared EditingDomain's
> AdapterFactory to create the PropertySource:
>
> public static IPropertySource propertySource(EObject eObject) {
> ...
> AdapterFactory af = adapterFactory(eObject);
> if (af != null) {
> IItemPropertySource ips =
> (IItemPropertySource)af.adapt(eObject, IItemPropertySource.class);
> if (ips != null) {
> return new PropertySource(eObject, ips);
> }
> }
> return null;
> }
>
>
> I'm not sure if my approach from above is the way to go at all. But if
> it is a way, then I might be missing something to get an editable
> properties view. The IPropertySource propertySource() method was taken
> 1:1 from the GMF generated
> diagram.xxx.sheet.XXXPropertySection.java#propertySource().
>
> Does the properties view make a difference between editors and views
> as source of its data? If so, how can I force it to accept the
> editability?
It all appears okay. In the end, it's the non-null result of
IPropertyDescriptor.createPropertyEditor that makes something be
editable so I suppose in some cases it's returning null where you'd like
it to not return null...
>
> Thanks for help in adavance!
>
> Regards
> Robert
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03756 seconds