public interface IlvSDMModel
IlvSDMModel
interface describes a
set of objects that constitute a graph of nodes connected
by links.
The SDM model is designed to be used as the source of data
for an IlvSDMEngine
that will display
the data objects in a Rogue Wave JViews grapher.
The SDM model is independent of
any graphic representation, and can
be displayed under different forms, for
example in a table or in a chart.
An SDM model describes a set of objects of two types: links and nodes. It is mandatory for a link to connect two nodes, but it is not mandatory for a node to be connected to other nodes. In other words, the SDM model distinguishes only between links and "non-links". For simplicity, we call these "non-link" objects "nodes", even when they are not connected to other nodes.
The model can be hierarchical: each top-level node or link can have children. This set of children is called a "sub-model". The nodes of a sub-model can be connected together, and they can also be connected to nodes that are outside of the sub-model. In other words, it is legal for a link to connect two nodes that belong to different levels in the data hierarchy.
The SDM model makes no assumptions about the Java class
of the application objects: all node and link entities
are returned as instances of Object
. It is
possible, for example, that some nodes will belong to a
class and some other nodes will belong to another class.
It is up to the SDM engine's graphic renderer (or any other
object that displays the model) to create an
appropriate graphic representation of the application objects
returned by the model.
For most applications, you do not need to implement the
IlvSDMModel
interface from the start. You
can either use the IlvDefaultSDMModel
class that implements the interface using built-in
node and link types, or you can subclass
IlvBasicSDMModel
and override only
the methods that you need.
IlvSDMEngine
,
IlvDefaultSDMModel
,
IlvBasicSDMModel
Modifier and Type | Method and Description |
---|---|
void |
addObject(Object object,
Object parent,
Object before)
Adds an object to the model.
|
void |
addSDMModelListener(SDMModelListener listener)
Adds a listener to this SDM model.
|
void |
addSDMPropertyChangeListener(SDMPropertyChangeListener listener)
Adds a property change listener to this SDM model.
|
void |
clear()
Removes all the objects from the model.
|
Object |
createLink(String tag)
Creates a new link.
|
Object |
createNode(String tag)
Creates a new node.
|
Enumeration<?> |
getChildren(Object parent)
Returns the objects of a submodel.
|
Object |
getFrom(Object link)
Returns the application object that is the source
of the specified link.
|
String |
getID(Object obj)
Returns the identifier of the object.
|
Object |
getObject(String id)
Returns the object of the model whose identifier is
id . |
Object |
getObjectProperty(Object obj,
String property)
Returns a property of an object of the data.
|
String[] |
getObjectPropertyNames(Object obj)
Returns the names of the properties that can
be retrieved for an object.
|
Enumeration<?> |
getObjects()
Returns the application objects that represent the SDM
nodes and links.
|
Object |
getParent(Object obj)
Returns the parent of an object, if that object
belongs to a submodel.
|
String |
getTag(Object obj)
Returns the symbolic type (the "tag") of an object.
|
Object |
getTo(Object link)
Returns the application object that is the destination
of the specified link.
|
boolean |
isAdjusting()
Returns the last value passed to
setAdjusting(boolean) . |
boolean |
isEditable()
Specifies whether this model supports editing or not.
|
boolean |
isLink(Object obj)
Returns
true if the specified data object
is a link between two nodes. |
void |
removeObject(Object object)
Removes an object from the model.
|
void |
removeSDMModelListener(SDMModelListener listener)
Removes a listener from this SDM model.
|
void |
removeSDMPropertyChangeListener(SDMPropertyChangeListener listener)
Removes a property change listener from this SDM model.
|
void |
setAdjusting(boolean adjusting)
Call this method to tell the SDM model that subsequent calls to the
editing methods should be treated as a single modification.
|
void |
setFrom(Object link,
Object node)
Sets the node that is the source of the specified link.
|
void |
setID(Object obj,
String id)
Sets the identifier of an object.
|
void |
setObjectProperty(Object object,
String property,
Object value)
Sets the value of a property of an object of this model.
|
void |
setTo(Object link,
Object node)
Sets the node that is the destination of the specified link.
|
Enumeration<?> getObjects()
The nodes and the links are returned in a single enumeration, which makes it possible for an SDM model implementation to supply the data objects in a mixed order (for example, two nodes, then a link between them, then two other nodes, and so on).
Note that a link does not need to be enumerated after its end nodes, because the SDM engine handles forward references. Note, though, that loading the model will be faster if links are enumerated after their end nodes.
This method returns only the first level of the SDM,
not the subobjects that can be attached to an object.
If an object has a submodel, the elements of the
submodel are returned by the getChildren
method.
The SDM engine will call the isLink
method to find out whether each object is a link or
a node.
IlvGraphic
s by the
IlvSDMViewRenderer
associated with the
IlvSDMView
. The returned enumeration
can be null
if the model has no objects.Enumeration<?> getChildren(Object parent)
SDM renderers can decide to display subobjects in a special way, for instance with a "drill-down" node that displays the submodel only above a given zoom level.
The objects of the submodel can themselves have children.
parent
- An object returned by getObjects
or by a previous call to getChildren
.null
if the parent has no children.Object getParent(Object obj)
null
.
obj
- The object whose parent is queried.boolean isLink(Object obj)
true
if the specified data object
is a link between two nodes. When this method returns
true
, the model must be prepared to return
non-null values from the getFrom
and
getTo
methods.obj
- The object whose type is queried.true
if and only if the specified
data object is a link.Object getFrom(Object link)
This method will be called only for links, that is, SDM
objects for which the isLink
method returned true
.
The node returned by this method must be placed
before the link
in the
enumeration returned by getObjects
.
link
- The link whose source node is queried.Object getTo(Object link)
This method will be called only for links, that is, SDM
objects for which the isLink
method returned true
.
The node returned by this method must be placed
before the link
in the
enumeration returned by getObjects
.
link
- The link whose destination node is queried.String getID(Object obj)
getObject(java.lang.String)
.
The implementations of the methods getID(java.lang.Object)
and getObject(java.lang.String)
must guarantee that getObject(getID(obj)) == obj
for every object obj
in a given model.
obj
- The object whose identifier is requested.void setID(Object obj, String id)
getID(java.lang.Object)
has been called may result in the object not being
found any more by getObject(java.lang.String)
.
This method may do nothing if isEditable()
returns
false
.
obj
- The object whose identifier is to be changed.id
- The new identifier.Object getObject(String id)
id
.
The implementations of the methods getID(java.lang.Object)
and getObject(java.lang.String)
must guarantee that getObject(getID(obj)) == obj
for every object obj
in a given model.
id
- The identifier of the requested object.id
.String getTag(Object obj)
The tag can be seen as a primary style: it allows the SDM to represent objects with different tags in different ways. When the model is saved or loaded from an XML file, the tag will be the tag name of the XML element.
The tag of an object cannot be changed. In general, all the objects with the same tag should have the same properties.
obj
- The object whose tag is requested.Object getObjectProperty(Object obj, String property)
The properties of data objects are queried by the
SDM renderer, and used to set the graphic properties
of the IlvGraphic
object that represents
the data object obj
.
obj
- The object whose property is queried.property
- The name of the property.Object
representing the
value of the specified property, or null
if the object does not have or support the specified
property.String[] getObjectPropertyNames(Object obj)
obj
- The object whose property names are queried.void addSDMModelListener(SDMModelListener listener)
listener
- The listener to add.void removeSDMModelListener(SDMModelListener listener)
listener
- The listener to remove.void addSDMPropertyChangeListener(SDMPropertyChangeListener listener)
listener
- The listener to add.void removeSDMPropertyChangeListener(SDMPropertyChangeListener listener)
listener
- The listener to remove.boolean isEditable()
true
, the
methods addObject(java.lang.Object, java.lang.Object, java.lang.Object)
, removeObject(java.lang.Object)
, and
setObjectProperty(java.lang.Object, java.lang.String, java.lang.Object)
can be called to edit the
model. Otherwise, the editing methods may be empty.void addObject(Object object, Object parent, Object before)
This method should fire an
SDMModelListener.objectAdded(ilog.views.sdm.event.SDMModelEvent)
event to all SDMModelListener
s
registered with this model.
This method may do nothing if isEditable()
returns
false
.
object
- The new object to add to the model.parent
- The parent if the new object must be added
to a submodel, or null
if the new object
is a top-level object.before
- An existing object of the model before which
the new object must be inserted. You can pass null
to append the new object at the end of the model.void removeObject(Object object)
This method should fire an
SDMModelListener.objectRemoved(ilog.views.sdm.event.SDMModelEvent)
event to all SDMModelListener
s
registered with this model.
Note that if object
is a node, all the links connected
to this node will point to a nonexistent object. If you also want
the links coming from or going to that node to be removed from the
object model, you must call removeObject
on these links.
This method may do nothing if isEditable()
returns
false
.
object
- The object to remove.void setObjectProperty(Object object, String property, Object value)
This method should fire a
SDMPropertyChangeListener.propertyChanged(ilog.views.sdm.event.SDMPropertyChangeEvent)
event to all SDMPropertyChangeListener
s
registered with this model, not only for the given property
but also for all properties whose value implicitly depends on the value
of the given property
. This can be done through the methods
IlvBasicSDMModel.firePropertyChanged(Object, String, Object, Object)
or
IlvBasicSDMModel.firePropertyChanged(Object, String[], Object[], Object[])
.
This method may do nothing if isEditable()
returns
false
.
object
- The object whose property must be set.property
- The name of the property to set.value
- The new value of the property.Object createNode(String tag)
This method may return null
if isEditable()
returns
false
.
tag
- The tag of the new node.Object createLink(String tag)
This method may return null
if isEditable()
returns
false
.
tag
- The tag of the new link.void setFrom(Object link, Object node)
This method must be called only for links, that is, SDM
objects for which the isLink
method returned true
.
This method may do nothing if isEditable()
returns
false
.
link
- The link whose source node must be set.node
- The new source node of the link.void setTo(Object link, Object node)
This method must be called only for links, that is, SDM
objects for which the isLink
method returned true
.
This method may do nothing if isEditable()
returns
false
.
link
- The link whose destination node must be set.node
- The new destination node of the link.void setAdjusting(boolean adjusting)
boolean oldAdjusting = model.isAdjusting(); model.setAdjusting(true); try { Object obj = model.createNode("node"); obj.setObjectProperty("x", new Double(x)); obj.setObjectProperty("y", new Double(y)); obj.setObjectProperty("name", "Foo"); } finally { model.setAdjusting(oldAdjusting); }All
SDMModelEvent
events
fired during an adjustment sequence should have their
adjustment field set to this value.
If an IlvSDMEngine
is using the model, ILOG suggests that
you call IlvSDMEngine.setAdjusting(boolean)
instead.
adjusting
- The value of the flag.boolean isAdjusting()
setAdjusting(boolean)
.void clear()
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.