First you should decide which classes in the
model
package are appropriate, depending on the characteristics of your
existing business data and your requirements.
There are five levels of data model
implementation, each appropriate for certain situations:
- No use of existing data.There are three possible situations:
- You do not have existing data that you want to display and you will create your diagram(s) from scratch.
- You have existing data, but you want to duplicate it before displaying it, and it does not matter how the data will be represented in memory.
- You have exported your data to an XML file, and you want to read in the XML data.
In these cases, use the default SDM model implementation, IlvDefaultSDMModel.The nodes and the links of the default model are instances of the classes IlvDefaultSDMNode and IlvDefaultSDMLink. These objects have an arbitrary set of user-defined properties, so the default model can represent all kinds of objects. - Display existing data in a database.Your data is stored in a database, and you want to display it but not modify it directly in the diagram component.The
model
package provides a specific SDM model for this case: IlvJDBCSDMModel. This model uses the JDBC™ API to access the database. All you need to do is configure the model with the database URL, the names of the tables containing the nodes and links, and a few other parameters. - Existing JavaBeans™ .You have existing data stored in classes which conform to the JavaBeans standard: there are accessor methods (
get
andset
) for each bean property.In this case, use the class IlvJavaBeanSDMModel. This model uses your JavaBeans as the nodes and links of a graph, so there is no duplication or additional memory consumption. The properties of nodes and links are read and written using the JavaBeans API. All you have to do is supply the set of JavaBeans that will make up your graph. For an example, see JavaBeans example. - Existing Java™ classes that are not JavaBeans or existing data but no Java classes.For example, you already have an implementation of a Swing JTree model that represents your data and you want to display the contents of the tree without duplicating data.One of the following cases applies:
- You have existing data represented by Java classes that are not JavaBeans.
- You want to display data that is not already represented in memory by Java classes.
In such cases, there are two possible approaches:- Use the class IlvAbstractSDMModel, and wrap your objects into new objects that implement the IlvSDMNode and IlvSDMLink interfaces. This requires an extra object allocation because of the indirection, but allows you to make use of the predefined interfaces for nodes and links. For an example, see NonJavaBeans example: abstract model variant.
- Subclass the basic model, IlvBasicSDMModel, and implement the methods that list the objects and retrieve the properties of each object. This requires more work but is more open, and may be preferable if all objects already exist. For an example, see NonJavaBeans example: basic model variant.
The following table summarizes the
strategies described in this section.
Summary of data model strategies
Data Characteristics
|
Recommended Class
|
---|---|
New or from XML
|
|
Database (display only)
|
|
JavaBeans
|
|
Java classes or other existing objects
(for example, Swing)
|
|
If the graphic objects are to be moved
interactively, SDM tries to store the new object locations as x,y
properties in the model. However, the model can refuse to set the
x,y properties, for example when it is a read-only model. To cope
with such a case, the SDM library provides a metadata system that
manages new properties as if they were stored in the true model.
To enable metadata, call
ilog.views.sdm.IlvSDMEngine.setMetadataEnabled(true)
. Metadata is saved only in XML files. Other persistent mechanisms
are responsible for saving metadata if they need to.
The default model does not need metadata.
![Diagram
showing the SDM model class relationships. IlvBasicSDMModel implements
IlvSDMModel, which carries the interface stereotype. It is also the
base class for IlvAbstractSDMModel and its IlvTableSDMModel and IlvDefaultSDMModel
subclasses, as well as the base class for IlvJavaBeanSDMModel, for
IlvMultipleSDMModel and its IlvJDBCSDMModel subclass, and for IlvFilterSDMModel
and its IlvRDFSDMModel subclass. IlvFilterSDMModel has a one-way arrow
pointing back to IlvSDMModel. This association is specified in the
diagram by the model label.](../../JViews_Diagrammer/usrextdiag/_media/dia_sdm_model_default.png)
The SDM Model class relationships
![Diagram
of the abstract SDM model class relationships among four classes and
four interfaces. IlvAbstractSDMModel is the base class for the IlvBasicSDMModel
class that implements IlvSDMModel. It depends on IlvMutableSDMNode
and IlvMutableSDMLink, and these dependencies carry the access stereotype.
It also depends on the IlvDefaultSDMNode and IlvDefaultSDMLink classes
that implement IlvMutableSDMNode and IlvMutableSDMLink. These dependencies
carry the instantiate stereotype. IlvDefaultSDMLink extends IlvDefaultSDMNode
and IlvMutableSDMLink.extends IlvMutableSDMNode and IlvSDMLink. IlvSDMNode
is the base interface for IlvMutableSDMNode. It can have zero or more
children that are an aggregate for IlvAbstractSDMModel. IlvSDMLink
extends IlvSDMNode, but also has one-way to and from associations
pointing to IlvSDMNode.](../../JViews_Diagrammer/usrextdiag/_media/dia_abstract_sdm_model2_default.png)
The abstract SDM Model class
relationships