Commit 845af8ba authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(expressionEditor) switch e4 context in expression editor dialog (#282)

* Use WorkbenchContext in GroovyEditor
* Use Dialog context otherwise

fixes [BS-15972](https://bonitasoft.atlassian.net/browse/BS-15972)
parent 00b30c73
......@@ -190,7 +190,6 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
private void configureContext() {
final IEclipseContext e4Context = ((Workbench) PlatformUI.getWorkbench()).getContext();
getShell().setData("org.eclipse.e4.ui.dialogShellContext", e4Context.getActiveLeaf());
while (!Objects.equals(e4Context.getActiveLeaf(), e4Context)) {
e4Context.getActiveLeaf().deactivate();
}
......
......@@ -107,6 +107,8 @@ public class GroovyViewer implements IDocumentListener {
private UnknownElementsIndexer unknownElementsIndexer;
private IEclipseContext groovyEditorContext;
public GroovyViewer(final Composite mainComposite) {
this(mainComposite, null, null);
}
......@@ -139,16 +141,9 @@ public class GroovyViewer implements IDocumentListener {
}
try {
editor.getDocumentProvider().connect(input);
final IEclipseContext context = ((Workbench) PlatformUI.getWorkbench()).getContext();
final IEclipseContext activeLeaf = context.getActiveLeaf();
activeLeaf
.set("localContexts",
Lists.newLinkedList(Lists.newArrayList("org.eclipse.ui.contexts.window",
"org.eclipse.ui.contexts.dialogAndWindow",
"org.eclipse.ui.textEditorScope", "org.eclipse.jdt.ui.javaEditorScope",
"org.codehaus.groovy.eclipse.editor.groovyEditorScope")));
groovyEditorContext = createGroovyEditorContext();
final DummyEditorSite site = new DummyEditorSite(mainComposite.getShell(), editor);
activeLeaf.set(ISources.ACTIVE_SITE_NAME, site);
groovyEditorContext.set(ISources.ACTIVE_SITE_NAME, site);
editor.init(site, this.input);
editor.doSave(Repository.NULL_PROGRESS_MONITOR);
editor.createPartControl(mainComposite);
......@@ -182,19 +177,12 @@ public class GroovyViewer implements IDocumentListener {
@Override
public void focusLost(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell()
.getData("org.eclipse.e4.ui.dialogShellContext");
if (context != null) {
context.deactivate();
}
groovyEditorContext.deactivate();
}
@Override
public void focusGained(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell().getData("org.eclipse.e4.ui.shellContext");
if (context != null) {
context.activate();
}
groovyEditorContext.activate();
}
});
mainComposite.getShell().addDisposeListener(new DisposeListener() {
......@@ -206,6 +194,19 @@ public class GroovyViewer implements IDocumentListener {
});
}
private IEclipseContext createGroovyEditorContext() {
final IEclipseContext context = ((Workbench) PlatformUI.getWorkbench()).getContext();
final IEclipseContext activeLeaf = context.getActiveLeaf();
IEclipseContext groovyEditorContext = activeLeaf.createChild("groovyEditorContext");
groovyEditorContext
.set("localContexts",
Lists.newLinkedList(Lists.newArrayList("org.eclipse.ui.contexts.window",
"org.eclipse.ui.contexts.dialogAndWindow",
"org.eclipse.ui.textEditorScope", "org.eclipse.jdt.ui.javaEditorScope",
"org.codehaus.groovy.eclipse.editor.groovyEditorScope")));
return groovyEditorContext;
}
public IDocument getDocument() {
return editor.getDocumentProvider().getDocument(input);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment