Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ClassCastException when editing property sheet value(PropertyValueWrapper cannot be cast to java.lang.String)
ClassCastException when editing property sheet value [message #1115939] Tue, 24 September 2013 19:53 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi all,

I try to develop some kind of modeling tool using Graphiti and CDO.
Up to now, I managed to create diagrams and store them in CDO.
When I select a diagram element, the corresponding property sheet page is correctly displayed.
But I get the following error when I try to edit a property value :
java.lang.ClassCastException: org.eclipse.emf.edit.provider.ItemPropertyDescriptor$PropertyValueWrapper cannot be cast to java.lang.String
    at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.convertEStringToString(EcoreFactoryImpl.java:646)
    at org.eclipse.emf.ecore.impl.EcoreFactoryImpl.convertToString(EcoreFactoryImpl.java:219)
    at org.eclipse.emf.ecore.util.EcoreUtil.convertToString(EcoreUtil.java:3364)
    at org.eclipse.emf.edit.ui.provider.PropertyDescriptor$EDataTypeValueHandler.toString(PropertyDescriptor.java:203)
    at org.eclipse.emf.edit.ui.provider.PropertyDescriptor$EDataTypeCellEditor.isCorrect(PropertyDescriptor.java:255)
    at org.eclipse.jface.viewers.CellEditor.setValue(CellEditor.java:855)
    at org.eclipse.ui.views.properties.PropertySheetEntry.getEditor(PropertySheetEntry.java:384)
    at org.eclipse.ui.views.properties.PropertySheetViewer.activateCellEditor(PropertySheetViewer.java:163)
    at org.eclipse.ui.views.properties.PropertySheetViewer.handleSelect(PropertySheetViewer.java:727)
    at org.eclipse.ui.views.properties.PropertySheetViewer.access$8(PropertySheetViewer.java:707)
    at org.eclipse.ui.views.properties.PropertySheetViewer$6.mouseDown(PropertySheetViewer.java:816)
...


I could not find a solution on the web or figure out what to do by studying the generated EMF.Editor example.

I defined the following on my Graphiti editor side :
    @Override
    public Object getAdapter(Class<?> type) {
		if (type == IPropertySheetPage.class)
			return getPropertySheetPage();
		return null;
    }

    public IPropertySheetPage getPropertySheetPage() {
		if (propertySheetPage == null) {
			TransactionalEditingDomain ed = TransactionalEditingDomain.Registry.INSTANCE
					.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
			propertySheetPage = new ExtendedPropertySheetPage((AdapterFactoryEditingDomain) ed);
    	}
    	return propertySheetPage;
    }


The following adapter factory :
public class GraphitiAdapterFactory implements IAdapterFactory {

	@SuppressWarnings("rawtypes")
	@Override
	public Object getAdapter(Object adaptableObject, Class adapterType) {
	    if (adapterType== IPropertySource.class && adaptableObject instanceof GraphitiShapeEditPart){
	    	EObject element = (EObject)Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(((GraphitiShapeEditPart)adaptableObject).getPictogramElement());
	    	if (element != null) {
				TransactionalEditingDomain ed = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
		    	ComposedAdapterFactory emfGlobalFactory = new ComposedAdapterFactory();
				emfGlobalFactory.addAdapterFactory(new RepositorystructureItemProviderAdapterFactory());
				emfGlobalFactory.addAdapterFactory(new ApplicationItemProviderAdapterFactory());
				emfGlobalFactory.addAdapterFactory(new ServiceItemProviderAdapterFactory());
				TransactionalAdapterFactoryContentProvider tafcp =
						new TransactionalAdapterFactoryContentProvider(ed, emfGlobalFactory);
				return tafcp.getPropertySource(element);
	    	}
	      }
		return null;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Class[] getAdapterList() {
	    return new Class[] { IPropertySource.class };
	}
}


As well as the corresponding entries in my plugin.xml :
   <extension
         point="org.eclipse.ui.views">
...
      <view
            allowMultiple="false"
            class="org.eclipse.ui.views.properties.PropertySheet"
            id="org.eclipse.ui.views.properties.PropertySheet"
            name="Properties"
            restorable="true">
      </view>
   </extension>


   <extension
         point="org.eclipse.core.runtime.adapters">
      <factory
            adaptableType="org.eclipse.graphiti.ui.platform.GraphitiShapeEditPart"
            class="myappsmodeler.graphiti.GraphitiAdapterFactory">
         <adapter
               type="org.eclipse.ui.views.properties.IPropertySource">
         </adapter>
      </factory>
   </extension>


Could somebody please help me find my way out ?

Kind regards,

Laurent
Re: ClassCastException when editing property sheet value [message #1116236 is a reply to message #1115939] Wed, 25 September 2013 06:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Laurent,

This sounds the same as what's described in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417873. More comments below.

On 24/09/2013 9:53 PM, Laurent Le Moux wrote:
> Hi all,
>
> I try to develop some kind of modeling tool using Graphiti and CDO.
> Up to now, I managed to create diagrams and store them in CDO.
> When I select a diagram element, the corresponding property sheet page
> is correctly displayed.
> But I get the following error when I try to edit a property value :
>
> java.lang.ClassCastException:
> org.eclipse.emf.edit.provider.ItemPropertyDescriptor$PropertyValueWrapper
> cannot be cast to java.lang.String
> at
> org.eclipse.emf.ecore.impl.EcoreFactoryImpl.convertEStringToString(EcoreFactoryImpl.java:646)
> at
> org.eclipse.emf.ecore.impl.EcoreFactoryImpl.convertToString(EcoreFactoryImpl.java:219)
> at
> org.eclipse.emf.ecore.util.EcoreUtil.convertToString(EcoreUtil.java:3364)
> at
> org.eclipse.emf.edit.ui.provider.PropertyDescriptor$EDataTypeValueHandler.toString(PropertyDescriptor.java:203)
> at
> org.eclipse.emf.edit.ui.provider.PropertyDescriptor$EDataTypeCellEditor.isCorrect(PropertyDescriptor.java:255)
> at org.eclipse.jface.viewers.CellEditor.setValue(CellEditor.java:855)
> at
> org.eclipse.ui.views.properties.PropertySheetEntry.getEditor(PropertySheetEntry.java:384)
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.activateCellEditor(PropertySheetViewer.java:163)
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.handleSelect(PropertySheetViewer.java:727)
> at
> org.eclipse.ui.views.properties.PropertySheetViewer.access$8(PropertySheetViewer.java:707)
> at
> org.eclipse.ui.views.properties.PropertySheetViewer$6.mouseDown(PropertySheetViewer.java:816)
> ..
>
>
> I could not find a solution on the web or figure out what to do by
> studying the generated EMF.Editor example.
>
> I defined the following on my Graphiti editor side :
>
> @Override
> public Object getAdapter(Class<?> type) {
> if (type == IPropertySheetPage.class)
> return getPropertySheetPage();
> return null;
> }
>
> public IPropertySheetPage getPropertySheetPage() {
> if (propertySheetPage == null) {
> TransactionalEditingDomain ed =
> TransactionalEditingDomain.Registry.INSTANCE
> .getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
> propertySheetPage = new
> ExtendedPropertySheetPage((AdapterFactoryEditingDomain) ed);
> }
> return propertySheetPage;
> }
>
>
> The following adapter factory :
>
> public class GraphitiAdapterFactory implements IAdapterFactory {
>
> @SuppressWarnings("rawtypes")
> @Override
> public Object getAdapter(Object adaptableObject, Class adapterType) {
> if (adapterType== IPropertySource.class && adaptableObject
> instanceof GraphitiShapeEditPart){
As in https://bugs.eclipse.org/bugs/show_bug.cgi?id=417873 you need to
adapter IItemPropertySource as well.
> EObject element =
> (EObject)Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(((GraphitiShapeEditPart)adaptableObject).getPictogramElement());
> if (element != null) {
> TransactionalEditingDomain ed =
> TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
> ComposedAdapterFactory emfGlobalFactory = new
> ComposedAdapterFactory();
Surely it's a bad idea to create a new adapter factory on every attempt
to adapt.
> emfGlobalFactory.addAdapterFactory(new
> RepositorystructureItemProviderAdapterFactory());
> emfGlobalFactory.addAdapterFactory(new
> ApplicationItemProviderAdapterFactory());
> emfGlobalFactory.addAdapterFactory(new
> ServiceItemProviderAdapterFactory());
> TransactionalAdapterFactoryContentProvider tafcp =
> new
> TransactionalAdapterFactoryContentProvider(ed, emfGlobalFactory);
> return tafcp.getPropertySource(element);
> }
> }
> return null;
> }
>
> @SuppressWarnings("rawtypes")
> @Override
> public Class[] getAdapterList() {
> return new Class[] { IPropertySource.class };
> }
> }
>
>
> As well as the corresponding entries in my plugin.xml :
>
> <extension
> point="org.eclipse.ui.views">
> ..
> <view
> allowMultiple="false"
> class="org.eclipse.ui.views.properties.PropertySheet"
> id="org.eclipse.ui.views.properties.PropertySheet"
> name="Properties"
> restorable="true">
> </view>
> </extension>
>
>
>
> <extension
> point="org.eclipse.core.runtime.adapters">
> <factory
> adaptableType="org.eclipse.graphiti.ui.platform.GraphitiShapeEditPart"
> class="myappsmodeler.graphiti.GraphitiAdapterFactory">
> <adapter
> type="org.eclipse.ui.views.properties.IPropertySource">
> </adapter>
> </factory>
> </extension>
>
>
> Could somebody please help me find my way out ?
>
> Kind regards,
>
> Laurent


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: ClassCastException when editing property sheet value [message #1117740 is a reply to message #1116236] Thu, 26 September 2013 19:16 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Ed,

Many thanks for your answer. I followed your indications and it works just fine !
Hereafter the modifications if anybody is interested :
   <extension
         point="org.eclipse.core.runtime.adapters">
      <factory
            adaptableType="org.eclipse.emf.edit.provider.IItemPropertySource"
            class="myappsmodeler.graphiti.GraphitiAdapterFactory">
         <adapter
               type="org.eclipse.ui.views.properties.IPropertySource">
         </adapter>
      </factory>
      <factory
            adaptableType="org.eclipse.graphiti.ui.platform.GraphitiShapeEditPart"
            class="myappsmodeler.graphiti.GraphitiAdapterFactory">
         <adapter
               type="org.eclipse.ui.views.properties.IPropertySource">
         </adapter>
      </factory>
   </extension>


public class GraphitiAdapterFactory implements IAdapterFactory {
	
	private TransactionalAdapterFactoryContentProvider tafcp = null;
	
	private TransactionalAdapterFactoryContentProvider getTAFCP() {
		if (tafcp == null) {
			TransactionalEditingDomain ed = TransactionalEditingDomain.Registry.INSTANCE
					.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
	    	ComposedAdapterFactory emfGlobalFactory = new ComposedAdapterFactory();
			emfGlobalFactory.addAdapterFactory(new RepositorystructureItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ApplicationItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ServiceItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
			tafcp = new TransactionalAdapterFactoryContentProvider(ed, emfGlobalFactory);
		}
		return tafcp;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Object getAdapter(Object adaptableObject, Class adapterType) {
	    if (adaptableObject instanceof GraphitiShapeEditPart && adapterType == IPropertySource.class) {
	    	EObject element = (EObject)Graphiti.getLinkService()
					.getBusinessObjectForLinkedPictogramElement(((GraphitiShapeEditPart)adaptableObject).getPictogramElement());
	    	if (element != null) {
				return getTAFCP().getPropertySource(element);
	    	}
	    } else if (adaptableObject instanceof IItemPropertySource && adapterType == IPropertySource.class) {
	    	return getTAFCP().getPropertySource(adaptableObject);
	    }
		return null;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public Class[] getAdapterList() {
	    return new Class[] { IPropertySource.class };
	}
}


Regards,

Laurent
Previous Topic:[Xcore] abstract operation or derived feature
Next Topic:Now I need some advice for code generation
Goto Forum:
  


Current Time: Tue Apr 16 12:10:21 GMT 2024

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

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

Back to the top