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.
Methods for navigating among nodes and links
The three following methods navigate the
model object tree.
- getObjects returns the enumeration of all top-level objects.
- getChildren returns all the children of the given model object.
- getParent 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:
Methods for retrieving ID, tag, and properties
The following methods give information on
a model object:
- getID 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 returns the model object associated with the given ID.
- getTag 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 returns a String array that represents all the defined properties for this object.
- getObjectProperty returns an object representing the value of the given property on the given object.
Methods for implementing listeners
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.
- [ addSDMModelListener| removeSDMModelListener] manages a listener list for model events. A model event should be fired when the model hierarchy or a model object property is changed.
- [ addSDMPropertyChangeListener| removeSDMPropertyChangeListener] manages a listener list for property change events. A property change event should be fired when a model object property is changed.
Methods for editable models
All the editable methods are meant to be implemented if the model
predicate isEditable returns
true
.
The following methods modify the model
hierarchy:
- createNode and createLink create, respectively, a node and a link. The argument represents the object tag. These methods return a model object.
- addObject 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 isnull
). - removeObject removes the given object from the model.
- clear removes all objects at once.
The following model methods change object
properties:
- setObjectProperty 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 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 can be used to warn the model that several properties are about to be changed.