Search in sources :

Example 6 with ITextHover

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;
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 7 with ITextHover

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;
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) ProblemAnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor) AnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor) ProblemAnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor) BestMatchHover(org.eclipse.wst.sse.ui.internal.taginfo.BestMatchHover)

Example 8 with ITextHover

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);
    }
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover)

Example 9 with ITextHover

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();
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IInformationControlCreator(org.eclipse.jface.text.IInformationControlCreator) GridLayout(org.eclipse.swt.layout.GridLayout) IInformationControl(org.eclipse.jface.text.IInformationControl) AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) Control(org.eclipse.swt.widgets.Control) ITextHover(org.eclipse.jface.text.ITextHover) IInformationControl(org.eclipse.jface.text.IInformationControl) AbstractInformationControl(org.eclipse.jface.text.AbstractInformationControl) GridData(org.eclipse.swt.layout.GridData)

Example 10 with ITextHover

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;
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

ITextHover (org.eclipse.jface.text.ITextHover)23 IRegion (org.eclipse.jface.text.IRegion)8 Region (org.eclipse.jface.text.Region)5 AbstractCompositeHover (org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover)4 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 AnnotationHoverProcessor (org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor)3 ProblemAnnotationHoverProcessor (org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor)3 ITextHoverExtension2 (org.eclipse.jface.text.ITextHoverExtension2)2 ITextViewer (org.eclipse.jface.text.ITextViewer)2 Point (org.eclipse.swt.graphics.Point)2 CompoundRegion (com.liferay.ide.xml.search.ui.editor.CompoundRegion)1 InfoRegion (com.liferay.ide.xml.search.ui.editor.InfoRegion)1 LiferayCustomXmlHover (com.liferay.ide.xml.search.ui.editor.LiferayCustomXmlHover)1 MarkerRegion (com.liferay.ide.xml.search.ui.editor.MarkerRegion)1 TemporaryRegion (com.liferay.ide.xml.search.ui.editor.TemporaryRegion)1 Method (java.lang.reflect.Method)1