EMF Introduction Series (third, basic method of customizing applications)

Source: Internet
Author: User

With the help of EMF, you can generate a complete application without writing one line of code yourself, are you interested in EMF? But the resulting application looks like it's coming from the same mold, a multi-page editor, an outline view, and a property page, which of course doesn't meet everyone's needs. No need to worry, as long as we understand the EMF mechanism, to modify the application according to our requirements is not a very difficult thing.

First look at what EMF has generated for us. As previously described, EMF should generate four plug-in projects: Com.my.shop, Com.my.shop.edit, Com.my.shop.editor and Com.my.shop.tests, One of the last items is the framework code to help us write unit tests, and we'll focus on the first three projects for a while.

The first project is the model part, which contains the various types (Eclass, in the Ecore metamodel, the type called Eclass, the attribute called the Eattribute) corresponding Java interface and the default implementation class code, for example, in the Ecore model you define, such as Product.java and Productimpl.java, respectively, are placed in com.my.shop and Com.my.shop.impl packs; a factory class (Shopfactory) creates a new model instance using the factory pattern; The Package Class (Shoppackage) maintains information about the meta model, provides a bunch of static member variables, and also generates Shopadapterfactory and Shopswitch two classes, which are optional, and their roles are sold here for the time being.

The second project is the. Edit section, which contains a series of itemprovider classes to facilitate the display of these model objects in the various viewer (viewer) of the JFace, taking Categoryitemprovider as an example, which implements the Istructureditemcontentprovider, Itreeitemcontentprovider and Iitemlabelprovider These interfaces, note that the "Item" in these interface names is removed JFace in need of provider, you can take these words with "Item" provider imagine to jface corresponding provider packaging. With these Provider, it is convenient to use JFace Treeviewer, Tableviewer, and so on in your application. (In a previous GEF post, the EMF construction model was used, which was only part of the model, because the JFace viewer was not used.) So depending on your application, you can just generate the model part to use,. Edit partially relies on the model part, not the other. )

The third item is the editor, which relies on the. Edit section, which contains several UI-related classes. EMF generates this editor for us for two purposes: one allows us to modify the editor based on the editor without starting from scratch, and to show you how to use those classes in the first two projects in your application. The editor contains so many tabs to demonstrate the use of various viewers. Here's how to customize the generated application.

Modification of Ecore model and Genmodel model

In the Ecore model and the Genmodel model, we can modify the generated code by modifying some attribute changes, such as "(unnamed)", which means that the name of the newly created category and product is not an empty string, but the Namedelement class's Name property can be modified in the class diagram. Default Value Literal Property (yes, property properties.) See Figure 1). After modifying the Ecore model, you must update the Genmodel model by right-clicking the Shop.genmodel file in Package Explorer and selecting "Reload ..." in the pop-up menu so that Genmodel will change from the modified Ecore model To get the modified information. After that, the code is generated again from the Genmodel model, so that when the resulting program is run, the name of the category and product is "(unnamed)" by default. In the Genmodel model, you can customize more properties, such as the ID of each item that is generated, the package name of the generated class (in this case, com.my), the class name prefix (in this case, the shop), whether to generate an icon, a classification of the properties in the Standard property page, and so on

Figure 1 Modifying the default value of a property in the Eclipseuml class diagram

Some people are confused about the use of the Ecore model and the Genmodel model, because jet is generating code directly through Genmodel, so it's more appropriate to have the information like whether or not to generate an icon in the Genmodel, and The Ecore model defines the various types and relationships, so information like the default value of a property should be placed in the Ecore right.

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.