Search in sources :

Example 1 with IContextFunction

use of org.eclipse.e4.core.contexts.IContextFunction in project eclipse.platform.runtime by eclipse.

the class EclipseContext method internalGet.

public Object internalGet(EclipseContext originatingContext, String name, boolean local) {
    if (this == originatingContext) {
        ValueComputation valueComputation = localValueComputations.get(name);
        if (valueComputation != null) {
            Object result = valueComputation.get();
            if (result != IInjector.NOT_A_VALUE) {
                return result;
            }
        }
    }
    Object result = null;
    // 1. try for local value
    if (localValues.containsKey(name)) {
        result = localValues.get(name);
        if (result == null)
            return null;
    } else
        result = lookup(name, originatingContext);
    // if we found something, compute the concrete value and return
    if (result != null) {
        if (result instanceof IContextFunction) {
            ValueComputation valueComputation = new ValueComputation(name, originatingContext, ((IContextFunction) result));
            // do calculations before adding listeners
            result = valueComputation.get();
            originatingContext.localValueComputations.put(name, valueComputation);
        }
        if (result != IInjector.NOT_A_VALUE) {
            return result;
        }
    }
    // 3. delegate to parent
    if (!local) {
        IEclipseContext parent = (IEclipseContext) localValues.get(PARENT);
        if (parent != null) {
            return ((EclipseContext) parent).internalGet(originatingContext, name, local);
        }
    }
    return null;
}
Also used : IContextFunction(org.eclipse.e4.core.contexts.IContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Aggregations

IContextFunction (org.eclipse.e4.core.contexts.IContextFunction)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1