Search in sources :

Example 1 with IPropertyValueProxy

use of org.eclipse.elk.graph.properties.IPropertyValueProxy in project elk by eclipse.

the class EMapPropertyHolderImpl method copyProperties.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public IPropertyHolder copyProperties(IPropertyHolder source) {
    if (source == null) {
        return this;
    }
    if (source instanceof EMapPropertyHolder) {
        EMapPropertyHolder other = (EMapPropertyHolder) source;
        EMap<IProperty<?>, Object> ourProps = this.getProperties();
        for (Map.Entry<IProperty<?>, Object> entry : other.getProperties()) {
            Object value = entry.getValue();
            if (value instanceof IPropertyValueProxy) {
                IPropertyValueProxy proxy = (IPropertyValueProxy) value;
                Object newValue = proxy.resolveValue(entry.getKey());
                if (newValue != null) {
                    entry.setValue(newValue);
                    value = newValue;
                }
            }
            ourProps.put(entry.getKey(), value);
        }
    } else {
        this.getProperties().putAll(source.getAllProperties());
    }
    return this;
}
Also used : IPropertyValueProxy(org.eclipse.elk.graph.properties.IPropertyValueProxy) IProperty(org.eclipse.elk.graph.properties.IProperty) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EMapPropertyHolder(org.eclipse.elk.graph.EMapPropertyHolder) EMap(org.eclipse.emf.common.util.EMap) Map(java.util.Map) EcoreEMap(org.eclipse.emf.ecore.util.EcoreEMap)

Example 2 with IPropertyValueProxy

use of org.eclipse.elk.graph.properties.IPropertyValueProxy in project elk by eclipse.

the class EMapPropertyHolderImpl method getProperty.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@SuppressWarnings("unchecked")
public <T> T getProperty(IProperty<T> property) {
    Object value = getProperties().get(property);
    if (value instanceof IPropertyValueProxy) {
        value = ((IPropertyValueProxy) value).resolveValue(property);
        if (value != null) {
            getProperties().put(property, value);
            return (T) value;
        }
    } else if (value != null) {
        return (T) value;
    }
    // the reason for the side effect below is that if a default value has been returned
    // and the object is altered by the user, the user expects the altered object to be
    // the value of the property in case he asks for the property again
    T defaultValue = property.getDefault();
    if (defaultValue instanceof Cloneable) {
        // We are now dealing with a clone of the default value which me may safely store away
        // for further modification
        setProperty(property, defaultValue);
    }
    return defaultValue;
}
Also used : IPropertyValueProxy(org.eclipse.elk.graph.properties.IPropertyValueProxy) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 3 with IPropertyValueProxy

use of org.eclipse.elk.graph.properties.IPropertyValueProxy in project elk by eclipse.

the class EMapPropertyHolderImpl method getAllProperties.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public Map<IProperty<?>, Object> getAllProperties() {
    EMap<IProperty<?>, Object> props = getProperties();
    // check for unresolved properties
    for (Map.Entry<IProperty<?>, Object> entry : props) {
        if (entry.getValue() instanceof IPropertyValueProxy && entry.getKey() != null) {
            IPropertyValueProxy proxy = (IPropertyValueProxy) entry.getValue();
            // Try to resolve the proxy's value, maybe the layout option was
            // registered by now. If not, we preserve the proxy.
            Object value = proxy.resolveValue(entry.getKey());
            if (value != null) {
                entry.setValue(value);
            }
        }
    }
    return props.map();
}
Also used : IPropertyValueProxy(org.eclipse.elk.graph.properties.IPropertyValueProxy) IProperty(org.eclipse.elk.graph.properties.IProperty) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EMap(org.eclipse.emf.common.util.EMap) Map(java.util.Map) EcoreEMap(org.eclipse.emf.ecore.util.EcoreEMap)

Aggregations

IPropertyValueProxy (org.eclipse.elk.graph.properties.IPropertyValueProxy)3 InternalEObject (org.eclipse.emf.ecore.InternalEObject)3 Map (java.util.Map)2 IProperty (org.eclipse.elk.graph.properties.IProperty)2 EMap (org.eclipse.emf.common.util.EMap)2 EcoreEMap (org.eclipse.emf.ecore.util.EcoreEMap)2 EMapPropertyHolder (org.eclipse.elk.graph.EMapPropertyHolder)1