zoukankan      html  css  js  c++  java
  • gmf logic example 代码阅读笔记

    1. 创建element type的一段代码
    private Element createElement(Element container, IElementType type,
                EReference containmentFeature, IProgressMonitor progressMonitor) {

            CreateElementRequest createRequest 
    = new CreateElementRequest(
                getEditingDomain(), container, type, containmentFeature);

            IElementType elementType 
    = ElementTypeRegistry.getInstance()
                .getElementType(createRequest.getEditHelperContext());

            
    if (elementType != null) {
                ICommand createCommand 
    = elementType.getEditCommand(createRequest);

                
    if (createCommand != null && createCommand.canExecute()) {

                    
    try {
                        createCommand.execute(progressMonitor, 
    null);
                        CommandResult commandResult 
    = createCommand
                            .getCommandResult();

                        
    if (isOK(commandResult)) {
                            Object result 
    = commandResult.getReturnValue();

                            
    if (result instanceof Element) {
                                
    return (Element) result;
                            }
                        }

                    } 
    catch (ExecutionException e) {
                        Trace.catching(
                            LogicDiagramPlugin.getInstance(),
                            LogicDiagramDebugOptions.EXCEPTIONS_CATCHING,
                            getClass(), 
    "createElement", e); //$NON-NLS-1$

                        Log.error(LogicDiagramPlugin.getInstance(),
                            LogicDiagramStatusCodes.COMMAND_FAILURE, e
                                .getLocalizedMessage());
                    }
                }
            }
            
    return null;
        }
    2. element type commmand
    在这个例子里面的commands包里面只有3个command类,
    ConfigureLogicElementCommand继承类org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand
    此类为抽象类,包含了基本类型的create方法,其中方法createElement为抽象的create方法为其他create方法所调用。
    方法doExecuteWithResult()在具体的实现类中重写,并在element type 对应的helper 或 device类中使用。

    3. IElementType 源代码
    public interface IElementType
        
    extends IAdaptable {

        
    /**
         * Gets the unique identifier for this element type.
         * 
         * 
    @return the unique identifier
         
    */
        
    public abstract String getId();

        
    /**
         * Gets the icon URL.
         * 
         * 
    @return the icon URL
         
    */
        
    public abstract URL getIconURL();

        
    /**
         * Gets the display name.
         * 
         * 
    @return the display name
         
    */
        
    public abstract String getDisplayName();

        
    /**
         * Gets the metaclass for this element type.
         * 
         * 
    @return the metaclass
         
    */
        
    public abstract EClass getEClass();

        
    /**
         * Gets a command to edit an element of this type.
         * 
         * 
    @param request
         *            the edit request
         * 
    @return the edit command, or <code>null</code> if none is found. The
         *         command returned may not be executable, and this should be tested
         *         before it is executed.
         
    */
        
    public abstract ICommand getEditCommand(IEditCommandRequest request);
        
        
    /**
         * Answers whether or not the requested edit can be performed.
         * 
         * 
    @param req
         *            the edit request
         * 
    @return <code>true</code> if the requested edit can be performed,
         *         <code>false</code> otherwise.
         
    */
        
    public boolean canEdit(IEditCommandRequest req);

        
    /**
         * Gets the edit helper for this element type.
         * 
         * 
    @return the edit helper
         
    */
        
    public abstract IEditHelper getEditHelper();
        
        
    /**
         * Gets the element supertypes for this type.
         * Ordered from furthest supertype to nearest supertype.
         * 
         * 
    @return the element supertypes
         
    */
        
    public IElementType[] getAllSuperTypes();

    }

  • 相关阅读:
    获取随机图片
    依靠前端解决跨域问题的几种方式
    浅谈什么是前端BFC
    script标签中defer和async的区别
    nodejs学习笔记(一):centos7安装node环境
    深入浅出之js闭包知识点梳理(一)
    js实现防抖函数和节流函数
    前端flex布局学习笔记
    es6 之class介绍
    localstorage实现两个页面通信,购物车原理。
  • 原文地址:https://www.cnblogs.com/youngerbaby/p/402283.html
Copyright © 2011-2022 走看看