public class IlvMultipleSDMModel extends IlvBasicSDMModel implements SDMModelListener, SDMPropertyChangeListener
IlvMultipleSDMModel
lets you combine several SDM models
(called the "submodels")
into a single one. It is especially useful when used with the IlvTableSDMModel
,
when you need to combine several tables into one SDM model.
The multiple model will delegate most of its calls to the submodel to
which an object belongs. To determine the owner model for each object,
it will call the getModel(java.lang.Object)
method. The default implementation uses a hash map
to store the submodel to which an object belongs. This default implementation
may not be very efficient, so it is recommended, if possible, to write a subclass
and override the getModel(java.lang.Object)
and setModel(java.lang.Object, ilog.views.sdm.IlvSDMModel)
methods with
a more efficient implementation (for example, storing the model in a member variable
of the data object).
The multiple model can resolve intermodel links, that is,
links contained in a submodel and connecting nodes in other
submodels. For such links to work, the submodel containing the intermodel links
must implement the IlvInterModelLinks
interface. Then
the source and destination nodes of links can be resolved by querying their
IDs and searching for the nodes globally in all the submodels.
Modifier and Type | Class and Description |
---|---|
static interface |
IlvMultipleSDMModel.OwnedObject
This interface can be implemented by nodes and links contained in
models that are combined using an
IlvMultipleSDMModel . |
Constructor and Description |
---|
IlvMultipleSDMModel()
Creates a new multiple model with no submodels.
|
IlvMultipleSDMModel(IlvSDMModel[] models)
Creates a new multiple model that combines the specified submodels.
|
Modifier and Type | Method and Description |
---|---|
void |
addModel(IlvSDMModel model)
Adds a submodel at the end of the list.
|
void |
addModel(IlvSDMModel model,
int index)
Adds a submodel at a specified position.
|
void |
addObject(Object object,
Object parent,
Object before)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
void |
adjustmentFinished(SDMModelEvent event)
This method is called at the end of an adjustment sequence on the underlying filtered model.
|
void |
clear()
Clears all the submodels.
|
Object |
createLink(String tag)
This method returns
null , because it is not possible
in general to know which submodel must be called to create the new object. |
Object |
createNode(String tag)
This method returns
null , because it is not possible
in general to know which submodel must be called to create the new object. |
void |
dataChanged(SDMModelEvent event)
This method is called when the contents of a submodel are changed.
|
Enumeration |
getChildren(Object parent)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
Object |
getFrom(Object link)
This method handles intermodel links: if the submodel containing the link implements
the
IlvInterModelLinks interface, this method first queries the
source node's ID by calling IlvInterModelLinks.getFromID(java.lang.Object) , then
it searches for the source node in all the submodels by calling getObject(java.lang.String) . |
String |
getID(Object obj)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
String |
getIDImpl(Object obj)
This method calls
getID(java.lang.Object) . |
protected IlvSDMModel |
getModel(Object obj)
This method determines the model to which an object belongs.
|
IlvSDMModel[] |
getModels()
Returns the submodels that this multiple model combines.
|
Object |
getObject(String id)
Finds the object with the specified ID in all the submodels.
|
Object |
getObjectProperty(Object obj,
String property)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
String[] |
getObjectPropertyNames(Object obj)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
Enumeration |
getObjects()
Returns the objects of each submodel, one after another in the order
in which the submodels were added.
|
Object |
getParent(Object obj)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
String |
getTag(Object obj)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
Object |
getTo(Object link)
This method handles intermodel links: if the submodel containing the link implements
the
IlvInterModelLinks interface, this method first queries the
destination node's ID by calling IlvInterModelLinks.getToID(java.lang.Object) , then
it searches for the destination node in all the submodels by calling getObject(java.lang.String) . |
boolean |
isAdjusting()
Returns the last value passed to
IlvBasicSDMModel.setAdjusting(boolean) . |
boolean |
isEditable()
Returns
true if all submodels are editable. |
boolean |
isLink(Object obj)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
void |
linkDestinationChanged(SDMModelEvent event)
This method is called when the destination of a link has changed in a submodel.
|
void |
linkSourceChanged(SDMModelEvent event)
This method is called when the source of a link has changed in a submodel.
|
void |
objectAdded(SDMModelEvent event)
This method is called when an object is added to a submodel.
|
void |
objectRemoved(SDMModelEvent event)
This method is called when an object is removed from a submodel.
|
void |
propertyChanged(SDMPropertyChangeEvent event)
This method is called when a property of an object of a submodel is changed.
|
void |
removeModel(IlvSDMModel model)
Removes a submodel.
|
void |
removeObject(Object object)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
void |
setAdjusting(boolean adjusting)
This method sets the flag indicating
that subsequent calls to the editing methods should
be treated as a single modification.
|
void |
setFrom(Object link,
Object node)
This method handles intermodel links: if the submodel containing the link implements
the
IlvInterModelLinks interface, this method calls IlvInterModelLinks.setFromID(java.lang.Object, java.lang.String)
with the ID of the source node. |
void |
setID(Object obj,
String id)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
void |
setIDImpl(Object obj,
String id)
This method calls
setID(java.lang.Object, java.lang.String) . |
protected void |
setModel(Object obj,
IlvSDMModel model)
This method is called every time an object is returned by the
enumeration resulting from the
getObjects() method. |
void |
setModels(IlvSDMModel[] models)
Sets the submodels that this multiple model combines.
|
void |
setObjectProperty(Object object,
String property,
Object value)
This call is delegated to the submodel returned by
getModel(java.lang.Object) . |
void |
setTo(Object link,
Object node)
This method handles intermodel links: if the submodel containing the link implements
the
IlvInterModelLinks interface, this method calls IlvInterModelLinks.setFromID(java.lang.Object, java.lang.String)
with the ID of the destination node. |
addObjectImpl, addSDMModelListener, addSDMPropertyChangeListener, allocID, contains, fireAdjustmentFinished, fireDataChanged, fireIDChanged, fireLinkDestinationChanged, fireLinkSourceChanged, fireObjectAdded, fireObjectRemoved, firePropertyChanged, firePropertyChanged, removeSDMModelListener, removeSDMPropertyChangeListener
public IlvMultipleSDMModel(IlvSDMModel[] models)
models
- The models to combine. This parameter may be null
,
in which case the submodels must be specified through setModels(ilog.views.sdm.IlvSDMModel[])
or addModel(ilog.views.sdm.IlvSDMModel)
.public IlvMultipleSDMModel()
setModels(ilog.views.sdm.IlvSDMModel[])
or addModel(ilog.views.sdm.IlvSDMModel)
.public void setModels(IlvSDMModel[] models)
models
- The models to combine.public IlvSDMModel[] getModels()
public void addModel(IlvSDMModel model)
model
- The submodel to add.public void addModel(IlvSDMModel model, int index)
model
- The submodel to add.index
- The position where the submodel must be inserted.public void removeModel(IlvSDMModel model)
model
- The submodel to remove.public Enumeration getObjects()
getObjects
in interface IlvSDMModel
IlvGraphic
s by the
IlvSDMViewRenderer
associated with the
IlvSDMView
. The returned enumeration
can be null
if the model has no objects.public Enumeration getChildren(Object parent)
getModel(java.lang.Object)
.getChildren
in interface IlvSDMModel
getChildren
in class IlvBasicSDMModel
parent
- The parent object.null
.public Object getParent(Object obj)
getModel(java.lang.Object)
.getParent
in interface IlvSDMModel
getParent
in class IlvBasicSDMModel
obj
- The child object.null
.public boolean isLink(Object obj)
getModel(java.lang.Object)
.isLink
in interface IlvSDMModel
isLink
in class IlvBasicSDMModel
obj
- The object whose type is queried.false
.public Object getFrom(Object link)
IlvInterModelLinks
interface, this method first queries the
source node's ID by calling IlvInterModelLinks.getFromID(java.lang.Object)
, then
it searches for the source node in all the submodels by calling getObject(java.lang.String)
.
If the link's model does not implement IlvInterModelLinks
,
this call is delegated to the submodel returned by getModel(java.lang.Object)
.
getFrom
in interface IlvSDMModel
getFrom
in class IlvBasicSDMModel
link
- The link whose source node is queried.null
.public Object getTo(Object link)
IlvInterModelLinks
interface, this method first queries the
destination node's ID by calling IlvInterModelLinks.getToID(java.lang.Object)
, then
it searches for the destination node in all the submodels by calling getObject(java.lang.String)
.
If the link's model does not implement IlvInterModelLinks
,
this call is delegated to the submodel returned by getModel(java.lang.Object)
.
getTo
in interface IlvSDMModel
getTo
in class IlvBasicSDMModel
link
- The link whose destination node is queried.null
.public String getID(Object obj)
getModel(java.lang.Object)
.getID
in interface IlvSDMModel
getID
in class IlvBasicSDMModel
obj
- The object whose identifier is requested.String
that identifies the object in a unique way.public String getIDImpl(Object obj)
getID(java.lang.Object)
.getIDImpl
in class IlvBasicSDMModel
obj
- The object whose identifier is requested.IlvBasicSDMModel.getID(java.lang.Object)
public void setID(Object obj, String id)
getModel(java.lang.Object)
.setID
in interface IlvSDMModel
setID
in class IlvBasicSDMModel
obj
- The object whose identifier is to be changed.id
- The new identifier.public void setIDImpl(Object obj, String id)
setID(java.lang.Object, java.lang.String)
.setIDImpl
in class IlvBasicSDMModel
obj
- The object whose identifier is to be set.id
- The new identifier.IlvBasicSDMModel.setID(java.lang.Object, java.lang.String)
public Object getObject(String id)
getObject
in interface IlvSDMModel
getObject
in class IlvBasicSDMModel
id
- The identifier of the requested object.id
.public String getTag(Object obj)
getModel(java.lang.Object)
.getTag
in interface IlvSDMModel
obj
- The object whose tag is requested.public Object getObjectProperty(Object obj, String property)
getModel(java.lang.Object)
.getObjectProperty
in interface IlvSDMModel
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.public String[] getObjectPropertyNames(Object obj)
getModel(java.lang.Object)
.getObjectPropertyNames
in interface IlvSDMModel
obj
- The object whose property names are queried.public boolean isEditable()
true
if all submodels are editable.isEditable
in interface IlvSDMModel
isEditable
in class IlvBasicSDMModel
public void addObject(Object object, Object parent, Object before)
getModel(java.lang.Object)
.addObject
in interface IlvSDMModel
addObject
in class IlvBasicSDMModel
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.public void removeObject(Object object)
getModel(java.lang.Object)
.removeObject
in interface IlvSDMModel
removeObject
in class IlvBasicSDMModel
object
- The object to remove.public void setObjectProperty(Object object, String property, Object value)
getModel(java.lang.Object)
.setObjectProperty
in interface IlvSDMModel
setObjectProperty
in class IlvBasicSDMModel
object
- The object whose property is to be set.property
- The name of the property to set.value
- The new value of the property.public Object createNode(String tag)
null
, because it is not possible
in general to know which submodel must be called to create the new object.
Subclasses should override this method and determine how the new object
must be created.createNode
in interface IlvSDMModel
createNode
in class IlvBasicSDMModel
tag
- The tag of the new node.public Object createLink(String tag)
null
, because it is not possible
in general to know which submodel must be called to create the new object.
Subclasses should override this method and determine how the new object
must be created.createLink
in interface IlvSDMModel
createLink
in class IlvBasicSDMModel
tag
- The tag of the new link.public void setFrom(Object link, Object node)
IlvInterModelLinks
interface, this method calls IlvInterModelLinks.setFromID(java.lang.Object, java.lang.String)
with the ID of the source node.
If the link's model does not implement IlvInterModelLinks
,
this call is delegated to the submodel returned by getModel(java.lang.Object)
.
setFrom
in interface IlvSDMModel
setFrom
in class IlvBasicSDMModel
link
- The link whose source node must be set.node
- The new source node of the link.public void setTo(Object link, Object node)
IlvInterModelLinks
interface, this method calls IlvInterModelLinks.setFromID(java.lang.Object, java.lang.String)
with the ID of the destination node.
If the link's model does not implement IlvInterModelLinks
,
this call is delegated to the submodel returned by getModel(java.lang.Object)
.
setTo
in interface IlvSDMModel
setTo
in class IlvBasicSDMModel
link
- The link whose destination node must be set.node
- The new destination node of the link.public void setAdjusting(boolean adjusting)
setAdjusting
in interface IlvSDMModel
setAdjusting
in class IlvBasicSDMModel
adjusting
- The value of the flag.public boolean isAdjusting()
IlvBasicSDMModel.setAdjusting(boolean)
.isAdjusting
in interface IlvSDMModel
isAdjusting
in class IlvBasicSDMModel
public void clear()
clear
in interface IlvSDMModel
protected IlvSDMModel getModel(Object obj)
The implementation of this method can rely on the setModel(java.lang.Object, ilog.views.sdm.IlvSDMModel)
method being called for every object returned by the
enumeration resulting from the getObject(java.lang.String)
method. For example, if you use
a hash map to store the model, you can associate the model with the
object in setModel(java.lang.Object, ilog.views.sdm.IlvSDMModel)
, and retrieve it in getModel(java.lang.Object)
.
The default implementation tests if the object implements the
IlvMultipleSDMModel.OwnedObject
interface. If it does, the interface's
IlvMultipleSDMModel.OwnedObject.getModel()
is called. Otherwise, this method uses a
HashMap
.
If the objects of the submodels do not implement IlvMultipleSDMModel.OwnedObject
,
you are recommended, if you can, to override this method and use a more
efficient implementation, such as storing the model in a member
variable in the object.
obj
- The data model object.setModel(java.lang.Object, ilog.views.sdm.IlvSDMModel)
,
IlvMultipleSDMModel.OwnedObject
protected void setModel(Object obj, IlvSDMModel model)
getObjects()
method.
This method should associate the model with the object in the
most effective way, so that subsequent calls to getModel(java.lang.Object)
return the correct model.
Note: This method must also be called by createNode(java.lang.String)
and createLink(java.lang.String)
when a new object is created.
The default implementation tests if the object implements the
IlvMultipleSDMModel.OwnedObject
interface. If it does, the interface's
IlvMultipleSDMModel.OwnedObject.setModel(ilog.views.sdm.IlvSDMModel)
is called. Otherwise, this method uses a
HashMap
.
If the objects of the submodels do not implement IlvMultipleSDMModel.OwnedObject
,
you are recommended, if you can, to override this method and use a more
efficient implementation, such as storing the model in a member
variable in the object.
public void objectAdded(SDMModelEvent event)
IlvBasicSDMModel.fireObjectAdded(java.lang.Object)
to propagate
the event to the listeners of this multiple model.objectAdded
in interface SDMModelListener
event
- The event that was fired by the submodel.public void objectRemoved(SDMModelEvent event)
IlvBasicSDMModel.fireObjectRemoved(java.lang.Object)
to propagate
the event to the listeners of this multiple model.objectRemoved
in interface SDMModelListener
event
- The event that was fired by the submodel.public void dataChanged(SDMModelEvent event)
IlvBasicSDMModel.fireDataChanged(java.lang.Object)
to propagate
the event to the listeners of this multiple model.dataChanged
in interface SDMModelListener
event
- The event that was fired by the submodel.public void linkSourceChanged(SDMModelEvent event)
IlvBasicSDMModel.fireLinkSourceChanged(java.lang.Object)
to propagate
the event to the listeners of this multiple model.linkSourceChanged
in interface SDMModelListener
event
- The event that was fired by the submodel.public void linkDestinationChanged(SDMModelEvent event)
IlvBasicSDMModel.fireLinkDestinationChanged(java.lang.Object)
to propagate
the event to the listeners of this multiple model.linkDestinationChanged
in interface SDMModelListener
event
- The event that was fired by the submodel.public void adjustmentFinished(SDMModelEvent event)
IlvBasicSDMModel.fireAdjustmentFinished()
to propagate
the event to the listeners of this multiple model.adjustmentFinished
in interface SDMModelListener
event
- The event that was fired by the submodel.public void propertyChanged(SDMPropertyChangeEvent event)
IlvBasicSDMModel.firePropertyChanged(java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object)
to propagate
the event to the listeners of this multiple model.propertyChanged
in interface SDMPropertyChangeListener
event
- The event that was fired by the submodel.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.