覆盖EMF生成的XXXEditor.java的getPropertySheetPage()方法,其余步骤见以下代码里的注释,这个例子是对特定类型的EAttribute(eType为"COM.YOUR.ETYPE")使用自定义的对话框来设置属性值。
/** * This accesses a cached version of the property sheet. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public IPropertySheetPage getPropertySheetPage() { if (propertySheetPage == null) { propertySheetPage = new ExtendedPropertySheetPage(editingDomain) { public void setSelectionToViewer(List selection) { BMEditor.this.setSelectionToViewer(selection); BMEditor.this.setFocus(); } public void setActionBars(IActionBars actionBars) { super.setActionBars(actionBars); getActionBarContributor().shareGlobalActions(this, actionBars); } }; //Use custom content provider here propertySheetPage.setPropertySourceProvider(new BMAdapterFactoryContentProvider(adapterFactory)); } return propertySheetPage; } /** * Apply customized cell editor for custom datatype * @author zhanghao * */ class BMAdapterFactoryContentProvider extends AdapterFactoryContentProvider{ public BMAdapterFactoryContentProvider(AdapterFactory adapterFactory) { super(adapterFactory); } @Override protected IPropertySource createPropertySource(Object object, IItemPropertySource itemPropertySource) { return new PropertySource(object, itemPropertySource) { @Override protected IPropertyDescriptor createPropertyDescriptor(IItemPropertyDescriptor itemPropertyDescriptor) { return new PropertyDescriptor(object, itemPropertyDescriptor) { @Override public CellEditor createPropertyEditor(Composite composite) { Object genericFeature = itemPropertyDescriptor.getFeature(object); if(genericFeature instanceof EStructuralFeature && ((EStructuralFeature)genericFeature).getEType() instanceof EDataType){ EDataType eType=(EDataType)((EStructuralFeature)genericFeature).getEType(); if("COM.YOUR.DATATYPE".equals(eType.getInstanceTypeName())){ return new DialogCellEditor(composite) { @Override protected Object openDialogBox(Control cellEditorWindow) { //Open your dialog to read user input ExpressionDialog dialog = new ExpressionDialog(cellEditorWindow.getShell()); Resource resource = BMEditor.this.getEditingDomain().getResourceSet().getResources().get(0); BusinessModel model=(BusinessModel)resource.getContents().get(0); dialog.setModel(model); if (Window.OK == dialog.open()) { return dialog.getDemand(); }else{ return object; } } }; } } return super.createPropertyEditor(composite); } }; } }; } }
参考:http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg09433.html