Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to show an editable properties view
How to show an editable properties view [message #508769] Wed, 20 January 2010 09:37 Go to next message
Robert Wloch is currently offline Robert WlochFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30631
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
Re: How to show an editable properties view [message #508802 is a reply to message #508769] Wed, 20 January 2010 11:32 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
The behavior of when cells of the properties view are editable is really odd:

After I start the runtime workspace I load a model into my model browser. The tree then displays a logical view of domain model and gmf diagram elements.

Selected diagram elements show the Diagram instance in the properties view, but no cell in the view is ever editable. I'd like to at least edit the name of a Diagram element.

Selecting any domain model element allows me to click in the combo box cells and choose values. However, it's important to select the choices with the key up/down and Enter/Return keys, otherwise a NullPointerException is thrown and the properties view is not editable any more until I restart the runtime workspace. As long as I select values with the keyboard I can at least edit all values that are not EStrings.

Does anyone have any ideas of what's going on here?

Thanks a lot in advance!

Regards
Robert
Re: How to show get editable properties view [message #508828 is a reply to message #508800] Wed, 20 January 2010 13:48 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hi Ed,

thanks for the hint with IPropertyDescriptor.createPropertyEditor. It lead me closer to the cause of this odd behavior :

The method PropertySheetEntry.getEditor successfully creates EDataTypeCellEditors from the PropertyDescriptors. But when that getEditor() method executes
editor.setValue(editValue)
the bale takes it's course.
The variable editValue holds an ItemPropertyDescriptor$PropertyValueWrapper that is handed down to EcoreUtil.convertToString(EDataType, Object). From there on it goes on to EcoreFactoryImpl.convertEStringToString(EDataType, Object). There with Object being an instance of ItemPropertyDescriptor$PropertyValueWrapper the unchecked cast
return (String)instanceValue
causes a ClassCastException breaking the creation of the property cell's editor.

I don't really understand, why editValue is an instanceof ItemPropertyDescriptor$PropertyValueWrapper when I fill the properties view from my model browser view. Apparently this is not the case if GMF fills the properties view.

Once the editor is created, but the editValue not set due to the ClassCastException, the properties view seems to be left in an inconsistent state. It will never again try to create the editor (since the reference is not null any more) nor will it attempt to set the editValue again.

Regards
Rob
Re: How to show get editable properties view [message #508853 is a reply to message #508828] Wed, 20 January 2010 09:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30631
Registered: July 2009
Senior Member
Rob,

Maybe there's something wrong with your getEditableValue implementation
or it's not getting called at all. I vaguely recall problems related to
GEF where it wasn't being called... You might compare the behavior of
this method in a purely generated EMF editor verses the context you're
using...


Robert Wloch wrote:
> Hi Ed,
>
> thanks for the hint with IPropertyDescriptor.createPropertyEditor. It
> lead me closer to the cause of this odd behavior :
>
> The method PropertySheetEntry.getEditor successfully creates
> EDataTypeCellEditors from the PropertyDescriptors. But when that
> getEditor() method executes editor.setValue(editValue) the bale takes
> it's course.
> The variable editValue holds an
> ItemPropertyDescriptor$PropertyValueWrapper that is handed down to
> EcoreUtil.convertToString(EDataType, Object). From there on it goes on
> to EcoreFactoryImpl.convertEStringToString(EDataType, Object). There
> with Object being an instance of
> ItemPropertyDescriptor$PropertyValueWrapper the unchecked cast return
> (String)instanceValue causes a ClassCastException breaking the
> creation of the property cell's editor.
>
> I don't really understand, why editValue is an instanceof
> ItemPropertyDescriptor$PropertyValueWrapper when I fill the properties
> view from my model browser view. Apparently this is not the case if
> GMF fills the properties view.
>
> Once the editor is created, but the editValue not set due to the
> ClassCastException, the properties view seems to be left in an
> inconsistent state. It will never again try to create the editor
> (since the reference is not null any more) nor will it attempt to set
> the editValue again.
>
> Regards
> Rob
Re: How to show an editable properties view [message #508886 is a reply to message #508769] Wed, 20 January 2010 16:06 Go to previous message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Ed,

you're the best! Very Happy

I solved it with a combination of everything! Cool First, I went for the tabbed properties view and copied most of the generated GMF code. Although, now my BrowserPropertySection inherited AdvancedPropertySection I still got no IPropertySource inside GMF's PropertySheetEntry.setValues. And without a property source there's no call to getEditableValue(). *Thanks for that valuable hint!*

After I set my shared EditingDomain to my BrowserPropertySection everything is working now.

Thanks again, Ed!

Rob
Previous Topic:ClassCastException when Loading with dynamic EMF
Next Topic:dialog box to confirm delete
Goto Forum:
  


Current Time: Thu Nov 14 16:15:00 GMT 2019

Powered by FUDForum. Page generated in 0.02220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top