EMF Introduction Series (vii. Edit Preliminary)

Source: Internet
Author: User
Tags wrapper

In addition to generating the interface and implementation classes of the model part (which may be called the "core model"), EMF generates a project with a name that ends with. Edit, including code that is very tightly related to the core model and editor. This part of the code has been carefully designed, and the degree of reuse is quite high. Not only are they being used extensively in the EMF-generated editor project, we should also make the most of it when extending the editor.

In the example of an online store, the Com.my.shop.edit project contains a Itemprovideradapterfactory class and a set of Itemprovideradapter subclasses, which correspond to interface one by one of the core model, such as the core model Shop, category and product correspond to Shopitemprovider, Categoryitemprovider, and Productitemprovider respectively. This post is mainly about these itemprovider, and the content of the itemprovideradapterfactory will be introduced in future posts, in fact, as the name suggests, The main function of itemprovideradapterfactory is to generate Itemprovider. In fact, when constructing an EMF application, we often have to modify the code in the Itemprovider, while the itemprovideradapterfactory is rarely changed.

Figure 1 An EMF-generated. Edit Project

Attention:. The Itemprovideradapter name in the Edit project omits the word adapter, such as Categoryitemprovider rather than categoryitemprovideradapter, and you should be aware that it is a Adapter, because it does implement the Adapter interface. In the EMF there is also a special Itemprovider class for the adapter type, in which the itemprovider is not referring to it, but refers to the Xxxitemprovider, which is the subclass of the Itemprovideradapter.

Note: The adapter interface in EMF and the Iadaptable interface of Eclipse runtime are similar in name but not the same concept (see the previous translation post for iadaptable), the adapter in EMF equals the listener ( Listener, Observer), it listens to the object is EMF notifier, on a notifier can register multiple adapter. Itemprovideradapterfactory, on the other hand, are much like iadaptable, all of which can play the role of a dynamic transformation type, except that the former is typically used only for notifier to adapter conversions, while the latter has no restrictions. In addition, the name of the conversion method is different, the former is adapt () and the latter is Getadapter ().

It is easy to see from Figure 1 that itemprovider constitutes a major part of the. Edit project, and these itemprovider have several functions.

First, realize the function of ContentProvider and Labelprovider in JFace

The JFace Viewer (Viewer) is a wrapper over the controls in SWT, such as Tableviewer is a wrapper over the table, Treeviewer is a wrapper over the tree, and so on, which separates the control from the data displayed in the control in this way. So as to facilitate the updating of data display. Quite a few eclipse applications display data through the JFace Viewer, and the ContentProvider and labelprovider associated with the viewer control which data is displayed in the viewer, and how each data is displayed, respectively.

In the case of Treeviewer ContentProvider, the Itreecontentprovider interface should be implemented in JFace, which defines GetParent (), HasChildren (), and GetChildren () These three methods, where the Itreeitemcontentprovider interface corresponds to the EMF, this interface also has these three methods. Each itemprovider in the edit section implements this interface because the EMF already knows our model structure completely, so these three methods are already implemented in the Itemprovideradapter class. However, Itreeitemcontentprovider can not be directly to the jface of the treeviewer to use, so EMF provides a adapterfactorycontentprovider to do the matching work, You can see how to use it in the editor's code.

Labelprovider is similar in that it mainly controls the text and icons displayed. EMF generated Itemprovider defaults do not implement Itableitemlabelprovider, so if you want to use Tableviewer, modify the code to implement the Itableitemlabelprovider interface and additional methods. Please refer to the Productitemprovider in the online store example for details. From a jface perspective, Itemprovider is equivalent to integrating the ContentProvider and Labelprovider code of various viewers, and is a generic "contentlabelprovider". As a result, developers change their viewers with only a few changes to the code, rather than the traditional way of writing new ContentProvider and labelprovider for each viewer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.