eclipse-platform / eclipse-platform/eclipse.platform

Add public API to inject the local IEclipseContext

Open
#344 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
165
Forks
174
Avg merge
2d 8h
Merged PRs (30d)
22

Description

## Use Case

I want to write an Eclipse 4 command handler that wraps/decorates another command handler. To that effect, my handler has `@CanExecute` and `@Execute` methods which invoke the wrapped handler's respective `@CanExecute` and `@Execute` methods using `ContextInjectionFactory.invoke` like so:

```java
@Execute
public void execute(IEclipseContext context) {
// Decorator functionality goes here

IEclipseContext localContext = null; // How to obtain this?
ContextInjectionFactory.invoke(decoratee, Execute.class, context, localContext, null));
}
```

Unfortunately, this looses any "local context" the `ContextInjectionFactory`? invoking the above method might have had.

## Suggested Solution

Allow the local context to be injected as well, e.g., by using a `@Named` annotation:

```java
@Execute
public void execute(IEclipseContext context, @Named("local") IEclipseContext localContext) {
// Decorator functionality goes here

ContextInjectionFactory.invoke(decoratee, Execute.class, context, localContext, null));
}
```

## Workarounds

AFAICT, the only way to currently obtain this local context is using an internal API (`org.eclipse.e4.core.internal.contexts.ContextObjectSupplier`):

```java
@Execute
public void execute(IEclipseContext context, ContextObjectSupplier localContextSupplier) {
// Decorator functionality goes here

IEclipseContext localContext = localContextSupplier.getContext(); // internal API :-(
ContextInjectionFactory.invoke(decoratee, Execute.class, context, localContext, null));
}
```

But this is both internal API and also more awkward to use than getting the local context injected directly and not as a supplier.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.