All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.mihosoft.vmf.vmtemplates.impl.getter-collection-contained.vm Maven / Gradle / Ivy

Go to download

VMF (VRL Modeling Framework) is a lightweight modeling framework for generating Java code from data models.

The newest version!
#*
 * 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.contained && !$prop.crossRefProperty)##      COLLECTION PROP
    // this property holds a collection of objects that are contained in this instance (${type.typeName})

    // perform lazy initialization
    if(this.__vmf_prop_$prop.name==null) {
        this.__vmf_prop_$prop.name = ${VCOLL_PKG}.VList.newInstance(__vmf_get_prop_${prop.name}__vmf_RawList());

        this.__vmf_prop_${prop.name}.addChangeListener( (evt) -> {
            evt.added().elements().forEach( (e) -> {

                if(e==null || ${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CONTAINMENT.equals(evt.eventInfo())) return;

                // unregister from previous container
                ${VMFPKG_INT}.VObjectInternalModifiable valueInternal = (${VMFPKG_INT}.VObjectInternalModifiable)e;
                //if(valueInternal._vmf_getContainer()!=this) {
                    valueInternal._vmf_unregisterFromContainers();
                //}

                // register with this container
                ${VMFPKG}.VObject oldContainer = valueInternal._vmf_getContainer(); 
                valueInternal._vmf_setContainer(this);
#if(${prop.containmentInfo.opposite})## opposite
                valueInternal._vmf_setContainerPropertyId(valueInternal._vmf_getPropertyIdByName("${prop.containmentInfo.opposite.name}"));
                ((__VMF_TYPE_${prop.genericTypeName}Impl)valueInternal)._vmf_firePropertyChangeIfListenersArePresent("${prop.containmentInfo.opposite.name}", oldContainer, this, ${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CONTAINMENT);
#else##                                      ## opposite
                ((__VMF_TYPE_${prop.genericTypeName}Impl)valueInternal)._vmf_firePropertyChangeIfListenersArePresent("__vmf_prop_unnamed_container", oldContainer, this, ${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CONTAINMENT);
#end##                                       ## opposite                
                
            }); // end of evt.added()     

            evt.removed().elements().forEach( (e) -> {

                if(e==null || ${VMFPKG_INT}.ChangeInternal.CHANGE_TYPE_CONTAINMENT.equals(evt.eventInfo())) return;

                // unregister from previous container
                ${VMFPKG_INT}.VObjectInternalModifiable valueInternal = (${VMFPKG_INT}.VObjectInternalModifiable)e;

                // finally, set the container to 'null' and fire the corresponding event
                valueInternal._vmf_unregisterFromContainers();      
                
            }); // end of evt.added()     
        }); // end of addChangeListener
             

    } // end of "lazy init" if(this.__vmf_prop_$prop.name==null)

    // return the collection
    return this.__vmf_prop_$prop.name;
#end##                                                                                   COLLECTION PROP




© 2015 - 2025 Weber Informatics LLC | Privacy Policy