• 自定义EMF程序属性视图的Cell Editor


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

  • 相关阅读:
    在放置不同图片尺寸时,应该选择合适的放置
    在腾讯开发应用中心上架apk所遇到的问题
    仿慕课网下拉加载动画
    android 视频的缩略图 缓存机制和 异步加载缩略图
    在做Android开发的,如何去掉滚动view在尽头时的阴影效果
    java中常见的模式之自定义观察者和java库中观察者
    在JAVA和android中常用的单列模式
    android 代码控制控件的长宽,小技巧
    IFrame 框架的用法简介
    PHP中RabbitMQ之amqp扩展实现(四)
  • 原文地址:https://www.cnblogs.com/bjzhanghao/p/694602.html
Copyright © 2020-2023  润新知