Dynamic View Services > Specifying Dynamic View Types > References > Editing a Reference
 
Editing a Reference
Direct editing of a reference attribute by the component is subject to similar constraints as that of any other representation attribute:
*The reference attribute must be directly mapped to a runtime server (unary) relation path.
*The last relation of the path must declare a modifier or, if it is an inverted relation, its direct relation must declare a modifier.
The code sample below shows the reference attributes in a specification that defines a cell representation:
subscribe Contribution:
represent CellR cell:
mandatory Ref<RowR> row=employee->row;
Ref<ColumnR> column=project->column;
...
The two reference attributes row and column are editable because:
1. They are directly mapped to a runtime server relation path.
2. Their associated relations can be edited directly (employee) or by editing the corresponding direct relation (relation contributions corresponding to project).
Editing a reference means modifying the target of the corresponding relation path.
*To make the target null, use the following callback function:
IlsRpObject::onNullifyRef(IlsRpAttributeId);
*To replace the target, use the following function:
IlsRpObject::onUpdate(IlsRpAttributeId,IlsRpObject& objRef);
Editing the Row Reference Attribute
Suppose the matrix gadget allows to drag and drop a cell vertically to a new matrix row. Let us also assume that this operation executes the CellR callback onVMove with the new row as a parameter. Then, the body of this callback is the following:
CellR::onVMove(RowR& newRow){
onUpdate(getAttributeId("row"),newRow);
}
On the server side, the target of the employees relation is replaced by the Employee object, which is represented by newRow.
Note: The representation object you pass as an argument to the onUpdate function must be associated with a server object that is an instance of the target type —or of a subtype— of the server relation. The function IlsRpObject::isMatchingRef checks whether a given representation object can be used to update a reference.
Editing the Column Attribute
Symmetrically, suppose the matrix gadget allows to drag and drop a cell horizontally to a new matrix column. Let us also assume that this operation executes the CellR callback onHMove with the new column as a parameter. Then, the body of this callback is:
CellR::onHMove(ColumnR& newColumn){
onUpdate(getAttributeId("column"),newColumn);
}
For this callback to be executed on the server side, the target of the relation project must be replaced by the project associated to newColumn. Because project is an inverted relation, it cannot be edited directly. Instead, the contribution is cut from its current project and added to the relation contributions of the new “target” project.
Editing an Inverse Relation
As a rule, the semantics of editing an inverse relation through a representation depends on the arity of the two relations involved.
Let us assume the direct relation r is owned by an object x and has y as its target. i is its inverted relation (the inserter and extractor operators are noted respectively as << and >>):
1. r and i are both unary relations:
y.i=z =>
if (r is an ownership relation) y.cut
z.r=y
y.i=0 => x.r=0
2. r is an n-ary relation and i is a unary relation:
y.i=z =>
if (r is an ownership relation) y.cut
z.r << y
y.i=0 => x.r >> y
3. r is a unary relation and i is an n-ary relation:
y.i << z =>
if (r is an ownership relation) y.cut
z.r=y
y.i >> x => x.r =0
4. r and i are both n-ary relations:
y.i << z =>
if (r is an ownership relation) y.cut
z.r << y
y.i >> x => x.r >> y

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