use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class TranslationObjectSupplier method notifyRequestor.
/**
* Notify all given {@link IRequestor} about changes for their injected values. This way the
* dynamic injection is performed.
*
* @param requestors
* The {@link IRequestor} to inform about the instance changes.
*/
private void notifyRequestor(Collection<IRequestor> requestors) {
if (requestors != null) {
for (Iterator<IRequestor> it = requestors.iterator(); it.hasNext(); ) {
IRequestor requestor = it.next();
if (!requestor.isValid()) {
it.remove();
continue;
}
requestor.resolveArguments(false);
requestor.execute();
}
}
}
use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class PreferencesObjectSupplier method addListener.
private void addListener(String nodePath, String key, final IRequestor requestor) {
if (requestor == null)
return;
synchronized (listenerCache) {
if (listenerCache.containsKey(nodePath)) {
HashMap<String, List<PrefInjectionListener>> map = listenerCache.get(nodePath);
if (map.containsKey(key)) {
for (PrefInjectionListener listener : map.get(key)) {
IRequestor previousRequestor = listener.getRequestor();
if (previousRequestor.equals(requestor))
// avoid adding duplicate listeners
return;
}
}
}
}
final IEclipsePreferences node = InstanceScope.INSTANCE.getNode(nodePath);
PrefInjectionListener listener = new PrefInjectionListener(node, key, requestor);
node.addPreferenceChangeListener(listener);
synchronized (listenerCache) {
HashMap<String, List<PrefInjectionListener>> map = listenerCache.get(nodePath);
if (map == null) {
map = new HashMap<>();
listenerCache.put(nodePath, map);
}
List<PrefInjectionListener> listeningRequestors = map.get(key);
if (listeningRequestors == null) {
listeningRequestors = new ArrayList<>();
map.put(key, listeningRequestors);
}
listeningRequestors.add(listener);
}
}
use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class ContextObjectSupplier method get.
@Override
public void get(IObjectDescriptor[] descriptors, Object[] actualArgs, final IRequestor requestor, boolean initial, boolean track, boolean group) {
final String[] keys = new String[descriptors.length];
final boolean[] active = new boolean[descriptors.length];
for (int i = 0; i < descriptors.length; i++) {
String key = getKey(descriptors[i]);
if ((actualArgs[i] == IInjector.NOT_A_VALUE))
keys[i] = key;
else if (// allow provider to override IEclipseContext
ECLIPSE_CONTEXT_NAME.equals(key))
keys[i] = ECLIPSE_CONTEXT_NAME;
else
keys[i] = null;
if (descriptors[i] == null)
active[i] = false;
else
active[i] = (descriptors[i].hasQualifier(Active.class));
}
if (requestor != null && track) {
// only track if requested
if (initial) {
RunAndTrack trackable = new ContextInjectionListener(context, actualArgs, keys, active, requestor, group);
context.runAndTrack(trackable);
} else {
// we do track if this is done inside a computation, but don't create another runnable
fillArgs(actualArgs, keys, active);
}
} else {
if (descriptors.length > 0) {
pauseRecording();
try {
fillArgs(actualArgs, keys, active);
} finally {
resumeRecording();
}
}
}
}
use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class OSGiObjectSupplier method get.
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
final Class<?> requestingObjectClass = requestor.getRequestingObjectClass();
final Type desiredType = descriptor.getDesiredType();
if (BundleContext.class.equals(desiredType)) {
final Bundle bundle = FrameworkUtil.getBundle(requestingObjectClass);
// Iff track is request and there is no listener yet, lets track the bundle
if (track) {
if (!requestor2listener.containsKey(requestor)) {
track(bundle, requestor);
}
// Handlers only executed once and thus don't track the BC/Bundle.
// Still guard to now de-register a non-existing listener.
} else if (requestor2listener.containsKey(requestor)) {
untrack(requestor);
}
final BundleContext bundleContext = bundle.getBundleContext();
if (bundleContext != null) {
return bundleContext;
} else if (descriptor.getQualifier(Optional.class) != null) {
// Do not have a bundle context but requestor has marked the parameter/field optional
return null;
}
// $NON-NLS-1$ //$NON-NLS-2$
throw new InjectionException("Unable to inject BundleContext: " + bundle.getSymbolicName() + " bundle is not active or starting/stopping");
} else if (Bundle.class.equals(desiredType)) {
// state. However, the requestor will go away along with its bundle anyway.
return FrameworkUtil.getBundle(requestingObjectClass);
}
// Annotation used with unsupported type
return null;
}
use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class ServiceSupplier method get.
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
Type desiredType = descriptor.getDesiredType();
Bundle b = FrameworkUtil.getBundle(requestor.getRequestingObjectClass());
Service qualifier = descriptor.getQualifier(Service.class);
if (desiredType instanceof ParameterizedType) {
ParameterizedType t = (ParameterizedType) desiredType;
if (t.getRawType() == Collections.class || t.getRawType() == List.class) {
return handleCollection(b, t.getActualTypeArguments()[0], requestor, track && qualifier.dynamic(), qualifier);
}
}
return handleSingle(b, desiredType, requestor, descriptor, track && qualifier.dynamic(), qualifier);
}
Aggregations