|
|
|
|
|
|
Re: Strange editor redraw problem [message #1713046 is a reply to message #1712989] |
Fri, 30 October 2015 09:51 |
Aleksandar Toshovski Messages: 78 Registered: December 2011 |
Member |
|
|
No, it doesn't. Yesterday found the cause of the problem, but I'm not sure I understand why. A colleague of mine has implemented a PropertyTester, which causes the problem. When I remove the code it works normally. The funny thing is that we have two DSL languages: dsl1 and dsl2. The dsl2 extends dsl1. He implemented that in the first language and the problem occurs only in the second dsl. And it occurs after editing and saving the file. When I continue editing the editor gets broken.
package dsl.ui.tester;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.ILeafNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import dsl.Model;
public class TextSelectedPropertyTester extends PropertyTester {
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (property.equals("stringSelected")) {
ISelection selection = EditorUtils.getActiveXtextEditor().getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
int offset = ((ITextSelection) selection).getOffset();
boolean containsQuoteSymbol = ((ITextSelection) selection).getText().contains("\"");
if (containsQuoteSymbol)
return false;
IXtextDocument document = EditorUtils.getActiveXtextEditor().getDocument();
Model model = getModel(document);
if(model==null){
return false;
}
ICompositeNode node = NodeModelUtils.getNode(model);
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(node, offset);
if (leafNode != null && leafNode.getText().startsWith("\"") && leafNode.getText().endsWith("\"")) {
return true;
}
}
}
return false;
}
private Model getModel(IXtextDocument document) {
return document.readOnly(new IUnitOfWork<Model, XtextResource>() {
@Override
public Model exec(XtextResource resource) throws Exception {
if(resource.getContents().get(0) instanceof Model){
return (Model) resource.getContents().get(0);
}
return null;
}
});
}
}
The extension point
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="dsl.ui.tester.TextSelectedPropertyTester"
id="dsl.textSelection.tester"
namespace="dsl.ui"
properties="stringSelected"
type="java.lang.Object">
</propertyTester>
</extension>
[Updated on: Fri, 30 October 2015 09:53] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04394 seconds