<source id="4vppl"><ins id="4vppl"></ins></source>
<u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
<object id="4vppl"></object>
  • <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

    <object id="4vppl"></object>
    <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

      <i id="4vppl"><thead id="4vppl"></thead></i>

      <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>

      當前位置:首頁 > 網(wǎng)站舊欄目 > 學習園地 > 設(shè)計軟件教程 > 如何使EMF模型對應(yīng)的編輯控件能處理Undo&Redo操作

      如何使EMF模型對應(yīng)的編輯控件能處理Undo&Redo操作
      2010-01-14 22:57:07  作者:  來源:

      在EMF自動生成的editor中,只提供了TreeViewer作為編輯控件,自動生成的代碼能讓TreeViewer處理Redo&Undo操作,如果還需要對EMF對應(yīng)的Attribute使用Text, Combo等Widget進行編輯的話,那么如何將這些Widget的編輯也能實現(xiàn)Undo&Redo操作呢?

      首先我們來分析一下,對于TreeViewer是如何實現(xiàn)Redo&Undo操作的,在生成的editor代碼中有類似這樣的一句(這個是我改寫后的,實際生成的可能有所區(qū)別):為了只針對Redo&Undo對UI進行更新,還需要對RedoAction和UndoAction做進一步處理:
      其做法就是要讓editor知道當前的Action,然后在修改UI的時候,取得該Action看是否是我們指定的Action(RedoAction&UndoAction).

      java 代碼
       
      1. viewer.setContentProvider(new AdapterFactoryContentProvider(   
      2.                 getAdapterFactory()));  

      AdapterFactoryContentProvider實現(xiàn)了INotifyChangedListener接口,該接口就是用來處理在EMF模型發(fā)生變動時,如何更新綁定的UI控件:

      java 代碼
       
      1. public void notifyChanged(Notification notification)   
      2.   {   
      3.     if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed())   
      4.     {   
      5.       // If the notification is an IViewerNotification, it specifies how ViewerRefresh should behave.  Otherwise fall   
      6.       // back to NotifyChangedToViewerRefresh, which determines how to refresh the viewer directly from the model   
      7.       // notification.   
      8.       //   
      9.       if (notification instanceof IViewerNotification)   
      10.       {   
      11.         if (viewerRefresh == null)   
      12.         {   
      13.           viewerRefresh = new ViewerRefresh(viewer);   
      14.         }   
      15.   
      16.         if (viewerRefresh.addNotification((IViewerNotification)notification))   
      17.         {   
      18.           viewer.getControl().getDisplay().asyncExec(viewerRefresh);   
      19.         }   
      20.       }   
      21.       else  
      22.       {   
      23.         NotifyChangedToViewerRefresh.handleNotifyChanged(   
      24.           viewer,   
      25.           notification.getNotifier(),   
      26.           notification.getEventType(),   
      27.           notification.getFeature(),   
      28.           notification.getOldValue(),   
      29.           notification.getNewValue(),   
      30.           notification.getPosition());   
      31.       }   
      32.     }   
      33.   }  

      再看代碼:

      java 代碼
       
      1. public AdapterFactoryContentProvider(AdapterFactory adapterFactory)   
      2.   {   
      3.     this.adapterFactory = adapterFactory;   
      4.   
      5.     if (adapterFactory instanceof IChangeNotifier)   
      6.     {   
      7.       ((IChangeNotifier)adapterFactory).addListener(this);   
      8.     }   
      9.   }  

      這里關(guān)鍵的一句就是:

      java 代碼
       
      1. ((IChangeNotifier)adapterFactory).addListener(this);  

      它將更新UI的通知操作與adapterFactory關(guān)聯(lián)起來,然后在EMF模型發(fā)生變動的時候,會從adapterFactory來找到所有注冊的INotifyChangedListener
      因此做法就相當簡單了,即將EMF模型對應(yīng)的編輯控件實現(xiàn)INotifyChangedListener接口,然后拿到adapterFactory,并把該控件注冊進去.
      下面我的一個實現(xiàn):
      AbstractDoradoSection包含了EMF模型當前節(jié)點屬性的對應(yīng)編輯控件集合,讓其實現(xiàn)INotifyChangedListener接口

      并在構(gòu)造函數(shù)中注冊到adapterFactory中:

      java 代碼
       
      1. public AbstractDoradoSection(IAdaptable adaptable, Object input,   
      2.             Composite parent, String title, int style) {   
      3.         this.adaptable = adaptable;   
      4.         this.input = input;   
      5.         this.title = title;   
      6.         this.style = ExpandableComposite.TITLE_BAR | style;   
      7.   
      8.         AdapterFactory adapterFactory = (AdapterFactory) adaptable   
      9.                 .getAdapter(AdapterFactory.class);   
      10.         ((IChangeNotifier) adapterFactory).addListener(this);   
      11.   
      12.         initialize(parent);   
      13.     }  
      Redo&Undo更新UI處理:
      java 代碼
       
      1. /**  
      2.  * 當emf模型發(fā)生變化之后,更新ui,主要針對redo和undo處理  
      3.  *   
      4.  * @see org.eclipse.emf.edit.provider.INotifyChangedListener#notifyChanged(org.eclipse.emf.common.notify.Notification)  
      5.  */  
      6. public void notifyChanged(final Notification notification) {   
      7.     IActionProvider actionProvider = (IActionProvider) adaptable   
      8.             .getAdapter(IActionProvider.class);   
      9.     if (actionProvider.getAction() instanceof NotifierAction) {   
      10.         Object feature = notification.getFeature();   
      11.         if (feature instanceof EAttribute && rows != null) {   
      12.             for (Iterator iter = rows.iterator(); iter.hasNext();) {   
      13.                 final AttributeRow row = (AttributeRow) iter.next();   
      14.                 if (row.getAttribute() == feature) {   
      15.                     row.setTextContent(notification.getNewStringValue(), true);   
      16.                     break;   
      17.                 }   
      18.             }   
      19.         }   
      20.     }   

      安徽新華電腦學校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢
      国产午夜福三级在线播放_亚洲精品成a人片在线观看_亚洲自慰一区二区三区_久久棈精品久久久久久噜噜
      <source id="4vppl"><ins id="4vppl"></ins></source>
      <u id="4vppl"><sub id="4vppl"><label id="4vppl"></label></sub></u>
      <object id="4vppl"></object>
    1. <u id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></u>

      <object id="4vppl"></object>
      <b id="4vppl"><sub id="4vppl"><tr id="4vppl"></tr></sub></b>

        <i id="4vppl"><thead id="4vppl"></thead></i>

        <thead id="4vppl"><li id="4vppl"><label id="4vppl"></label></li></thead>
        亚洲国产午夜精品理论 | 五月花国产一区二区 | 日本韩国床震无遮挡高潮hd | 五月天福利国产视频 | 亚洲精品国自产拍在线观看 | 日韩综合永久久网 |