ClassCastException when editing property sheet value [message #1115939] |
Tue, 24 September 2013 15:53  |
Eclipse User |
|
|
|
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 #1117740 is a reply to message #1116236] |
Thu, 26 September 2013 15:16  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.08787 seconds