use of org.eclipse.jface.text.ITextHover in project webtools.sourceediting by eclipse.
the class StructuredTextViewer method getTextHover.
protected ITextHover getTextHover(int offset, int stateMask) {
ITextHover hover = super.getTextHover(offset, stateMask);
if (hover == null) {
final IDocument document = getDocument();
if (fConfiguration != null && document != null) {
// Check for computed partitions
try {
final String partition = TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
final int idx = partition != null ? partition.indexOf(':') : -1;
if (idx > -1) {
hover = fConfiguration.getTextHover(this, partition.substring(0, idx), stateMask);
}
} catch (BadLocationException e) {
}
}
}
return hover;
}
use of org.eclipse.jface.text.ITextHover in project webtools.sourceediting by eclipse.
the class StructuredTextViewerConfiguration method getTextHover.
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
ITextHover textHover = null;
/*
* Returns a default problem, annotation, and best match hover
* depending on stateMask
*/
TextHoverManager.TextHoverDescriptor[] hoverDescs = SSEUIPlugin.getDefault().getTextHoverManager().getTextHovers();
int i = 0;
while (i < hoverDescs.length && textHover == null) {
if (hoverDescs[i].isEnabled() && computeStateMask(hoverDescs[i].getModifierString()) == stateMask) {
String hoverType = hoverDescs[i].getId();
if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType))
textHover = new ProblemAnnotationHoverProcessor();
else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType))
textHover = new AnnotationHoverProcessor();
else if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType))
textHover = new BestMatchHover(contentType);
else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) {
ITextHover[] hovers = createDocumentationHovers(contentType);
if (hovers.length > 0) {
textHover = hovers[0];
}
}
}
i++;
}
return textHover;
}
use of org.eclipse.jface.text.ITextHover in project webtools.sourceediting by eclipse.
the class TestViewerConfigurationHTML method testGetTextHover.
public void testGetTextHover() {
// probably no display
if (!fDisplayExists)
return;
String[] hoverPartitions = new String[] { IHTMLPartitions.HTML_DEFAULT, IHTMLPartitions.SCRIPT };
for (int i = 0; i < hoverPartitions.length; i++) {
ITextHover hover = fConfig.getTextHover(fViewer, hoverPartitions[i], SWT.NONE);
assertNotNull("hover was null for partition: " + hoverPartitions[i], hover);
}
}
use of org.eclipse.jface.text.ITextHover in project eclipse.platform.text by eclipse.
the class CompositeInformationControl method createContent.
@Override
public void createContent(Composite parent) {
// TODO maybe use canReuse or canReplace
this.controls = new LinkedHashMap<>();
GridLayout layout = new GridLayout(1, false);
parent.setLayout(layout);
boolean firstControl = true;
for (Entry<ITextHover, IInformationControlCreator> hoverControlCreator : this.creators.entrySet()) {
IInformationControl informationControl = hoverControlCreator.getValue().createInformationControl(parent.getShell());
if (informationControl instanceof AbstractInformationControl) {
List<Control> children = Arrays.asList(((AbstractInformationControl) informationControl).getShell().getChildren());
children.remove(parent);
if (children.size() == 0) {
continue;
}
for (Control control : children) {
control.setParent(parent);
control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
if (!firstControl) {
((GridData) children.get(0).getLayoutData()).verticalIndent = 15;
}
controls.put(hoverControlCreator.getKey(), informationControl);
firstControl = false;
} else {
GenericEditorPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, GenericEditorPlugin.BUNDLE_ID, // $NON-NLS-1$
"Only text hovers producing an AbstractInformationControl can be aggregated; got a " + informationControl.getClass().getSimpleName()));
informationControl.dispose();
}
}
}
use of org.eclipse.jface.text.ITextHover in project eclipse.platform.text by eclipse.
the class CompositeTextHover method getHoverRegion.
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
this.regions = new LinkedHashMap<>();
IRegion res = null;
for (ITextHover hover : this.allHovers) {
IRegion region = hover.getHoverRegion(textViewer, offset);
if (region != null) {
this.regions.put(hover, region);
if (res == null) {
res = region;
} else {
int startOffset = Math.max(res.getOffset(), region.getOffset());
int endOffset = Math.min(res.getOffset() + res.getLength(), region.getOffset() + region.getLength());
res = new Region(startOffset, endOffset - startOffset);
}
}
}
return res;
}
Aggregations