
eu.mihosoft.vmf.vmtemplates.impl.setter-no-collection-cross-reference.vm Maven / Gradle / Ivy
#*
* Copyright 2017-2024 Michael Hoffer . All rights reserved.
* Copyright 2017-2019 Goethe Center for Scientific Computing, University Frankfurt. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* If you use this software for scientific research then please cite the following publication(s):
*
* M. Hoffer, C. Poliwoda, & G. Wittum. (2013). Visual reflection library:
* a framework for declarative GUI programming on the Java platform.
* Computing and Visualization in Science, 2013, 16(4),
* 181–192. http://doi.org/10.1007/s00791-014-0230-y
*#
#if(${prop.propType} != "COLLECTION" && !${prop.container} && !${prop.contained} && ${prop.crossRefProperty})
// this property holds a (cross-)reference which is indicated by the @Refers annotation (see model type ${type.typeName})
// ----------------------------------------
// - cross-ref:
// -> prop:
// -> name: ${prop.name}
// -> propType: ${prop.typeName}
// -> opposite: true, ${prop.referenceInfo.opposite.typeName}.${prop.referenceInfo.opposite.name}
// -> propType: ${prop.referenceInfo.opposite.typeName}
// -> collection: false
// ----------------------------------------
// ----------------------------------------
// return early if identical value has been set
// ----------------------------------------
if (this.__vmf_prop_${prop.name} == ${prop.name}) {
return;
}
// ----------------------------------------
#if(${prop.referenceInfo.opposite.propType} == "COLLECTION")## collection opposite
// ----------------------------------------
// store the old value ...
// ----------------------------------------
${prop.typeName} oldValue = this.__vmf_prop_${prop.name};
// ----------------------------------------
// ----------------------------------------
// remove this object as reference from old value
// ----------------------------------------
if(oldValue!=null) {
## String eventInfo = oldValue.get${prop.referenceInfo.opposite.nameWithUpperCase}().getEventInfo();
## oldValue.get${prop.referenceInfo.opposite.nameWithUpperCase}().setEventInfo(${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CROSS_REF);
oldValue.get${prop.referenceInfo.opposite.nameWithUpperCase}().remove(this);
## oldValue.get${prop.referenceInfo.opposite.nameWithUpperCase}().setEventInfo(eventInfo);
}
// ----------------------------------------
// ----------------------------------------
// set the new value + fire change event
// ----------------------------------------
this.__vmf_prop_$prop.name = $prop.name;
_vmf_firePropertyChangeIfListenersArePresent("$prop.name", oldValue, this.__vmf_prop_$prop.name);
// ----------------------------------------
// ----------------------------------------
// registering with the opposite collection
// ----------------------------------------
if(this.__vmf_prop_${prop.name}!=null) {
String eventInfo = this.__vmf_prop_${prop.name}.get${prop.referenceInfo.opposite.nameWithUpperCase}().getEventInfo();
this.__vmf_prop_${prop.name}.get${prop.referenceInfo.opposite.nameWithUpperCase}().setEventInfo(${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CROSS_REF);
this.__vmf_prop_${prop.name}.get${prop.referenceInfo.opposite.nameWithUpperCase}().add(this);
this.__vmf_prop_${prop.name}.get${prop.referenceInfo.opposite.nameWithUpperCase}().setEventInfo(eventInfo);
}
// ----------------------------------------
#else## collection opposite
// ----------------------------------------
// set the new value
// ----------------------------------------
$prop.typeName oldValue = this.__vmf_prop_$prop.name;
this.__vmf_prop_$prop.name = $prop.name;
// ----------------------------------------
// ----------------------------------------
// remove this object as reference from old value
// ----------------------------------------
if(oldValue!=null) {
oldValue.set${prop.referenceInfo.opposite.nameWithUpperCase}(null);
}
// ----------------------------------------
// ----------------------------------------
// fire property change event
// ----------------------------------------
_vmf_firePropertyChangeIfListenersArePresent("$prop.name", oldValue, this.__vmf_prop_$prop.name);
// ----------------------------------------
// register this with opposite if new value is not null
// ----------------------------------------
if(this.__vmf_prop_${prop.name}!=null) {
Object refOldVal = ((__VMF_TYPE_${prop.type.implementation.typeName})this.__vmf_prop_${prop.name}).__vmf_get_prop_${prop.referenceInfo.opposite.name}();
((__VMF_TYPE_${prop.type.implementation.typeName})this.__vmf_prop_${prop.name}).__vmf_set_prop_${prop.referenceInfo.opposite.name}(this);
// fire property change event
if(refOldVal != this) {
((__VMF_TYPE_${prop.type.implementation.typeName})this.__vmf_prop_${prop.name})._vmf_firePropertyChangeIfListenersArePresent("${prop.referenceInfo.opposite.name}", refOldVal, this, ${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CROSS_REF);
}
}
// ----------------------------------------
#end## collection opposite
#end##