Using Rational Application Developer visual Editor to implement Swing visual components and data binding
Introduction
The Java™ visual Editor allows users to graphically edit the Java user interface. This functionality is further enhanced in the IBM Rational application Developer for Websphere®software V6. Because V6 supports the rapid binding of visual components to data from different sources, for example, this data can originate from Web services or EJB components. This article describes how to use the excellent features of data binding, using a fast and powerful way to define the user interface of data reading and data writing.
Swing Overview
Like many other parts, the AWT (Abstract window tool) and Swing graphical interface components are included in the Java Basic Class library (JFC), which provides a framework to easily construct a graphical user interface (GUI) that adds rich graphical functionality and interoperability to Java applications. Swing is a versatile general-purpose toolkit that offers a number of very useful features. But for our purposes, here we focus on two important features, because these two features are most important for understanding the binding model and binding operations of the visual editor.
Using Swing's data model
Most Swing components have models that allow you to flexibly decide how to store and retrieve data in your application. Among them, there are two such models in the data binding tool of Rational application Developer (hereinafter referred to as Application Developer), which are document and table models, and let's look at these two models:
Figure 1: Document-blocking model
In the document model (Figure 1), the text component is used to separate data from its data view (called a model), which implements the Javax.swing.text.Document interface and provides the following services:
Contains text. The document stores the text content in a Javax.swing.text.Element object, and can also represent arbitrary text logic structures, such as paragraphs, shared style text, and so on.
Support for text editing is provided through remove (string astring) and insertstring (int position, string astring, AttributeSet anattributeset).
Notifies the document listener of changes to the text and enables the editing listener to undo the changes.
Manage Position objects. When text content is changed, the Position object tracks specific positions in the text.
Enables you to get information about the text, such as its length, and the text fragment.