Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Custom property editor for EDataTypes
Custom property editor for EDataTypes [message #216543] Wed, 28 January 2009 06:02 Go to next message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
Hi,

I am trying to create a custom property editor for a model element with
a property of EDataType - a file reference, which is also serializible
according to EMF.

After much searching I found
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg10837.html
which describes how to add a custom property editor to a field, which
works well. It adds a '...' to the CellEditor of the property cell,
which when clicked, can be edited with a dialog box (in my case, a
FileDialog).

However, the result returned is not saved anywhere. Once the FileDialog
is closed, the filename is displayed in the cell field, but it is not
saved back to the original model object/property. If I select away from
the model element and reselect it, the value is reset to its previous
value. The diagram file is not marked as dirty.

My code is almost identical to the code in the thread above; am I
missing a setValue() somewhere, or something similar? I thought that the
result from the ExtendedDialogCellEditor would be used to set the property.

I also tried extending createEDataTypeCellEditor(EDataType, Composite)
with the same approach, but got the same result.

I tried setting the value manually, i.e. ((MyObject) object).setFile(new
FileReference(filename));, but this throws a "Cannot modify resource set
without a write transaction".

It appears that while the approach above would work for normal property
values (e.g. EStrings), it isn't working for EDataTypes.

Any ideas? Is there something special I should be doing in order to
handle custom EDataType property editors? Or should I just ignore
EDataTypes in EMF and change my property type to EString?

Thanks!

Jevon
Re: Custom property editor for EDataTypes [message #216620 is a reply to message #216543] Thu, 29 January 2009 01:21 Go to previous message
Jevon  is currently offline Jevon Friend
Messages: 164
Registered: July 2009
Senior Member
Hi,

After more debugging and referring to the EMF source, I found a
solution: The Object returned by the openDialogBox() method needs to
first be passed through a EDataTypeValueHandler, and likewise,
retrieving results must also be passed through this handler.

That is:

protected class CustomizedPropertyDescriptor extends PropertyDescriptor {

public CustomizedPropertyDescriptor(Object object,
IItemPropertyDescriptor itemPropertyDescriptor) {
super(object, itemPropertyDescriptor);
}

public CellEditor createPropertyEditor(Composite composite) {
EClassifier eType = ((EStructuralFeature) itemPropertyDescriptor
.getFeature(object)).getEType();

final EDataType dataType = (EDataType) eType;
if (dataType.equals(DomainPackage.eINSTANCE.getFileReference()) ) {

CellEditor result = new ExtendedDialogCellEditor(composite,
getEditLabelProvider()) {

// based on
org.eclipse.emf.edit.ui.provider.PropertyDescriptor.createED ataTypeCellEditor(EDataType
eDataType, Composite composite)
protected EDataTypeValueHandler valueHandler = new
EDataTypeValueHandler(
dataType);

@Override
protected Object openDialogBox(Control cellEditorWindow) {

Shell shell = PlatformUI.getWorkbench().getDisplay()
.getActiveShell();
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFileName(valueHandler.toString(getValue()));
String fileSelected = dialog.open();
if (fileSelected == null) {
return getValue();
}

return valueHandler.toValue(fileSelected);
}

};
return result;
}

return super.createPropertyEditor(composite);
}

}

Hope this helps someone else out!

Cheers
Jevon

Jevon Wright wrote:
> Hi,
>
> I am trying to create a custom property editor for a model element with
> a property of EDataType - a file reference, which is also serializible
> according to EMF.
>
> After much searching I found
> http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg10837.html
> which describes how to add a custom property editor to a field, which
> works well. It adds a '...' to the CellEditor of the property cell,
> which when clicked, can be edited with a dialog box (in my case, a
> FileDialog).
>
> However, the result returned is not saved anywhere. Once the FileDialog
> is closed, the filename is displayed in the cell field, but it is not
> saved back to the original model object/property. If I select away from
> the model element and reselect it, the value is reset to its previous
> value. The diagram file is not marked as dirty.
>
> My code is almost identical to the code in the thread above; am I
> missing a setValue() somewhere, or something similar? I thought that the
> result from the ExtendedDialogCellEditor would be used to set the property.
>
> I also tried extending createEDataTypeCellEditor(EDataType, Composite)
> with the same approach, but got the same result.
>
> I tried setting the value manually, i.e. ((MyObject) object).setFile(new
> FileReference(filename));, but this throws a "Cannot modify resource set
> without a write transaction".
>
> It appears that while the approach above would work for normal property
> values (e.g. EStrings), it isn't working for EDataTypes.
>
> Any ideas? Is there something special I should be doing in order to
> handle custom EDataType property editors? Or should I just ignore
> EDataTypes in EMF and change my property type to EString?
>
> Thanks!
>
> Jevon
Previous Topic:Copy-Paste: which kind of ID?
Next Topic:[Announce] GMF 2.2.0 I200901281927 is available
Goto Forum:
  


Current Time: Thu Sep 26 20:47:48 GMT 2024

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

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

Back to the top