<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

          哪個模型的控制器能接受在活動之間建立轉(zhuǎn)移的請求呢,只有活動模型的控制器了,因為活動模型中維護著活動的輸入和輸出轉(zhuǎn)移的列表,在活動控制器增加策略,使該控制器能接受建立轉(zhuǎn)移的請求,代碼如下:

    protectedvoid createEditPolicies() {
           
    //allow removal of the associated model element
           installEditPolicy(EditPolicy.COMPONENT_ROLE, new AbstractActivityComponentEditPolicy

    ());
           
    //allow the creation of transitions and 
           
    // and the reconnection of transitions between AbstractActivity instances
           installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new 

    TransitionGraphicalNodeEditPolicy());
           
        }
    這里安裝了TransitionGraphicalNodeEditPolicy策略,這個策略的代碼如下:
    package com.example.workflow.policy;
     
    import org.eclipse.gef.commands.Command;
    import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
    import org.eclipse.gef.requests.CreateConnectionRequest;
    import org.eclipse.gef.requests.ReconnectRequest;
     
    import com.example.workflow.commands.TransitionCreateCommand;
    import com.example.workflow.model.AbstractActivity;
     
    public class TransitionGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy{
                  
           
    protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
                  TransitionCreateCommand cmd 
    = 
                         (TransitionCreateCommand)request.getStartCommand();
                  cmd.setTarget((AbstractActivity)getHost().getModel());
                  
    return cmd;
           }

           
           
    protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
                  AbstractActivity source 
    = (AbstractActivity)getHost().getModel();
                  TransitionCreateCommand cmd 
    = new TransitionCreateCommand(source);
                  request.setStartCommand(cmd);
                  
    return cmd;
           }

     
           
    protected Command getReconnectSourceCommand(ReconnectRequest request) {
                  
    // TODO Auto-generated method stub
                  return null;
           }

     
           
    protected Command getReconnectTargetCommand(ReconnectRequest request) {
                  
    // TODO Auto-generated method stub
                  return null;
           }

     
    }

    這個類繼承了GraphicalNodeEditPolicy,并且覆蓋了getConnectionCreateCommand和getConnectionCompleteCommand,從這兩個方法的字面意思就明白它們在什么時候執(zhí)行,在getConnectionCreateCommand方法中,新建一個TransitionCreateCommand命令對象,并且把轉(zhuǎn)移的起始活動放入該命令對象中,在getConnectionCompleteCommand方法中,得到在getConnectionCreateCommand方法中創(chuàng)建的命令,并且把轉(zhuǎn)移的目標活動放入命令中。TransitionCreateCommand命令的代碼如下:

    package com.example.workflow.commands;
     
    import java.util.Iterator;
     
    import org.eclipse.gef.commands.Command;
     
    import com.example.workflow.model.AbstractActivity;
    import com.example.workflow.model.Transition;
     
    public class TransitionCreateCommand extends Command{
           
           
    /** The Transition instance. */
           
    private Transition transition;
           
    /** Start endpoint for the Transition. */
           
    private final AbstractActivity source;
           
    /** Target endpoint for the Transition. */
           
    private AbstractActivity target;
                  
           
    public TransitionCreateCommand(AbstractActivity source){
                  
    if (source == null{
                         
    throw new IllegalArgumentException();
                  }

                  setLabel(
    "connection creation");
                  
    this.source = source;
           }

           
           
           
    public boolean canExecute() {
                  
    // disallow source -> source connections
                  if (source.equals(target)) {
                         
    return false;
                  }

                  
    // return false, if the source -> target connection exists already
                  for (Iterator iter = source.getSourceTransitions().iterator(); iter.hasNext

    ();) 
    {
                         Transition tran 
    = (Transition) iter.next();
                         
    if (tran.getTarget().equals(target)) {
                                
    return false;
                         }

                  }

                  
    return true;
           }

                  
           
    public void execute() {
                  
    // create a new transition between source and target
                  transition = new Transition(source, target);         
           }

     
           
           
    public void redo() {
                  transition.reconnect();
           }

           
           
           
    public void setTarget(AbstractActivity target) {
                  
    if (target == null{
                         
    throw new IllegalArgumentException();
                  }

                  
    this.target = target;
           }

     
           
           
    public void undo() {
                  transition.disconnect();
           }

    }

    在這個命令中,用剛才放入的兩個活動構(gòu)建一個轉(zhuǎn)移對象,其實通過代碼我們知道最終執(zhí)行的是在起始活動的輸入轉(zhuǎn)移列表中加入剛才新建的轉(zhuǎn)移對象,在目標活動的輸入轉(zhuǎn)移列表中加入新建的轉(zhuǎn)移對象。代碼如下:

    void addTransition(Transition tran) {
           
    if (tran == null || tran.getSource() == tran.getTarget()) {
               thrownew IllegalArgumentException();
           }

           
    if (tran.getSource() == this{
               sourceTransitions.add(tran);
               firePropertyChange(SOURCE_CONNECTIONS_PROP, 
    null, tran);
           }
     elseif (tran.getTarget() == this{
               targetTransitions.add(tran);
               firePropertyChange(TARGET_CONNECTIONS_PROP, 
    null, tran);
           }

        }

    我們看到,向活動維護的轉(zhuǎn)移列表中加入轉(zhuǎn)移時,活動模型通知控制器它的SOURCE_CONNECTIONS_PROP和TARGET_CONNECTIONS_PROP屬性發(fā)生變化了,因此在活動控制器中應該根據(jù)這兩個屬性來屬性活動的視圖,代碼如下:

    publicvoid propertyChange(PropertyChangeEvent evt) {
           String prop 
    = evt.getPropertyName();      
           
    if(AbstractActivity.SIZE_PROP.equals(prop) 
                  
    ||AbstractActivity.LOCATION_PROP.equals(prop)){
               refreshVisuals();
           }
    elseif(AbstractActivity.SOURCE_TRANSITIONS_PROP.equals(prop)){
               refreshSourceConnections();
           }
    elseif(AbstractActivity.TARGET_TRANSITIONS_PROP.equals(prop)){
               refreshTargetConnections();
           }
          
        }

    這里刷新的不是活動的視圖,而是活動的輸入和輸入轉(zhuǎn)移對應的視圖。只修改這些代碼,還不能在編輯器中展示出新建的轉(zhuǎn)移,還應該讓活動控制器實現(xiàn)NodeEditPart接口,同時要實現(xiàn)這接口中的四個方法,代碼如下:

    private ConnectionAnchor anchor;
    protected ConnectionAnchor getConnectionAnchor(){
           
    if (anchor == null{
               anchor 
    = new ChopboxAnchor(getFigure());;
           }

           returnanchor;
        }

     
        
    public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
           
    return getConnectionAnchor();
        }

     
        
    public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
           
    return getConnectionAnchor();
        }

     
        
    public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
           
    return getConnectionAnchor();
        }

     
        
    public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
           
    return getConnectionAnchor();
        }

    這四個方法就是實現(xiàn)轉(zhuǎn)移和活動連接的錨點。另外我們還要覆蓋父類中的兩個方法,得到活動模型維護的輸入轉(zhuǎn)移和輸出轉(zhuǎn)移,代碼如下:
     protected List getModelSourceConnections() {
           
    return getCastedModel().getSourceTransitions();
        }

        
    protected List getModelTargetConnections() {
           
    return getCastedModel().getTargetTransitions();
        }
    這樣我們就可以在活動之間建立轉(zhuǎn)移了,效果下圖:
     

    這樣我們就在兩個活動之間建立了轉(zhuǎn)移。那么如何刪除轉(zhuǎn)移呢,要刪除活動之間的轉(zhuǎn)移,應該在轉(zhuǎn)移控制器中安裝策略,代碼如下:

    private Transition getCastedModel(){
           
    return (Transition)getModel();
        }

        
        protectedvoid createEditPolicies() 
    {
           
    //Allows the removal of the transition model element
           installEditPolicy(EditPolicy.CONNECTION_ROLE, new ConnectionEditPolicy() {
               
    protected Command getDeleteCommand(GroupRequest request) {
                  returnnew TransitionDeleteCommand(getCastedModel());
               }

           }
    );
           
        }

    這里安裝的是gef框架提供的策略,我們沒有創(chuàng)建自己的策略,而是直接覆蓋其中的getDeleteCommand,方法,在這個方法中新建了一個ransitionDeleteCommand命令,這個命令的代碼如下:

    package com.example.workflow.commands;
     
    import org.eclipse.gef.commands.Command;
     
    import com.example.workflow.model.Transition;
     
    public class TransitionDeleteCommand extends Command {
        
    /** Transition instance to disconnect. */
        
    private final Transition transition;
         
        
    public TransitionDeleteCommand(Transition tran) {
           
    if (tran == null{
               
    throw new IllegalArgumentException();
           }

           setLabel(
    "Transition deletion");
           
    this.transition = tran;
        }

        
    public void execute() {
           transition.disconnect();
        }

        
        
    public void undo() {
           transition.reconnect();
        }

    }

    這個類最終執(zhí)行的其實活動模型中的removeTransition方法,從活動模型維護的轉(zhuǎn)移列表中刪除它,而此時活動模型通知控制器自己的OURCE_CONNECTIONS_PROP和TARGET_CONNECTIONS_PROP屬性發(fā)生變化了,要刷新視圖,而這個我們在新建轉(zhuǎn)移時,已經(jīng)實現(xiàn),因而這兒不用在實現(xiàn)了。這樣運行程序,我們就可以刪除活動之間的轉(zhuǎn)移了。
    接下來我們再給轉(zhuǎn)移控制器安裝一個策略,目的是當選擇轉(zhuǎn)移,轉(zhuǎn)移有個反饋,給用戶感覺是已經(jīng)選擇了轉(zhuǎn)移,要不然,選擇和不選擇轉(zhuǎn)移,效果一樣,代碼如下:


    protectedvoid createEditPolicies() {
           
    //Selection handle edit policy. 
           
    // Makes the transition show a feedback, when selected by the user.
           installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE,
                  
    new ConnectionEndpointEditPolicy());
           
    //Allows the removal of the transition model element
           installEditPolicy(EditPolicy.CONNECTION_ROLE, new ConnectionEditPolicy() {
               
    protected Command getDeleteCommand(GroupRequest request) {
                  returnnew TransitionDeleteCommand(getCastedModel());
               }

           }
    );
               }
    下一節(jié)我們介紹如何在轉(zhuǎn)移上新建,刪除和移動拐點。

    Feedback

    # re: 流程設計器開發(fā)六(轉(zhuǎn)移建立和刪除)[未登錄]  回復  更多評論   

    2008-01-13 17:02 by fisher
    請問addTransition()是加在哪個類里?

    # re: 流程設計器開發(fā)六(轉(zhuǎn)移建立和刪除)  回復  更多評論   

    2008-01-14 08:39 by 玩轉(zhuǎn)Java
    加在模型AbstractActivity中。
    主站蜘蛛池模板: 久久久久久国产精品免费免费男同 | 亚洲免费观看网站| 亚洲阿v天堂在线| 亚洲午夜未满十八勿入网站2| 内射无码专区久久亚洲 | av电影在线免费看| 色屁屁www影院免费观看视频| 亚洲精品理论电影在线观看| 色天使亚洲综合在线观看| 亚洲fuli在线观看| 国产91在线|亚洲| 亚洲性无码一区二区三区| 亚洲色偷偷色噜噜狠狠99| 亚洲成AV人片高潮喷水| 直接进入免费看黄的网站| 黄网站色视频免费看无下截| 粉色视频在线观看www免费| 4hu四虎免费影院www| 中文在线观看永久免费 | 亚洲一区精彩视频| 亚洲精品无码国产片| 美女视频免费看一区二区| 国产福利在线观看永久免费| 丁香花在线视频观看免费| 久久午夜羞羞影院免费观看| 91麻豆最新在线人成免费观看| 在人线av无码免费高潮喷水| 成人永久福利免费观看| 亚洲国产精品人人做人人爽 | av大片在线无码免费| 久久久久久精品成人免费图片 | 国产免费一级高清淫曰本片| 国产成人AV免费观看| 3d成人免费动漫在线观看| 亚洲欧洲免费无码| 亚洲情侣偷拍精品| 久久青青成人亚洲精品| 亚洲国产模特在线播放| 色偷偷亚洲男人天堂| 13小箩利洗澡无码视频网站免费| 最近中文字幕完整免费视频ww|