<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
    如何輸出的流程文件
    主站蜘蛛池模板: 亚洲国产精品成人精品无码区在线| 亚洲天堂一区二区三区| 日本不卡免费新一区二区三区 | 久久精品国产亚洲av麻豆图片| 在线观看免费a∨网站| sss在线观看免费高清| 亚洲精品网站在线观看你懂的| 日韩免费视频播播| a在线观看免费网址大全| 亚洲午夜福利在线视频| 国产亚洲精AA在线观看SEE| 成年女性特黄午夜视频免费看| 日韩大片在线永久免费观看网站 | 亚洲av无码一区二区三区网站| 四虎免费影院ww4164h| 成人国产网站v片免费观看 | 成人在线免费视频| 亚洲精品国产电影午夜| 亚洲国产91精品无码专区| 国色精品卡一卡2卡3卡4卡免费| 一级做受视频免费是看美女| 亚洲影视自拍揄拍愉拍| 亚洲女同成av人片在线观看 | 亚洲国产成人综合| 精品久久久久久亚洲| 免费永久看黄在线观看app| 毛片免费全部播放无码| 两个人看www免费视频| WWW国产亚洲精品久久麻豆| 亚洲二区在线视频| 亚洲AV无码国产精品麻豆天美| 免费一级毛片在级播放| 好先生在线观看免费播放| 久久久高清日本道免费观看| 一级人做人a爰免费视频| 亚洲av色香蕉一区二区三区蜜桃| 亚洲视频在线不卡| 亚洲AV日韩AV天堂久久| 国产亚洲色视频在线| jizzjizz亚洲| 四虎免费久久影院|