The Swing architecture allows Java developers to create complex displays that render large amounts of data. Unfortunately, writing code to maintain those data within a large Swing component is a nightmare. In this article, Jonathan Simon introduces a technique called idata or intelligent data. You can use the Idata architecture to create a central repository of data within your application. This allows more thorough separation of the data from the display, and a clearer and more maintainable code that produces the data. There's even an open source toolbox with sample code to help you get started. Read on to learn more and see a sample implementation of Idata technology. Share your thoughts with the author and other readers on the forum.
The Advanced Swing architecture allows developers to design more complex displays than ever before. These displays often require a large number of highly error-prone and difficult to maintain logic. For advanced Swing components (for example, JTable and JTree), it is often difficult to use the program logic to store, edit, and render data based on the unit, often requiring more global knowledge. You can persist intelligent data, or data with advanced knowledge, as unit data in a component model, which provides the necessary knowledge to develop advanced applications. The Idata technology described in this article establishes a common architecture for integrating intelligent data with Swing components while retaining the model-view-controller (Model-view-controller) architecture. This is achieved through a tightly integrated indirect scheme that uses intelligent data for data storage, data retrieval, and display settings indirectly. The generated indirect object creates a flexible and scalable central location for complex business display logic and interactivity with minimal complexity.
Developers can get an open source Idata toolbox to help them integrate the idata architecture into their own projects. The Toolbox contains a collection of interfaces that define the indirect layer, default implementation, optimization, custom editor and renderer, and many examples. Please read resources for a link to the toolbox.
Three layers of idata technology
Idata technology contains three layers.
Data storage: Idata technology assumes that the application stores data in DataObject. People loosely define DataObject as JavaBean objects that contain fields and corresponding Get[fieldname] () and Set[fieldname] () methods.
Displays the data value of the component indirectly: the data indirect layer consists of an object that contains a DataObject definition. This is called intelligent data or idata layer. (Note that the idata layer is not confused with the Idata technology, which is the overall name of the architecture.) The Idata layer interface defines a common method for accessing and modifying fields in DataObject. For specific requirements, each concrete idata layer class implements these common values (accessor) and assignment (Mutator) methods. Typically, the idata layer implements the values in read only (get) and write (set) DataObject. However, as you will see in the example, this indirectly creates a central location for implementing complex logic that includes editing validation, virtual data, and data grooming. The idata layer is further subdivided into non modifiable (read-only) and modifiable (read/write) data functions. This distinction is made to simplify interfaces with complex non-editable data that do not need to be edited logically.
The display of custom editing and rendering components based on data is indirect: intelligent display, or idisplay layer, by using an indirection similar to the idata layer to complete the Smart Display. The IDisplay layer defines an interface for the components that edit and render idata layer objects. Examples of this idisplay layer customization include: Changing the cell background color to display error conditions, and creating generic editors that allow the idata layer implementation to determine which components are best suited for editing their data. Like the idata layer, the IDisplay layer is subdivided into modifiable data and unmodified data.
These three layers combine to create a tightly integrated set of indirect objects that are added to the component model rather than the data itself. This architecture makes it possible to base the knowledge of the unit, while retaining the model-view-controller architecture in Swing. The logic for retrieving, displaying, and editing data is encapsulated in a smart data object within each cell. The result is a functionally flexible and scalable technology that enables the display and interaction of complex user interfaces.
Figure 1. Complete architecture class diagram of Idata technology
Next, we'll discuss each layer of the Idata technology architecture. At the same time, we'll build some code snippets for the Imaginary Bicycle store (Bike shop) application to demonstrate the technology.