`
czjxdm
  • 浏览: 122889 次
社区版块
存档分类
最新评论

treeView refresh

阅读更多
当我们使用TableViewer或TreeViewer时,每当其input值发生改变,通常要调用视图的refresh方法来执行刷新操作,而使用EMF模型作为视图组件的文本提供器和标签提供器,却可以省略refresh操作。

当构建AdapterFactoryContentProvider和AdapterFactoryLabelProvider对象时,需要传入所需要的适配器工厂类,该适配器工厂类实现了IChangeNotifier接口定义的3个方法,起到了监听器的作用:
addListener(INotifyChangedListener notifyChangedListener):添加监听者
removeListener(INotifyChangedListener notifyChangedListener):删除监听者
fireNotifyChanged(Notification notification):对监听者执行通知操作

而同时AdapterFactoryContentProvider和AdapterFactoryLabelProvider对象都实现了INotifyChangedListener接口,因此在构造方法中,便可将自己注册成为适配器工厂类的监听者:

view plaincopy to clipboardprint?
01.public AdapterFactoryContentProvider(AdapterFactory adapterFactory){  
02.    this.adapterFactory = adapterFactory;  
03.    if (adapterFactory instanceof IChangeNotifier){  
04.      ((IChangeNotifier)adapterFactory).addListener(this);//将自己注册成为adapterFactory的监听者  
05.    }  
06.} 
public AdapterFactoryContentProvider(AdapterFactory adapterFactory){
    this.adapterFactory = adapterFactory;
    if (adapterFactory instanceof IChangeNotifier){
      ((IChangeNotifier)adapterFactory).addListener(this);//将自己注册成为adapterFactory的监听者
    }
}
这样,当适配器工厂类执行fireNotifyChanged方法时,便可将模型改变通知到AdapterFactoryContentProvider和AdapterFactoryLabelProvider对象,执行它们的notifyChanged()方法:

view plaincopy to clipboardprint?
01.public void notifyChanged(Notification notification){  
02.    if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()){  
03.      if (notification instanceof IViewerNotification){  
04.        if (viewerRefresh == null){  
05.          viewerRefresh = new ViewerRefresh(viewer);  
06.        }  
07.        if (viewerRefresh.addNotification((IViewerNotification)notification)){  
08.          viewer.getControl().getDisplay().asyncExec(viewerRefresh);  
09.        }  
10.      }  
11.      else{  
12.        NotifyChangedToViewerRefresh.handleNotifyChanged(viewer,notification.getNotifier(),notification.getEventType(),  
13.  notification.getFeatur(),notification.getOldValue(),notification.getNewValue(),notification.getPosition());  
14.      }  
15.    }  
16.} 
public void notifyChanged(Notification notification){
    if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()){
      if (notification instanceof IViewerNotification){
        if (viewerRefresh == null){
          viewerRefresh = new ViewerRefresh(viewer);
        }
        if (viewerRefresh.addNotification((IViewerNotification)notification)){
          viewer.getControl().getDisplay().asyncExec(viewerRefresh);
        }
      }
      else{
        NotifyChangedToViewerRefresh.handleNotifyChanged(viewer,notification.getNotifier(),notification.getEventType(),
  notification.getFeatur(),notification.getOldValue(),notification.getNewValue(),notification.getPosition());
      }
    }
}


由代码可以看出AdapterFactoryContentProvider和AdapterFactoryLabelProvider对象还记录了它们所对应的视图viewer,并在notifyChanged方法中对视图执行了刷新操作。

然而回到上一步,适配器工厂类的fireNotifyChanged方法又是在什么时候触发的呢?

当EMF实体类的类结构发生变化时(如:对某一个属性执行了set方法),会调用eNotify(Notification notification)方法来触发其适配器类的通知操作:

view plaincopy to clipboardprint?
01.public void eNotify(Notification notification){  
02.    Adapter[] eAdapters = eBasicAdapterArray();//返回该实体类所有的适配器类  
03.    if (eAdapters != null && eDeliver()){  
04.      for (int i = 0, size = eAdapters.length; i < size; ++i)  
05.      {  
06.        eAdapters[i].notifyChanged(notification);//执行适配器类的notifyChanged方法。  
07.      }  
08.    }  
09.} 
public void eNotify(Notification notification){
    Adapter[] eAdapters = eBasicAdapterArray();//返回该实体类所有的适配器类
    if (eAdapters != null && eDeliver()){
      for (int i = 0, size = eAdapters.length; i < size; ++i)
      {
        eAdapters[i].notifyChanged(notification);//执行适配器类的notifyChanged方法。
      }
    }
}


而EMF模型适配器类的构造函数中同样传入了adapterFactory适配器工厂类,这样在模型适配器类的notifyChanged方法中,便可进行如下处理:

view plaincopy to clipboardprint?
01.if (adapterFactory instanceof IChangeNotifier){  
02.      IChangeNotifier changeNotifier = (IChangeNotifier)adapterFactory;  
03.      changeNotifier.fireNotifyChanged(notification);  
04.} 
if (adapterFactory instanceof IChangeNotifier){
      IChangeNotifier changeNotifier = (IChangeNotifier)adapterFactory;
      changeNotifier.fireNotifyChanged(notification);
}


以此来触发适配器工厂类的fireNotifyChanged方法。
整个模型改变通知的类图大致如下:



1、当模型实体类Company的类结构发生变化时,会触发其适配器类(CompanyItemProvider)的notifyChange()方法;
2、模型适配器类会调用其适配器工厂类的fireNotifyChanged方法,来触发监听器的通知;
3、适配器工厂类对它的监听者(AdapterFactoryContentProvider)进行通知,执行他们的notifyChanged方法;
4、AdapterFactoryContentProvider对象中会执行视图的刷新操作。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/JavaMan_chen/archive/2010/11/30/6045954.aspx


http://www.java2s.com/CN/Code/Java/SWT-JFace-Eclipse/Demonstratesmultilinecomments.htm



http://www.ibm.com/developerworks/cn/java/wa-eclipsemvc/


MVC 架构(或设计模式)是图形用户界面(GUI)的设计样式,由三部分构成:模型、视图和控制器。MVC 把表示层从数据解耦出来,也把表示从数据的操作解耦出来。
实现 MVC 架构与其他类型的应用程序有所不同。主要的区别来自如何放置和实现业务逻辑或查看呈现逻辑。与典型的 Web 应用程序不同,在这类程序中,程序员必须设计和实现所有 MVC 组件,而 Eclipse 提供的 API 可以替您做大部分控制或呈现工作。所以,不能严格地把 Eclipse 的 MVC 实现与 Web 或其他应用程序类型的 MVC 进行比较。
  • 大小: 26.5 KB
分享到:
评论

相关推荐

    treeview是主要用来建立进化树的

    TreeView 控件响应一些我们觉的VFP 控件的方法和事件: Click, DblClick, Drag, DragDrop, DragOver, GotFocus, KeyDown, KeyPress, KeyUp, LostFocus, MouseDown, MouseMove, MouseUp, Move, Refresh, SetFocus, ...

    基于c#、jquery开发的treeView目录树组件

    很简洁,可随意定制-Based on c#, jquery development treeView tree components, the biggest feature is the display of the tree node state to ajax way, saved to a user session, even if a page refresh, the...

    Mendix Treeview小部件例程V9.14版

    另在原程序基础上做了微小改动,在Demo2-products的ProductTree页添加了“refresh”按钮,改进了该页编辑数据后左侧树结构没有刷新的问题。通过该例程,可完整了解marketplace上提供的小部件“Tree view widget”...

    vb学生公寓管理系统

    Private Sub TreeView3_NodeClick(ByVal Node As MSComctlLib.Node) provider = "provider=Microsoft.jet.oledb.4.0" datasource = "data source=" & App.Path & "\DB.mdb" With Adodc3 .Mode = adModeReadWrite ....

    Android代码-一个支持定制的树状 Android 自定义View

    Tree2View &gt; TreeView implementation in ...refresh status after delete and add files ⑤Select listener Long press node for file operations (Copy, Cut, Rename, Delete) ⑥Animation support Add or dele

    UsbTreeView usb设备查看工具

    Keeps the tree item selection over refresh way more descriptors are decoded, as Audio 2.0 Hexdump of the descriptors can be shown Safe removal, device restart and port restart Extended USB information...

    PB中遍历生成树及树的增、删、改

    pb8源码,PB中遍历生成树及树的增、删、改 效果图:... 在tv的ue_refresh事件的代码中,把ltvi_Item.data = '-1'改成ltvi_Item.data = '0',并把selectchanged事件代码注释掉

    Visual Basic 6编程技术大全 中译本扫描版带书签 2/2

    2.2.2 Refresh方法30 2.2.3 SetFocus方法30 2.2.4 ZOrder方法31 2.3 通用事件31 2.3.1 Click和DblClick事件31 2.3.2 Change事件32 2.3.3 GotFocus和LostFocus事件33 2.3.4 KeyPress、KeyDown和KeyUp事件33 2.3.5 ...

    Visual Basic 6编程技术大全 中译本扫描版带书签 1/2

    2.2.2 Refresh方法30 2.2.3 SetFocus方法30 2.2.4 ZOrder方法31 2.3 通用事件31 2.3.1 Click和DblClick事件31 2.3.2 Change事件32 2.3.3 GotFocus和LostFocus事件33 2.3.4 KeyPress、KeyDown和KeyUp事件33 2.3.5 ...

    unigui0.83.5.820

    - 0000763: UniDBGrid doesn't handle TDataSet.Refresh() - 0000762: UniListBox and Items.Delete bug - 0000760: UniDBLookupXXX: KeyField value submit bug - 0000761: UniEdit and KeyXXX event bug - ...

    VB编程资源大全(英文源码 API)

    Label, Format)&lt;END&gt;&lt;br&gt;43,nodisk.zip Show Message When There is No Disk in a Drive&lt;END&gt;&lt;br&gt;44,fullpath.zip Add Full Paths to a TreeView&lt;END&gt;&lt;br&gt;45,disksrch.zip Search for Disk in a Removable...

    C#全能速查宝典

    《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用...

    UniGUI 说明

    这个文档中的话题与解决方案, 几乎全部来自 UniGUI 的交流群, 群中活跃的 BDS2007、 cmj 等人,给了众多使用 UniGUI 的人很多帮助。 这个文档, 主要是学习与方便后来之人, 文档积累的起因是严肃而正式的, 因为...

Global site tag (gtag.js) - Google Analytics