Using the graphical editing framework to create an eclipse based application

Source: Internet
Author: User

This article provides you with the steps to use GEF from beginning to end. Instead of completing each step in its entirety, we will use a subset of your application model and make that subset work first. For example, at first we might ignore the connection, or focus on only a subset of the graphic element types in your application.

GEF Overview

GEF assumes that you have a model that you want to graphically display and edit. To do this, GEF provides a viewer (type Editpartviewer) that can be used anywhere in the Eclipse Workbench. Like the JFace Viewer, the GEF Viewer is an adapter on an SWT control. But their similarities are just that. The GEF Viewer is based on the model-view-controller (MODEL-VIEW-CONTROLLER,MVC) architecture.

The controller acts as a bridge between the view and the model (see Figure 1). Each controller (the so-called EditPart in this article) is responsible for mapping the model to its view and for making changes to the model. EditPart also observes the model and updates the view to reflect changes in the state of the model. EditPart is an object in which users interact with this object. EditPart will be introduced in more detail later.

Figure 1. Model-View-controller

GEF provides two types of viewers: graphical and tree based. Each viewer is responsible for a different type of view. The Graphics Viewer uses graphics (figure) that are drawn on the SWT canvas (Canvas). Graphics are defined in the DRAW2D plug-in, which is part of GEF. Treeviewer use SWT trees and TreeItem for their views.

The 1th step. Choose Your own model

GEF knew nothing about the model. Any model type can work as long as it conforms to the attributes described below.

What's in the model?

All things are in the model. The model is the only thing that will be permanently stored and restored. Your application should store all of the important data in the model. In the process of editing, undoing, and redo, the model is the only thing that remains unchanged. Over time, graphics and EditPart will be garbage collected and recreated.

When the user interacts with the EditPart, EditPart does not directly manipulate the model. Instead, you create a command that encapsulates the changes. Commands can be used to authenticate user interactions and provide undo and redo support.

Strictly speaking, the command concept is also part of the model. They are not models themselves, but some methods, and the models are edited by these methods. command is used to perform all of the user's revocable changes. In theory, the command should only understand the model. They should avoid referencing EditPart or graphics. Similarly, if possible, the command should avoid invoking the user interface (for example, a pop-up dialog box).

Two stories of a model

A simple GEF application is the editor for drawing diagrams. (This diagram only means that the picture, not the class diagram, etc.) can be modeled as some shapes. A shape may have attributes such as location, color, and possibly a set of structures that are composed of multiple shapes. There is nothing to be surprised about, and the aforementioned requirements are easy to maintain (see Figure 2).

Figure 2. A simple model

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.