Commit 31eb5d67 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

fix(patternExpression) do not remove referenced elements

* referenced elements where always cleaned on load

Closes BS-16504
parent 7214bb75
......@@ -33,6 +33,9 @@ import com.google.common.collect.Sets;
public class PatternExpressionModelBuilder implements IDocumentListener {
private static final String GROOVY_START_TAG = "${";
private static final String GROOVY_END_TAG = "}";
private List<Expression> scope;
private Expression expression;
......@@ -58,13 +61,14 @@ public class PatternExpressionModelBuilder implements IDocumentListener {
}
private String strip(String expression) {
if (expression.startsWith("${")) {
expression = expression.substring(2);
String strippedExpression = expression;
if (strippedExpression.startsWith(GROOVY_START_TAG)) {
strippedExpression = strippedExpression.substring(2);
}
if (expression.endsWith("}")) {
expression = expression.substring(0, expression.length() - 1);
if (strippedExpression.endsWith(GROOVY_END_TAG)) {
strippedExpression = strippedExpression.substring(0, strippedExpression.length() - 1);
}
return expression;
return strippedExpression;
}
/*
......@@ -90,14 +94,16 @@ public class PatternExpressionModelBuilder implements IDocumentListener {
try {
final String expressionContent = strip(document.get(region.getOffset(), region.getLength()));
if (expressionContent != null && !parsedExpressions.contains(expressionContent)) {
final Expression groovyScriptExpression = ExpressionHelper.createGroovyScriptExpression(expressionContent, String.class.getName());
final Expression groovyScriptExpression = ExpressionHelper
.createGroovyScriptExpression(expressionContent, String.class.getName());
groovyScriptExpression.setName(expressionContent);
final Document expDoc = new Document();
expDoc.set(expressionContent);
final FindReplaceDocumentAdapter expDocFinder = new FindReplaceDocumentAdapter(expDoc);
for (final Expression exp : scope) {
if (expDocFinder.find(0, exp.getName(), true, true, true, false) != null) {
groovyScriptExpression.getReferencedElements().add(ExpressionHelper.createDependencyFromEObject(exp));
groovyScriptExpression.getReferencedElements()
.add(ExpressionHelper.createDependencyFromEObject(exp));
}
}
expression.getReferencedElements().add(groovyScriptExpression);
......
......@@ -47,6 +47,7 @@ import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.ITextListener;
......@@ -73,8 +74,6 @@ import com.google.common.collect.Sets;
*/
public class PatternExpressionViewer extends Composite {
private static final String GROOVY_START_TAG = "${";
private static final String GROOVY_END_TAG = "}";
public static final String GROOVY_EXPRESSION_CONTENT_TYPE = "__groovy_partition_content_type";
private static final int UNDO_REDO_HISTORY_SIZE = 25;
private TextViewer viewer;
......@@ -125,7 +124,8 @@ public class PatternExpressionViewer extends Composite {
mc.hide(expressionViewer.getControl());
mc.show(getViewerControl());
helpDecoration.show();
mc.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).extendedMargins(15, 25, 0, 0).create());
mc.setLayout(
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).extendedMargins(15, 25, 0, 0).create());
bindPatternExpression();
} else {
mc.hide(getViewerControl());
......@@ -210,11 +210,16 @@ public class PatternExpressionViewer extends Composite {
configurePatternExpressionModelBuilder();
patternBinding = context.bindValue(SWTObservables.observeText(viewer.getTextWidget(), SWT.Modify),
EMFObservables.observeValue(expression, ExpressionPackage.Literals.EXPRESSION__CONTENT), startegy, null);
fireDocumentChanged();
}
protected void fireDocumentChanged() {
final DocumentEvent event = new DocumentEvent();
event.fDocument = viewer.getDocument();
patternExpressionModelBuilder.documentChanged(event);
}
protected void configurePatternExpressionModelBuilder() {
expression.getReferencedElements().clear();
patternExpressionModelBuilder.setExpression(expression);
}
......@@ -294,18 +299,17 @@ public class PatternExpressionViewer extends Composite {
document.setDocumentPartitioner(partitioner);
}
protected TextViewer createViewer(final Composite parent) {
return new TextViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
}
public void setContextInput(final EObject input) {
contextInput = input;
final List<Expression> filteredExpressions = getFilteredExpressions();
patternExpressionModelBuilder.setScope(filteredExpressions);
final ContentAssistant assistant = new ContentAssistant();
final PatternExpressionCompletionProcessor javaCompletionProcessor = new PatternExpressionCompletionProcessor(new FakeEditorPart(),
final PatternExpressionCompletionProcessor javaCompletionProcessor = new PatternExpressionCompletionProcessor(
new FakeEditorPart(),
filteredExpressions);
javaCompletionProcessor.setCompletionProposalAutoActivationCharacters(new char[] { '.' });
assistant.setContentAssistProcessor(javaCompletionProcessor, GROOVY_EXPRESSION_CONTENT_TYPE);
......
Markdown is supported
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