GMF

In our previous page, we successfully created an EDataType and the structure to link it up to a custom editor. However, in order to deal with EDataTypes, you also need to deal with the values you get through an EDataTypeValueHandler. As discussed in my thread on the GMF mailing list, the solution can be something like the following:

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()) {
      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);
}

This can be implemented as a dynamic template, as I implemented in the IAML editor.

In the next page I discuss how to provide an absolute path-based File property editor for GMF.