The selection servlet can be configured to provide additional
information for each selected object. This information corresponds
to additional properties that can be used on the client.
To do so, you need to subclass the selection support
implementation to override getAdditionalProperties(IlvSelectionResponse
response, Object object)
, as in the following example.
The following selection support adds the properties of
an SDM node:
//Subclass to override the getAdditionalProperties method
public class DiagrammerSelectionSupport extends IlvDiagrammerSelectionSupport {
public DiagrammerSelectionSupport(IlvDiagrammerServletSupport support) {
super(support);
}
protected ArrayList getAdditionalProperties(IlvSelectionResponse response,
Object object) {
ArrayList props = super.getAdditionalProperties(response, object);
IlvSDMNode node = (IlvSDMNode) object;
IlvDiagrammer diagrammer = (IlvDiagrammer)
response.getProperty(DIAGRAMMER_KEY);
IlvSDMModel model = diagrammer.getEngine().getModel();
String names[] = model.getObjectPropertyNames(node);
for (int i = 0; i < names.length; i++) {
ArrayList l = new ArrayList();
l.add(names[i]);
l.add(model.getObjectProperty(node, names[i]));
props.add(l);
}
return props;
}
}
//Use the new selection selection support class in the servlet support.
public class DiagrammerServletSupport extends IlvDiagrammerServletSupport {
[...]
protected IlvSelectionSupport createSelectionSupport() {
return new DiagrammerSelectionSupport(this);
}
}
In image mode, you need to issue an additional request
to get the selection information (the information is disabled by default).
To force this additional request on each selection, use view.getSelectionManager().setForceUpdateProperties(true)
.
In rectangle mode, the selection information is always
enabled.
There are two ways to retrieve the selection information
on the client side:
Get the current selection at any time.
view.getSelectionManager().getSelection()
Register a listener for selection changes.
The listener is notified of the current selection.
The additional properties are available in the properties
of
a selection rectangle.
If the selection support example illustrated earlier
in this section is used, the following listener example fills a panel
with properties of the selected object:
function showProperties(rList) {
if (rList.length == 1) {
var p = "<table>";
for(var i=0; i<rList[0].getProperties(length); i++){
var props = rList[0].getProperties();
p += "<td>" + props[i][0]+ "</td>";
p += "<td>" + props[i][1]+ "</td>";
}
p +="<table>";
propPanel.setContent(p);
}
}