Java Data Sources > Working with the Server/Java Mapping > SDM (Stylable Data Mapper) > Working with SDM Data Sources
 
Working with SDM Data Sources
Presentation
The SDM data source connects and synchronizes a business model running in an Rogue Wave® Server to an SDM model running and displayed in a JavaTM client. Rogue Wave Server offers bidirectional synchronization between the two models through a mapping defined in an ILS view.
Requirements
To work with Rogue Wave JViews data sources, make sure the following software is correctly installed on your machine:
*Rogue Wave Server
*Rogue Wave JViews 8.10
*Java 2 Platform, Standard or Enterprise Edition 1.2
Example
The following example shows how you can work with SDM data sources. It consists in:
*Definining a dynamic business model
*Initializing the business model
*Defining the synchronization
1. Define a dynamic business model to manage nodes and links in a network, in order to display this network with an SDM engine.
That business model can be illustrated as follows:
Representing a Business Model with Nodes and Links
2. Initialize the business model with some JavaScriptTM code.
The following code sample defines a graph with subgraphs contained by a node through the parent relation:
function createNode(parent, label, x, y) {
var node = new Node();
node.parent = parent;
node.label = label;
node.x = x;
node.y = y;
return node;
}
function createLink(parent, from, to) {
var link = new Link();
link.parent = parent;
link.from = from;
link.to = to;
return link;
}
//-------------------------------------------------------------------------
// called when the Dynamic Server starts
//-------------------------------------------------------------------------
function OnLoad(args) {
writeln("Dynamic Server " + MvServer.serverName +
" Scripting is enabled");
var nodes = new Array();
var network = new Network("My Network");
MvServer.DeclObjectLabel(network, network.identifier);
// main graph
network.nodes.add(nodes[1] = createNode(null, "Start", 291.125, 56.375));
network.nodes.add(nodes[2] = createNode(null, "Simple node 1",
195.33594, 87.375));
network.nodes.add(nodes[3] = createNode(null, "Simple node 2",
436.33594,588.375));
network.nodes.add(nodes[4] = createNode(null, "Another node", 30.335938,
365.375));
network.nodes.add(nodes[5] = createNode(null, "Compound node 1:
click to expand sub-graph", 195.71094,344.875));
network.nodes.add(nodes[6] = createNode(null, "Compound node 3:
click to expand sub-graph", 436.59766,327.875));
network.nodes.add(nodes[7] = createNode(null, "Simple node", 195.33594,
595.375));
network.nodes.add(nodes[8] = createNode(null, "End", 331.33594, 660.375));
network.links.add(createLink(null, nodes[1], nodes[2]));
network.links.add(createLink(null, nodes[2], nodes[5]));
network.links.add(createLink(null, nodes[2], nodes[4]));
network.links.add(createLink(null, nodes[5], nodes[7]));
network.links.add(createLink(null, nodes[4], nodes[7]));
network.links.add(createLink(null, nodes[7], nodes[8]));
network.links.add(createLink(null, nodes[1], nodes[6]));
network.links.add(createLink(null, nodes[3], nodes[8]));
network.links.add(createLink(null, nodes[6], nodes[3]));
// sub node 6
network.nodes.add(nodes[9] = createNode(nodes[6], "Start of another
subgraph", 492.76562, 243.375));
network.nodes.add(nodes[10] = createNode(nodes[6], "End of other
subgraph", 493.97656, 447.375));
network.nodes.add(nodes[11] = createNode(nodes[6], "Sub-node", 454.97656,
308.375));
network.nodes.add(nodes[12] = createNode(nodes[6], "Sub-node 3",
454.97656, 376.375));
network.nodes.add(nodes[13] = createNode(nodes[6], "Sub-node 2",
520.97656, 340.375));
network.links.add(createLink(nodes[6], nodes[9], nodes[11]));
network.links.add(createLink(nodes[6], nodes[9], nodes[13]));
network.links.add(createLink(nodes[6], nodes[11], nodes[12]));
network.links.add(createLink(nodes[6], nodes[13], nodes[10]));
network.links.add(createLink(nodes[6], nodes[12], nodes[10]));
// sub node 5
network.nodes.add(nodes[14] = createNode(nodes[5], "Start of subgraph",
115.70703, 254.375));
network.nodes.add(nodes[15] = createNode(nodes[5], "Sub-node", 223.70703,
162.375));
network.nodes.add(nodes[17] = createNode(nodes[5], "Sub-node", 96.70703,
338.375));
network.nodes.add(nodes[18] = createNode(nodes[5], "Compound node 2:
click to expand sub-graph", 274.29297,344.375));
network.nodes.add(nodes[19] = createNode(nodes[5], "Sub-node",
119.70703, 433.375));
network.nodes.add(nodes[20] = createNode(nodes[5], "End of subgraph",
193.70703, 527.375));
network.links.add(createLink(nodes[5], nodes[14], nodes[17]));
network.links.add(createLink(nodes[5], nodes[14], nodes[15]));
network.links.add(createLink(nodes[5], nodes[17], nodes[19]));
network.links.add(createLink(nodes[5], nodes[19], nodes[20]));
network.links.add(createLink(nodes[5], nodes[15], nodes[18]));
network.links.add(createLink(nodes[5], nodes[18], nodes[20]));
// sub node 18
network.nodes.add(nodes[21] = createNode(nodes[18], "Start of
sub-subgraph", 270.70703, 236.375));
network.nodes.add(nodes[22] = createNode(nodes[18], "Yet another node",
318.70703, 375.375));
network.nodes.add(nodes[24] = createNode(nodes[18], "Sub-sub-node",
221.70703, 323.375));
network.nodes.add(nodes[25] = createNode(nodes[18], "Sub-sub-node",
318.70703, 316.375));
network.nodes.add(nodes[26] = createNode(nodes[18], "End of
sub-subgraph", 273.70703, 452.375));
network.links.add(createLink(nodes[18], nodes[21], nodes[24]));
network.links.add(createLink(nodes[18], nodes[21], nodes[25]));
network.links.add(createLink(nodes[18], nodes[25], nodes[22]));
network.links.add(createLink(nodes[18], nodes[22], nodes[26]));
network.links.add(createLink(nodes[18], nodes[24], nodes[26]));
}
3. Define the synchronization between the business model on the server and the SDM model in an .ils view specification.
view SDMView (any containerIndex= 0, string containerClass= ""):
represent IlsDSRepresentation repres:
any containerIndex = view.containerIndex;
string containerClass = view.containerClass;
string title = "a sdm view";
subscribe origin Network:
represent IlsRpSDMModel sdm:
string identifier = identifier;
string styleSheets = "data/expandWithLayout.css";
string background = "white";
string interactor = "ilog.views.interactor.IlvSelectInteractor";
# nodes and links
propagate nodes;
propagate links;
subscribe Node:
# parent
propagate parent;
represent IlsRpSDMNode node:
mandatory ref<IlsRpSDMModel> SDM = view.origin->sdm;
mandatory string tag = "node";
ref<IlsRpSDMNode> parent = parent->node;
# additional properties
string label = label;
double x = x;
double y = y;
subscribe Link:
# parent, from and to
propagate parent;
propagate from;
propagate to;
represent IlsRpSDMLink link:
mandatory ref<IlsRpSDMModel> SDM = view.origin->sdm;
mandatory string tag = "link";
ref<IlsRpSDMNode> from = from->node;
ref<IlsRpSDMNode> to = to->node;
Here are a few comments on this view specification:
*Thetag attribute defines the SDM logical type of the node.
*The parent attribute of the node and the from and to attributes of the links may be null. The attributes x and y are the coordinates used to display the node in the graphic view.
*The label attribute is used to display text related to the node.
Your server is ready to run. You are now going to create a Java client.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ilog.server.jcomp.*;
import ilog.server.jsds.*;
import ilog.server.jsds.swing.*;
import java.awt.*;
public class MySDMFrame extends JFrame {
IlsDSIlvSDMView sdmview = new IlsDSIlvSDMView();
public MySDMFrame() {
getContentPane().add(sdmview);
sdmview.setServerName("sdmserver");
sdmview.setObjectId("My Network");
sdmview.setViewId("SDMView");
sdmview.setLabel("sdm");
sdmview.connect();
}
public static void main(String[] args) {
IlsDSComponent.Initialize(args);
MySDMFrame myFrame = new MySDMFrame();
myFrame.setSize(512, 256);
myFrame.setVisible(true);
}
}
This Java client uses a high-level object (IlsDSIlvSDMView) which contains:
*a data source container,
*an instance IlsSDMDataSource,
*an instance of IlvSDMView,
*and an adapter. (IlsSDMDS2IlvSDMViewAdapter) to interface the data source with the SDM data model embedded in the IlvSDMView.
This high-level object manages the connection to the server and can be used to replace the adapter or the graphic component in managing the correct relations between the different
To take advantage of the SDM style sheet, you can use the two following style sheets which are pointed in the .ils view specification with the styleSheets attribute.
/******************************************************************/
/* expand.css */
/* SDM engine configuration part */
/******************************************************************/
SDM {
XMLFile : "file:expand.xml";
LinkLayout : true;
ExpandCollapse : true;
}
///////////////////////////////////////////////////////////
 
node:selected {
fillColor2 : red;
}
node:expanded:selected {
foreground : red;
}
link:selected {
foreground : red;
lineWidth : 4;
mode : "MODE_NEON";
}
node {
class : "ilog.views.sdm.graphic.IlvGeneralNode" ;
shapeType : RoundRectangle;
shapeWidth : 40;
shapeAspectRatio : 1;
strokeWidth : 2;
horizontalAutoResizeMode : "EXPAND_OR_SHRINK";
verticalAutoResizeMode : "EXPAND_OR_SHRINK";
label : "@label";
labelPosition : Center;
labelSpacing : 10;
wordWrapMode : true;
workWrapMargin : "-20";
fillStyle : "RADIAL_GRADIENT";
fillColor1 : "white";
fillColor2 : "brown";
fillStart : "0.25";
fillEnd : "0.75";
fillAngle : "45";
foreground : "#666666";
InitiallyExpanded : false;
}
node:expanded {
ToolTipText : "Click to collapse/expand";
foreground : '#F5DEB3' ;
}
node:collapsed {
ToolTipText : "Click to collapse/expand";
icon : url(images/subgraph.gif);
iconPosition : Top;
}
link {
class : "ilog.views.sdm.graphic.IlvGeneralLink"
mode : "MODE_GRADIENT";
foreground : orange;
lineWidth : 3;
oriented : true;
}
/******************************************************************/
/* expandWithLayout.css */
/* SDM engine configuration part */
/******************************************************************/
@import "expand.css";
SDM {
GraphLayout : true;
}
GraphLayout {
graphLayout : "@#Hierarchical";
}
#Hierarchical {
class : "ilog.views.graphlayout.hierarchical.IlvHierarchicalLayout";
FlowDirection : "Bottom";
GlobalLinkStyle : "Orthogonal links";
}

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.