Previous | Next |
To help you create the mechanisms that allow users to select and manipulate data, Bean Works provides abstractions for both selection and command objects. A selection lets the user select some (or all) of the data in a model, and a command takes target data, often specified by a selection, and performs some action on it. For example, in a bitmap editing component, the user might select some region of the graphic, and then apply a change to it using a command-driven menu item:
This mechanism provides you with a way to specify and manipulate data that is independent of the data itself.
A selection object doesn't actually contain any data, it just provides a specification of data. Typically you create a selection class that works with a model and has a specification mechanism that is appropriate for the type of data in that model. This might be, for example, a geometric region in a bitmap, identifiers for cells in a table or spreadsheet, or a range of characters within a larger text string. You can then design suites of commands that manipulate the type of data specified. For example, for a selection specifying text data, you might create commands that access the selected characters and change their font, underline them, or convert them to uppercase.
Your selection classes should provide all the necessary access to the data in the model. By doing this, you can create commands that only call methods on the selection to access data, rather than calling the model's methods directly. This supports the undo/redo capability provided by the command processor, and ensures that commands always operate on the correct data, even when components are streamed in and out of persistent storage or run in different address spaces.
The connection between the selection and the model objects for a component is maintained by the component controller. Typically, there is always a current selection on the component's model. In some cases, the current selection is simply undefined when no data is selected. In other cases, an empty selection (as opposed to an undefined selection) is meaningful. For example, in a component that handles text data, an empty selection may be used to indicate the current insertion point. If you define a selection class for your component, the controller initializes a current selection automatically at runtime.
You create command classes that each encapsulate a specific change to target data (typically a selection). For example, you might create a command that deletes the selected object, that underlines a selected text string, or that retrieves data associated with a selected account number from a database. Bean Works includes a command processor that provides automatic support for undo and redo of commands as long as you implement the necessary methods and ensure that your command objects maintain the data they need to undo the changes they make. For example, a command that deletes selected text needs to save the deleted string so that it can be reinserted if the user undoes the command.
See Bean Works Architecture for information on the Java classes that provide the abstractions for selections and commands.
Previous | Next |
Copyright ©
Taligent, Inc. 1996 - 1997.
Copyright © IBM Corporation 1996 - 1997.
All Rights Reserved.