| Developing with the SDK > Using and Writing Data Models > Implementing the Behavior of Data Model Objects |
Implementing the Behavior of Data Model Objects |
INDEX
PREVIOUS
NEXT
|
The methods that implement the possible behavior of data model objects are supplied as the IlvSDMModel interface. Various supplied data model classes implement different subsets of these methods.
The methods in the interface recognize links as distinct from other objects and allow for parent-child relationships to implement a hierarchical model. Each data model object has a unique identifier (ID), a nonunique tag, and various properties (attributes). For links, the From and To properties store the end points. The monitoring of changes is available through a listener mechanism.
The three following methods navigate the model object tree.
getObjects returns the enumeration of all top-level objects.
getChildren(Object) returns all the children of the given model object.
getParent(Object) returns the parent of the given object in the model tree, or null if the object is at the top level.
When a model object is a link, the following methods apply:
isLink(Object) returns true if the given parameter is a link. The model must be prepared to return valid values on getFrom and getTo calls on a link.
getFrom(Object) returns the model object that is the source of the given link.
getTo(Object) returns the model object that is the destination of the given link.
The following methods give information on a model object:
getID(Object) returns the unique ID (a String) associated with the object. IDs are used to define the references from a link to its source and destination nodes.
getObject(String) returns the model object associated with the given ID.
getTag(Object) returns the tag of a model object. The tag is a String that describes the type of the model object. Several objects may share the same tag. For example, the tag is the name of the XML element in an XML data file.
getObjectPropertyNames(Object) returns a String array that represents all the defined properties for this object.
getObjectProperty(Object, String) returns an object representing the value of the given property on the given object.
The model is dynamic: it can change itself. To keep the graphical display consistent with the model state, there is a listener mechanism that sends events when a modification occurs in the model.
add|remove]SDMModelListener(SDMModelListener) manages a listener list for model events. A model event should be fired when the model hierarchy or a model object property is changed.
add|remove]SDMPropertyChangeListener(SDMPropertyChangeListener) manages a listener list for property change events. A property change event should be fired when a model object property is changed.
All the editable methods are meant to be implemented if the model predicate isEditable returns true.
The following methods modify the model hierarchy:
createNode(String) and createLink(String) create, respectively, a node and a link. The argument represents the object tag. These methods return a model object.
addObject(Object, Object, Object) adds the first argument to the model below the second one (or at the top level if the second argument is null), and before the third argument (or at the end if the third argument is null).
removeObject(Object) removes the given object from the model.
clear removes all objects at once.
The following model methods change object properties:
setFrom(Object, Object) and setTo (Object, Object) modify the source and destination objects of a link. The first argument is the link; the second one is the new end point.
setObjectProperty(Object, String, Object) changes a model object property. The first argument is the model object, the second one is the property name, and the third one is the property value.
setID (Object, String) allows you to change the ID of a model object. It is wise to call this method before adding the object to the model to make sure that there is always a unique, stable ID for each model object.
isAdjusting and setAdjusting(boolean) can be used to warn the model that several properties are about to be changed.
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |