Implementing MVC in Custom SWT components

Source: Internet
Author: User

Learn how to easily integrate model-view-controller with Eclipse based applications

Introduction: Eclipse SWT (Standard part Toolkit) provides a rich set of APIs to implement custom widgets (widgets). In this article, the author briefly outlines the MVC (model-View-Controller) architecture, explains the current implementation of MVC in the form of a structured viewer, and introduces an implementation that uses custom SWT widgets.

What is MVC?

The MVC architecture (or design pattern) is a graphical user interface (GUI) design style, consisting of three parts: models, views, and controllers. MVC decoupled the presentation layer from the data, and also decoupled the representation from the operation of the data.

Implementing the MVC architecture differs from other types of applications. The main differences come from how to place and implement business logic or view rendering logic. Unlike a typical WEB application, in which a programmer must design and implement all the MVC components, the API provided by Eclipse can do most of the control or rendering work for you. Therefore, it is not strictly possible to compare the MVC implementation of Eclipse with the Web or MVC of other application types.

Eclipse JFace

The Eclipse JFace implements the MVC architecture with content providers and label providers. The JFace API wraps standard (not unimportant) parts, such as tables and trees, and implements structured content providers and label providers. Different content providers can be implemented based on the part type. A list-oriented viewer implements a structured viewer, while the content is mapped to part entries in a structured (list) manner.

The base class, called the viewer, is an extension of the structured viewer. The viewer acts as a part container. The content provider obtains the data in a structured manner; Similarly, the label provider obtains the corresponding label. The JFace Viewer implementation retrieves the data, sets the corresponding association, and updates the user interface (UI) component with the dataset. It also performs selection, filtering, and sorting.

How to implement JFace

Eclipse View and Viewer are responsible for performing most of the JFace control functions. The Viewer, or the view portion of MVC, also acts as a component container;

Eclipse View instantiates the viewer, content provider, and label provider and acts as a model, holds value objects, and sets them to inputelement in the viewer.

To create a View, instantiate the Viewer with the Createpartcontrol () method. Listing 1 instantiates a default tree viewer, or you can customize the tree and use the tree object as a parameter to instantiate the tree viewer with the constructor.

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.