自訂EMF程式屬性視圖的Cell Editor

來源:互聯網
上載者:User

覆蓋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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.