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 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);
}
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 TextViewerJoinLinesAction method run.
@Override
public void run() {
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;
int startLine = selection.getStartLine();
int endLine = selection.getEndLine();
try {
int caretOffset = joinLines(document, startLine, endLine);
if (caretOffset > -1) {
StyledText widget = viewer.getTextWidget();
widget.setRedraw(false);
adjustHighlightRange(viewer, caretOffset, 0);
viewer.revealRange(caretOffset, 0);
viewer.setSelectedRange(caretOffset, 0);
widget.setRedraw(true);
}
} catch (BadLocationException e) {
// should not happen
}
}
Aggregations