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 ...@@ -190,7 +190,6 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
private void configureContext() { private void configureContext() {
final IEclipseContext e4Context = ((Workbench) PlatformUI.getWorkbench()).getContext(); final IEclipseContext e4Context = ((Workbench) PlatformUI.getWorkbench()).getContext();
getShell().setData("org.eclipse.e4.ui.dialogShellContext", e4Context.getActiveLeaf());
while (!Objects.equals(e4Context.getActiveLeaf(), e4Context)) { while (!Objects.equals(e4Context.getActiveLeaf(), e4Context)) {
e4Context.getActiveLeaf().deactivate(); e4Context.getActiveLeaf().deactivate();
} }
......
...@@ -107,6 +107,8 @@ public class GroovyViewer implements IDocumentListener { ...@@ -107,6 +107,8 @@ public class GroovyViewer implements IDocumentListener {
private UnknownElementsIndexer unknownElementsIndexer; private UnknownElementsIndexer unknownElementsIndexer;
private IEclipseContext groovyEditorContext;
public GroovyViewer(final Composite mainComposite) { public GroovyViewer(final Composite mainComposite) {
this(mainComposite, null, null); this(mainComposite, null, null);
} }
...@@ -139,16 +141,9 @@ public class GroovyViewer implements IDocumentListener { ...@@ -139,16 +141,9 @@ public class GroovyViewer implements IDocumentListener {
} }
try { try {
editor.getDocumentProvider().connect(input); editor.getDocumentProvider().connect(input);
final IEclipseContext context = ((Workbench) PlatformUI.getWorkbench()).getContext(); groovyEditorContext = createGroovyEditorContext();
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")));
final DummyEditorSite site = new DummyEditorSite(mainComposite.getShell(), editor); 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.init(site, this.input);
editor.doSave(Repository.NULL_PROGRESS_MONITOR); editor.doSave(Repository.NULL_PROGRESS_MONITOR);
editor.createPartControl(mainComposite); editor.createPartControl(mainComposite);
...@@ -182,19 +177,12 @@ public class GroovyViewer implements IDocumentListener { ...@@ -182,19 +177,12 @@ public class GroovyViewer implements IDocumentListener {
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell() groovyEditorContext.deactivate();
.getData("org.eclipse.e4.ui.dialogShellContext");
if (context != null) {
context.deactivate();
}
} }
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell().getData("org.eclipse.e4.ui.shellContext"); groovyEditorContext.activate();
if (context != null) {
context.activate();
}
} }
}); });
mainComposite.getShell().addDisposeListener(new DisposeListener() { mainComposite.getShell().addDisposeListener(new DisposeListener() {
...@@ -206,6 +194,19 @@ public class GroovyViewer implements IDocumentListener { ...@@ -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() { public IDocument getDocument() {
return editor.getDocumentProvider().getDocument(input); 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