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

流程设计器开发十一(扩展点部分)

Posted on 2008-01-16 08:42 笑看人生 阅读(1607) 评论(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() <