You can register a listener that is called when the selection
changes:
<jvdf:selectionManager onSelectionChanged="displayProperties(selection)"/>
The
onSelectionChanged
attribute
value is
JavaScript™
code that
is executed when the selection has changed. The execution context
defines the variable
selection
, which stores
the current selection as an array of
IlvSelectionRectangle instances.
The JavaScript code can be
a function as follows:
// Alert the ID and bounds of all the selected objects
function displayProperties(selection) {
for (var i = 0; i < selection.length; i++)
alert(selection[i].getID()+" "+selection[i].getBounds());
}
Besides ID and bounds properties of the selected object,
you might want to get also the properties of the selected node or
link in the JViews Diagrammer model.
This can be done by configuring a property accessor on
the selection manager:
<jvdf:selectionManager propertyAccessor="#{serverBean.propertyAccessor}" [...] />
With:
public class ServerBean {
private IlvFacesDiagrammerPropertyAccessor accessor =
new IlvFacesDiagrammerPropertyAccessor();
public IlvFacesDiagrammerPropertyAccessor getPropertyAccessor() {
return accessor;
}
}
The
IlvFacesDiagrammerPropertyAccessor contains several methods that can be either called
or redefined to configure or specialize the way it gives access to
model properties.
Once done, in the JavaScript you can access all the methods
of the IlvSelectionRectangle
and code as
follows:
// Alert all the properties of all the selected objects
function displayProperties(selection) {
for (var i = 0; i < selection.length; i++) {
var propertiesNames = selection[i].getObjectPropertyNames();
for (var j = 0; j < propertiesNames.length; j++)
alert(selection[i].getObjectProperty(propertiesNames[j]));
}
}
In addition, if the diagrammerView
has
been set as editable:
<jvdf:diagrammerView editable="true" [...] />
you can also set properties on the client such that they
can be committed back to the model on the server. You can do this
by using the following code:
// Modify a property on the first selected object
thediagrammer.getSelectionManager().getSelection()[0].
setObjectProperty("propertyName","propertyValue");
// [other modifications]
thediagrammer.getSelectionManager().
commitSelectionProperties(true, oncompleted, onfailed);
where:
To obtain selected object properties information on the
client side while you are running the selection in image mode, you
need to force an additional request by setting the property forceUpdateProperties
to true
.
In regular mode this feature is available without any overhead.