Commit 00b30c73 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

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

* Use WorkbenchContext in GroovyEditor
* Use Dialog context otherwise

fixes [BS-15972](https://bonitasoft.atlassian.net/browse/BS-15972)
parent a60fa9c9
......@@ -180,7 +180,8 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
expressionType = ExpressionConstants.SCRIPT_TYPE;
}
}
final IExpressionProvider currentProvider = ExpressionEditorService.getInstance().getExpressionProvider(expressionType);
final IExpressionProvider currentProvider = ExpressionEditorService.getInstance()
.getExpressionProvider(expressionType);
if (currentProvider != null && expressionTypeViewer != null) {
expressionTypeViewer.setSelection(new StructuredSelection(currentProvider));
}
......@@ -189,13 +190,13 @@ 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();
}
getShell().setData("org.eclipse.e4.ui.shellContext", e4Context.createChild("expressionDialogContext"));
}
private boolean isSupportedConstantType(final String returnType) {
return returnType.equals(String.class.getName()) ||
returnType.equals(Boolean.class.getName()) ||
......@@ -237,7 +238,8 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
protected void createExpressionTypePanel(final Composite parentForm) {
final Composite parentComposite = new Composite(parentForm, SWT.NONE);
parentComposite.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.FILL).grab(false, true).create());
parentComposite
.setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.FILL).grab(false, true).create());
parentComposite.setLayout(new GridLayout(1, false));
final Label expressionTypeLabel = new Label(parentComposite, SWT.NONE);
......@@ -358,8 +360,6 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
if (currentExpressionEditor != null) {
dataBindingContext = new EMFDataBindingContext();
currentExpressionEditor.createExpressionEditor(contentComposite, dataBindingContext, isPassword);
contentComposite.layout(true, true);
if (helpControl != null) {
......@@ -384,7 +384,8 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
selectionToExpressionType.setConverter(convert);
if (domain != null) {
domain.getCommandStack().execute(SetCommand.create(domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__TYPE, type));
domain.getCommandStack().execute(
SetCommand.create(domain, inputExpression, ExpressionPackage.Literals.EXPRESSION__TYPE, type));
} else {
inputExpression.setType(type);
}
......@@ -394,7 +395,8 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
if (expressionNameResolver != null) {
inputExpression.setName(expressionNameResolver.getName(inputExpression));
}
currentExpressionEditor.bindExpression(dataBindingContext, context, inputExpression, viewerTypeFilters, expressionViewer);
currentExpressionEditor.bindExpression(dataBindingContext, context, inputExpression, viewerTypeFilters,
expressionViewer);
currentExpressionEditor.addListener(new Listener() {
@Override
......@@ -436,7 +438,8 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
if (FileActionDialog.getDisablePopup()) {
return true;
}
if (MessageDialog.openQuestion(getShell(), Messages.handleShellCloseEventTitle, Messages.handleShellCloseEventMessage)) {
if (MessageDialog.openQuestion(getShell(), Messages.handleShellCloseEventTitle,
Messages.handleShellCloseEventMessage)) {
return super.canHandleShellCloseEvent();
}
return false;
......
......@@ -143,7 +143,8 @@ public class GroovyViewer implements IDocumentListener {
final IEclipseContext activeLeaf = context.getActiveLeaf();
activeLeaf
.set("localContexts",
Lists.newLinkedList(Lists.newArrayList("org.eclipse.ui.contexts.window", "org.eclipse.ui.contexts.dialogAndWindow",
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);
......@@ -155,7 +156,7 @@ public class GroovyViewer implements IDocumentListener {
BonitaStudioLog.error(e1);
}
final StyledText styledText = getSourceViewer().getTextWidget();
final StyledText styledText = getSourceViewer().getTextWidget();
styledText.setTextLimit(MAX_SCRIPT_LENGTH);
getSourceViewer().addTextListener(new ITextListener() {
......@@ -178,22 +179,22 @@ public class GroovyViewer implements IDocumentListener {
styledText.setData(BONITA_KEYWORDS_DATA_KEY, getProvidedVariables(null, null));
styledText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell().getData("org.eclipse.e4.ui.shellContext");
if(context != null){
IEclipseContext context = (IEclipseContext) styledText.getShell()
.getData("org.eclipse.e4.ui.dialogShellContext");
if (context != null) {
context.deactivate();
}
}
@Override
public void focusGained(FocusEvent e) {
IEclipseContext context = (IEclipseContext) styledText.getShell().getData("org.eclipse.e4.ui.shellContext");
if(context != null){
if (context != null) {
context.activate();
}
}
}
});
mainComposite.getShell().addDisposeListener(new DisposeListener() {
......@@ -205,7 +206,6 @@ public class GroovyViewer implements IDocumentListener {
});
}
public IDocument getDocument() {
return editor.getDocumentProvider().getDocument(input);
}
......@@ -283,12 +283,15 @@ public class GroovyViewer implements IDocumentListener {
}
}
unknownElementsIndexer = new UnknownElementsIndexer(knowVariables, getGroovyCompilationUnit());
unknownElementsIndexer.addJobChangeListener(new UpdateUnknownReferencesListener(getDocument(), getSourceViewer().getAnnotationModel()));
unknownElementsIndexer.addJobChangeListener(
new UpdateUnknownReferencesListener(getDocument(), getSourceViewer().getAnnotationModel()));
}
public List<ScriptVariable> getProvidedVariables(final EObject context, final ViewerFilter[] filters) {
final List<ScriptVariable> providedScriptVariable = GroovyUtil.getBonitaVariables(context, filters, isPageFlowContext);
final IExpressionProvider daoExpressionProvider = ExpressionEditorService.getInstance().getExpressionProvider(ExpressionConstants.DAO_TYPE);
final List<ScriptVariable> providedScriptVariable = GroovyUtil.getBonitaVariables(context, filters,
isPageFlowContext);
final IExpressionProvider daoExpressionProvider = ExpressionEditorService.getInstance()
.getExpressionProvider(ExpressionConstants.DAO_TYPE);
if (daoExpressionProvider != null) {
final List<Expression> expressions = newArrayList(daoExpressionProvider.getExpressions(null));
Collections.sort(expressions, new ExpressionComparator());
......
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