Emf-edit function Analysis

Source: Internet
Author: User
Tags object implement list of attributes modify object object domain in domain

1. Emf.edit

A) Description: Emf.edit is located between Emf.editor and Emf.ecore, he played an intermediary role. He is responsible for translating UI-related requests from Emf.editor into Emf.ecore UI-independent calls. He needs to provide the following four features: implementing ContentProvider and Labelprovider to support the viewer display, and implementing the Ipropertysource for supporting the display of properties Implement the commandframework used to support the operation of the model, and implement the framework used to support modification notifications.



b) ContentProvider and Labelprovider

I. Figure:



Ii. Description: When Treeviewer needs to display the content, call her Icontentprovider's GetChildren (Object obj) method. This method is forwarded to the Adapterfactorycontentprovider interior. She uses the itemprovideradapterfactory she quotes to get a adapter of the Itreeitemcontentprovider type of obj, This adapter is a itemprovideradapter (here for Teacheritemprovider) that corresponds to the Ecore model generated by the EMF, Finally, the teacheritemprovider is responsible for generating the list of child nodes that need to be displayed.



Iii. Code:

Public Classadapterfactorycontentprovider implements Itreecontentprovider {

public Object []getchildren (Object object) {

Itreeitemcontentprovider Treeitemcontentprovider =

(Itreeitemcontentprovider) Adapterfactory.adapt (object,

Itreeitemcontentprovider.class);

return Treeitemcontentprovider.getchildren (object);

}

}

Note: Red is a UI-related request, Blue is a UI-independent adapter class, and Pink is a UI-independent request.



c) Ipropertysource

I. Figure:



Ii. Description: When Propertysheetpage needs to display the property content, he accesses his ipropertysourceprovider getpropertysource (Object obj) method. This method is forwarded to the Adapterfactorycontentprovider interior. She uses the itemprovideradapterfactory she quotes to get a adapter of the Iitempropertysource type of obj, This adapter is a itemprovideradapter (here for Teacheritemprovider) that corresponds to the Ecore model generated by the EMF, Finally, this teacheritemprovider is responsible for generating the list of attributes that need to be displayed.

Iii. Code:

Public Classadapterfactorycontentprovider implements ipropertysourceprovider{

Public Ipropertysource Getpropertysource (Object object) {

Iitempropertysource Itempropertysource = (iitempropertysource)

Adapterfactory.adapt (Object,iitempropertysource.class));

...

}

}



d) Command Framework

I. Figure:



Ii. Description: Since Emf.editor does not understand the underlying model details, he cannot manipulate the model directly, and he needs to generate some command objects to manipulate the model. When editor needs to modify the model, he creates a Command object for the model operation by calling his CreateCommand (editingdomain domain) method. The method will eventually be forwarded to CreateCommand () in domain, and domain will obtain a Ieditingdomainitemprovider adapter based on the itemprovideradapterfactory he references. , and he finally generates the Command object that is used to manipulate the model.



Iii. Code:

public class Deleteaction extendscommandactionhandler{

Public Commandcreatecommand (Collection selection) {

Returnremovecommand.create (domain, selection);

}

}

public class Removecommand extendsabstractoverrideablecommand{

public static commandcreate (...) {

Return Domain.createcommand (...);

}

}

Public Classadapterfactoryeditingdomain implements editingdomain{

Public Commandcreatecommand (...) {

Ieditingdomainitemprovider Editingdomainitemprovider =

(Ieditingdomainitemprovider) adapterfactory.adapt (owner,

Ieditingdomainitemprovider.class);

Returneditingdomainitemprovider.createcommand (...);

}

}

Note: When you need to execute the command, editor invokes the Commandstack on Editingdomain and invokes the Execute (command C) method above him.



e) Notify Framework

I. Figure:



Ii. Description: When we modify the value of the model, the model will issue an update notification to his corresponding itemprovider, which is then forwarded to the Itemprovideradapterfactory, which is then eventually sent to Adapterfactorycon Tentprovider, and he will be responsible for updating the corresponding 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.