use of org.eclipse.jface.text.ITextViewer in project dbeaver by dbeaver.
the class SQLCompletionProposal method validate.
@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
if (event == null) {
return false;
}
SQLSyntaxManager syntaxManager = getContext().getSyntaxManager();
DBPDataSource dataSource = getContext().getDataSource();
final SQLWordPartDetector wordDetector = new SQLWordPartDetector(document, syntaxManager, offset);
String wordPart = wordDetector.getWordPart();
int divPos = wordPart.lastIndexOf(syntaxManager.getStructSeparator());
if (divPos != -1) {
if (divPos == wordPart.length() - 1) {
// It is valid only if full word matches (it should be the only proposal)
if (replacementString.equals(wordPart.substring(0, divPos))) {
{
// Call completion popup again
UIUtils.asyncExec(() -> {
IEditorPart activeEditor = UIUtils.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor != null) {
ITextViewer textViewer = activeEditor.getAdapter(ITextViewer.class);
if (textViewer != null) {
textViewer.getTextOperationTarget().doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
}
}
});
}
}
return false;
}
wordPart = wordPart.substring(divPos + 1);
}
String wordLower = wordPart.toLowerCase(Locale.ENGLISH);
if (!CommonUtils.isEmpty(wordPart)) {
boolean matchContains = dataSource != null && dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.PROPOSALS_MATCH_CONTAINS);
boolean matched;
if (getObject() == null || !matchContains) {
// For keywords use strict matching
matched = (matchContains ? replacementFull.contains(wordLower) : replacementFull.startsWith(wordLower)) && (CommonUtils.isEmpty(event.getText()) || replacementFull.contains(event.getText().toLowerCase(Locale.ENGLISH))) || (this.replacementLast != null && this.replacementLast.startsWith(wordLower));
} else {
// For objects use fuzzy matching
int score = TextUtils.fuzzyScore(replacementFull, wordLower);
matched = (score > 0 && (CommonUtils.isEmpty(event.getText()) || TextUtils.fuzzyScore(replacementFull, event.getText()) > 0)) || (this.replacementLast != null && TextUtils.fuzzyScore(this.replacementLast, wordLower) > 0);
if (matched) {
setProposalScore(score);
}
}
if (matched) {
setPosition(wordDetector);
return true;
}
} else if (divPos != -1) {
// Most likely it is a column name after an alias - all columns are valid
if (getObject() != null) {
return true;
}
}
return false;
}
use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.
the class AbstractCompositeHoverTest method testMultipleHovers.
@SuppressWarnings("deprecation")
@Test
public void testMultipleHovers() {
final ITextHover hover1 = new ITextHover() {
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
// TODO Auto-generated method stub
if (offset == 0)
return new Region(offset, 0);
return null;
}
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
return "hover1";
}
};
final ITextHover hover2 = new ITextHover() {
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
// TODO Auto-generated method stub
if (offset == 1)
return new Region(offset, 0);
return null;
}
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
return "hover2";
}
};
AbstractCompositeHover hover = new AbstractCompositeHover() {
@Override
protected List<ITextHover> createHovers() {
List<ITextHover> hovers = Lists.newArrayList();
hovers.add(hover1);
hovers.add(hover2);
return hovers;
}
};
assertEquals(2, hover.getHovers().size());
assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
assertEquals("hover1", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 1));
assertEquals("hover2", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(1, 0)));
}
use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.
the class CrossReferenceProposalTest method testBug276742_08b.
@Test
public void testBug276742_08b() throws Exception {
String modelAsString = "Foo {}";
ContentAssistProcessorTestBuilder builder = newBuilder();
XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class);
XtextResource resource = getResourceFromString(modelAsString);
ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString));
ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, modelAsString.length(), resource);
assertEquals(2, contexts.length);
Set<EClass> contextTypes = Sets.newHashSet(CrossReferenceProposalTestPackage.Literals.MODEL, CrossReferenceProposalTestPackage.Literals.CLASS);
CrossReferenceProposalTestLanguageGrammarAccess grammarAccess = get(CrossReferenceProposalTestLanguageGrammarAccess.class);
for (ContentAssistContext context : contexts) {
EObject model = context.getCurrentModel();
assertTrue(contextTypes.remove(model.eClass()));
if (context.getFirstSetGrammarElements().contains(grammarAccess.getClassAccess().getRightCurlyBracketKeyword_3())) {
assertEquals(CrossReferenceProposalTestPackage.Literals.CLASS, model.eClass());
} else {
assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, model.eClass());
}
}
}
use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.
the class TextViewerDeleteLineAction method run.
/*
* @see IAction#run()
*/
@Override
public void run() {
if (fTarget == null)
return;
ITextViewer viewer = getTextViewer();
if (viewer == null)
return;
if (!canModifyViewer())
return;
IDocument document = viewer.getDocument();
if (document == null)
return;
ITextSelection selection = getSelection(viewer);
if (selection == null)
return;
try {
fTarget.deleteLine(document, selection, fType, fCopyToClipboard);
} catch (BadLocationException e) {
// should not happen
}
}
use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.
the class TextViewerDeleteLineAction method update.
/*
* @see IUpdate#update()
*/
@Override
public void update() {
super.update();
if (!isEnabled())
return;
if (!canModifyViewer()) {
setEnabled(false);
return;
}
ITextViewer viewer = getTextViewer();
if (viewer != null) {
if (fTarget == null) {
fTarget = new TextViewerDeleteLineTarget(viewer);
}
} else {
fTarget = null;
}
setEnabled(fTarget != null);
}
Aggregations