Summary of GEF and EMF plug-in Design Patterns in eclipse

Source: Internet
Author: User

GEF (Graphical Editor framework) is a graphical editing framework that allows developers to visually display and edit models to improve user experience. With GEF, you can easily implement XML editor, UML class diagram editor, and other applications.Program.

EMF (eclipse modelling framework) is an important part of the Model Driven Architecture of eclipse. It can convert models into efficient, correct, and easy-to-Customize JavaCode.

Based on GEF and EMF, model-driven development (MDD) can be easily implemented. This article combines GEF and EMF plug-ins in graduate design, develop a Graphical Editor plug-in based on object-oriented Petri Net (a Petri Net, a mathematical representation of asynchronous and concurrent computer system models. During this period, I came across some of the design patterns used in these two plug-ins and shared them with you.

1. MVC

GEF uses the MVC framework to eliminate coupling between models and views:
(1) model: It can be expressed by any Java object. The model must have a notification mechanism.
(2) view: Figure/treeitems. In a typical graphicaleditor, figure is the draw2d figure used for display in graphicalviewer, while treeitems is used to display information in the treeviewer in outline.
(3) controller: Usually each figure corresponds to an editpart. editpart is used to control the model and view. Many modification tasks are implemented through editpolicy.

2. Command

Commands in GEF encapsulate modifications to the model. You can inherit the abstract class command in GEF to provide redo/undo functions. We mainly use execute ()/Redo () /undo.

3. chain of responsibility

Chain of responsibility transmits a request to multiple objects and gives these objects the opportunity to process the request, thus decoupling the request sender and receiver. In GEF, multiple editpolicies can receive requests and return commands. These commands are chained together.
In addition, as well as the message distribution mechanism in EMF.

4. State

Allows the Graphical Editor to modify its behavior when its internal status changes. For GEF editor, you can switch the tool to change the editor status. For example, for a mouse-pressed event, the editor performs different operations under the activation selection tool and activation creation tool. For details, see the org. Eclipse. GEF. tool interface. abstracttool defines several States, state_xxx.

5. Abstract Factory

GEF provides interfaces to create a series of related or dependent objects. This mode is used when an editorial component is created based on the model component.
In GEF, different editparts are created based on editpartfactory. In EMF, the factory class modelelementfactory that creates model elements is provided.

6. Factory method

Defines the method to create an object, but allows the subclass to determine the class to be instantiated. This mode is not discussed separately, but it is another optional method for creating an editorial component. The createchild method allows you to create a sub-Editorial component without using the factory.

7. Adapter

The getadapter (class key) method in the editpart of the GEF controller.
The notifier-adapter mechanism of EMF.

8. Singleton

The single plugin instance class abstractuiplugin Of The Eclipse plug-in project ensures that the plug-in is instantiated only once after running.

9. Composite

The composite of each display element in GEF exists in a composite relationship.
In EMF, composite models and submodels are also locked in a composite relationship.

10. Observer

The editpart in GEF is registered to the EMF model object as the observer. It monitors model changes and notifies the view to update the model.

Summary

By using a large number of design patterns, the flexibility and scalability of GEF and EMF plug-ins are achieved, facilitating development.

Related Article

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.