SDS
SDS

Reputation: 828

Is there a better way to get to Workbench context in an E4 application

I'm working with an E4 application and am currently in a Part. I want to push a flag at the Workbench level context and the only way that I could get to it is

context.getParent().getParent().getParent().set("FLAG", false);

Is there a better way to get to the Workbench level?

Upvotes: 1

Views: 887

Answers (2)

Cichy
Cichy

Reputation: 21

@Inject
IEclipseContext eclipseContext;

Of course You must be in E4ApplicationModel. If not, You can inject this (in Processor/LifeCycleManager/other in E4ApplicationModel...):

MyClass myClass = new MyClass();
ContextInjectionFactory.inject(myClass,eclipseContext);

Upvotes: 0

greg-449
greg-449

Reputation: 111217

The workbench context is accessible from the application object:

@Inject
MApplication application;

...

IEclipseContext appContext = application.getContext();

Using getParent() calls is very error prone as any change to the application model may break the code.

Upvotes: 1

Related Questions