<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 36, comments - 30, trackbacks - 0, articles - 3

    流程設計器開發十一(擴展點部分)

    Posted on 2008-01-16 08:42 笑看人生 閱讀(1558) 評論(3)  編輯  收藏 所屬分類: Java插件開發
     

    到目前為止,一個完整的流程設計器已基本完成,為了增加系統的可擴展性,比如目前活動的類型有三種,假如以后我們要增加活動的類型,怎么辦?按照目前的做法,我們只能修改代碼,為了使系統的擴展性更好,即我們如果要增加活動類型,只需要修改配置文件,而無須修改現有系統的代碼,為此,我們把活動類型定義一個擴展點,用戶以后要增加活動類型,只需擴展這個擴展點就可以了。(代碼

    plugin.xml文件中,增加擴展點,IdactivityNameActivitySchemaschema/activity.exsd

    activity.exsd具體內容如下:


    <?xml version='1.0' encoding='UTF-8'?>
    <!-- Schema file written by PDE -->
    <schema targetNamespace="com.example.workflow">
    <annotation>
          
    <appInfo>
             
    <meta.schema plugin="com.example.workflow" id="activity" name="Activity"/>
          
    </appInfo>
          
    <documentation>
             [Enter description of this extension point.]
          
    </documentation>
       
    </annotation>

       
    <element name="extension">
          
    <complexType>
             
    <sequence>
                
    <element ref="activity" minOccurs="1" maxOccurs="unbounded"/>
             
    </sequence>
             
    <attribute name="point" type="string" use="required">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="id" type="string">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="name" type="string">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                   
    <appInfo>
                      
    <meta.attribute translatable="true"/>
                   
    </appInfo>
                
    </annotation>
             
    </attribute>
          
    </complexType>
       
    </element>

       
    <element name="activity">
          
    <complexType>
             
    <attribute name="name" type="string" use="required">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="description" type="string">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="icon" type="string" use="required">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="type" type="string" use="required">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                
    </annotation>
             
    </attribute>
             
    <attribute name="figure" type="string" use="required">
                
    <annotation>
                   
    <documentation>
                      
                   
    </documentation>
                   
    <appInfo>
                      
    <meta.attribute kind="java" basedOn=":org.eclipse.draw2d.IFigure"/>
                   
    </appInfo>
                
    </annotation>
             
    </attribute>
          
    </complexType>
       
    </element>

       
    <annotation>
          
    <appInfo>
             
    <meta.section type="since"/>
          
    </appInfo>
          
    <documentation>
             [Enter the first release in which this extension point appears.]
          
    </documentation>
       
    </annotation>

       
    <annotation>
          
    <appInfo>
             
    <meta.section type="examples"/>
          
    </appInfo>
          
    <documentation>
             [Enter extension point usage example here.]
          
    </documentation>
       
    </annotation>

       
    <annotation>
          
    <appInfo>
             
    <meta.section type="apiInfo"/>
          
    </appInfo>
          
    <documentation>
             [Enter API information here.]
          
    </documentation>
       
    </annotation>

       
    <annotation>
          
    <appInfo>
             
    <meta.section type="implementation"/>
          
    </appInfo>
          
    <documentation>
             [Enter information about supplied implementation of this extension point.]
          
    </documentation>
       
    </annotation>

       
    <annotation>
          
    <appInfo>
             
    <meta.section type="copyright"/>
          
    </appInfo>
          
    <documentation>
             
          
    </documentation>
       
    </annotation>

    </schema>

     

    定義這個擴展點有若干個活動節點組成,每個活動節點具有name,descriptiontype,figure,icon屬性,其中icon屬性代表活動在編輯器托盤中顯示的圖標,有大小兩種圖標,而figure是活動要在編輯器區域顯示圖形對應的類,這個類必須實現IFigure接口,type代表活動類型。

    定義完這個擴展點后,我們再在plugin.xml中自己擴展這個擴展點,代碼如下:


      <extension
             
    point="com.example.workflow.activity">
          
    <activity
                
    description="Create a StartActivity"
                figure
    ="org.eclipse.draw2d.Ellipse"
                icon
    ="start16.gif,start24.gif"
                name
    ="Start"
                type
    ="1">
          
    </activity>
          
    <activity
                
    description="Create a Activity"
                figure
    ="org.eclipse.draw2d.RectangleFigure"
                icon
    ="activity16.gif,activity24.gif"
                name
    ="Activity"
                type
    ="2"></activity>
          
    <activity
                
    description="Create a EndActivity"
                figure
    ="org.eclipse.draw2d.Triangle"
                icon
    ="end16.gif,end24.gif"
                name
    ="End"
                type
    ="3">
          
    </activity>
       
    </extension>

     

      如果以后要增加活動類型的話,直接在這里擴展就可以了,要實現不修改原來的代碼,就增加活動類型的話,還必須修改一些地方。

    首先新建一個模型,來對應擴展點中對應的各個活動,代碼如下:

    package com.example.workflow.model;

    public class CreationEntry {
        
    private String name;//活動名稱
        private String description;//活動描述
        private String icon;//編輯器托盤上活動的圖標
        private String type;//活動類型
        private String figure;//活動在編輯器中顯示的圖形
        
        
    public String getName() {
            
    return name;
        }

        
    public void setName(String name) {
            
    this.name = name;
        }

        
    public String getDescription() {
            
    return description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public String getIcon() {
            
    return icon;
        }

        
    public void setIcon(String icon) {
            
    this.icon = icon;
        }

        
    public String getType() {
            
    return type;
        }

        
    public void setType(String type) {
            
    this.type = type;
        }

        
    public String getFigure() {
            
    return figure;
        }

        
    public void setFigure(String figure) {
            
    this.figure = figure;
        }

    }


     

    同時我們要新建一個模型工廠類,功能類似于原來的SimpleFactory,代碼如下:

    package com.example.workflow.ui;

    import org.eclipse.gef.requests.CreationFactory;

    import com.example.workflow.model.CreationEntry;

    public class CreationEntryFactory implements CreationFactory{
        
        
    private CreationEntry entry;
        
        
    public CreationEntryFactory(CreationEntry entry){
            
    this.entry = entry;
        }


        
    public Object getNewObject() {
            AbstractActivity activity 
    = new AbstractActivity();
            activity.setName(entry.getName());
            activity.setFigure(entry.getFigure());
            
    return activity;
        }


        
    public Object getObjectType() {        
            
    return entry.getType();
        }


    }


     

    同時修改一下WorkflowProcessXYLayoutEditPolicy類中的方法getCreateCommand,如下:

    protected Command getCreateCommand(CreateRequest request) {

            
    return new AbstractActivityCreateCommand((AbstractActivity) request
                    .getNewObject(), (WorkflowProcess) getHost().getModel(),
                    (Rectangle) getConstraintFor(request));

        }


     

    另外還要修改一下類AbstractActivityEditPart中的方法createFigureForModel()

        private IFigure createFigureForModel() {
            
    try {
                
    return (IFigure)Class.forName(getCastedModel().getFigure()).newInstance();
            }
     catch (InstantiationException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (IllegalAccessException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     catch (ClassNotFoundException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }

            
    return null;
        }


     

    還有給模型AbstractActivity增加屬性figure,以及該屬性的get/set方法。

    修改原來WorkflowProcessEditorPaletteFactory中方法createActivitiesDrawer,同時增加一個方法getCreationEntry(),這個方法的目的就是取得所用擴展我們定義活動擴展點地方。

    private static List<CreationEntry> getCreationEntry(){
            IExtensionPoint point 
    = Platform.getExtensionRegistry()
                    .getExtensionPoint(Activator.PLUGIN_ID 
    + ".activity");
            List
    <CreationEntry> entry = new ArrayList<CreationEntry>();
            CreationEntry model 
    = null;
            
            
    if(point != null){
                
    for (IExtension extension : point.getExtensions()){
                    
    for (IConfigurationElement config : extension
                            .getConfigurationElements())
    {
                        model 
    = new CreationEntry();
                        model.setName(config.getAttribute(
    "name"));
                        model.setDescription(config.getAttribute(
    "description"));
                        model.setIcon(config.getAttribute(
    "icon"));    
                        model.setType(config.getAttribute(
    "type"));    
                        model.setFigure(config.getAttribute(
    "figure"));
                        entry.add(model);
                    }

                }

                
    return entry;
            }

            
    return null;
        }


        
    /** */
        
    /** Create the "Activities" drawer. */
        
    private static PaletteContainer createActivitiesDrawer() {
            PaletteDrawer componentsDrawer 
    = new PaletteDrawer("Process");

            
    for(CreationEntry entry : getCreationEntry()){
                componentsDrawer.add(
    new CombinedTemplateCreationEntry(
                        entry.getName(), entry.getDescription(), entry.getType(),
                        
    new CreationEntryFactory(entry), 
                        ImageDescriptor
                                .createFromFile(Activator.
    class"icons/" +
                                        entry.getIcon().substring(
    0, entry.getIcon().indexOf(","))),
                        ImageDescriptor.createFromFile(Activator.
    class,
                                
    "icons/" + entry.getIcon().substring(entry.getIcon().indexOf(",")+1))));
            }

            
    return componentsDrawer;
        }

     

    至此,擴展點定義完成,以后要增加活動類型,我們只需擴展這個擴展點,指定一下活動的類型,名稱,活動在托盤和編輯器中顯示的圖標就可以了,再也不需要去修改原來的代碼了。


    Feedback

    # re: 流程設計器開發十一(擴展點部分)  回復  更多評論   

    2008-01-16 08:52 by Strive
    牛,

    # re: 流程設計器開發十一(擴展點部分)[未登錄]  回復  更多評論   

    2008-01-16 14:41 by dlpower
    能不能提供完整的代碼下載?謝謝!

    # 如何輸出的流程文件[未登錄]  回復  更多評論   

    2008-01-29 11:50 by fisher
    如何輸出的流程文件
    主站蜘蛛池模板: 亚洲国产精品成人久久久| 立即播放免费毛片一级| 午夜一级毛片免费视频| 日本黄页网址在线看免费不卡| 亚洲真人无码永久在线| 美女视频黄的全免费视频| 边摸边吃奶边做爽免费视频99| 亚洲成熟xxxxx电影| 最新69国产成人精品免费视频动漫 | 国产免费毛不卡片| 免费国产污网站在线观看不要卡 | 亚洲美免无码中文字幕在线| 四虎www免费人成| 最近中文字幕大全免费版在线| 亚洲高清有码中文字| 亚洲人成影院在线无码按摩店| 97无码免费人妻超级碰碰碰碰| 亚洲高清免费视频| 亚洲成年网站在线观看| 亚洲国产成人一区二区精品区| 日韩特黄特色大片免费视频| 91禁漫免费进入| 两个人日本WWW免费版| 亚洲欧美成人av在线观看| 久久久久亚洲AV无码永不| www.亚洲色图| 毛片免费vip会员在线看| 性xxxx视频免费播放直播| 一级毛片免费在线播放| 亚洲爆乳精品无码一区二区| 久久亚洲AV成人无码软件| 永久亚洲成a人片777777| 日本午夜免费福利视频| 黄页网站在线观看免费高清| 一级毛片在线免费看| 久久免费香蕉视频| 日韩一区二区三区免费播放| 亚洲av无码专区首页| 国产亚洲精品bv在线观看| 亚洲精品国产第1页| 亚洲国产精品第一区二区|