Search in sources :

Example 21 with ITextHover

use of org.eclipse.jface.text.ITextHover in project liferay-ide by liferay.

the class XmlSearchTestsUtils method getTextHover.

private static String[] getTextHover(IFile file, int nodeType, String... nodeNames) throws Exception {
    List<String> retval = new ArrayList<String>();
    IDOMModel domModel = null;
    Node targetNode = null;
    final StructuredTextViewer viewer = getEditor(file).getTextViewer();
    if (nodeType == Node.ELEMENT_NODE) {
        String elementName = nodeNames[0];
        domModel = getDOMModel(file, false);
        // the actual node is text node of this.element
        targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0).getFirstChild();
    } else if (nodeType == Node.ATTRIBUTE_NODE) {
        String elementName = nodeNames[0];
        String attrName = nodeNames[1];
        domModel = getDOMModel(file, false);
        NodeList elements = domModel.getDocument().getElementsByTagName(elementName);
        Element element = getElementByAttr(elements, attrName);
        targetNode = element.getAttributes().getNamedItem(attrName);
    } else {
        return null;
    }
    int offset = getRegion(targetNode).getOffset();
    final Method getTextHoverMethod = ReflectionUtil.getDeclaredMethod(viewer.getClass(), "getTextHover", true, int.class, int.class);
    getTextHoverMethod.setAccessible(true);
    final ITextHover hover = (ITextHover) getTextHoverMethod.invoke(viewer, offset, 0);
    final IRegion region = hover.getHoverRegion(viewer, offset);
    if (region instanceof CompoundRegion) {
        List<IRegion> regions = ((CompoundRegion) region).getRegions();
        for (IRegion reg : regions) {
            if (reg instanceof TemporaryRegion) {
                String info = ((TemporaryRegion) reg).getAnnotation().getText();
                retval.add(info);
            }
            if (reg instanceof MarkerRegion) {
                MarkerAnnotation annotation = ((MarkerRegion) reg).getAnnotation();
                String info = (annotation.getMarker().getAttribute(IMarker.MESSAGE)).toString();
                retval.add(info);
            }
            if (reg instanceof InfoRegion) {
                retval.add(((InfoRegion) reg).getInfo());
            }
        }
    }
    domModel.releaseFromRead();
    return retval.toArray(new String[0]);
}
Also used : MarkerRegion(com.liferay.ide.xml.search.ui.editor.MarkerRegion) ITextHover(org.eclipse.jface.text.ITextHover) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) IRegion(org.eclipse.jface.text.IRegion) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) InfoRegion(com.liferay.ide.xml.search.ui.editor.InfoRegion) CompoundRegion(com.liferay.ide.xml.search.ui.editor.CompoundRegion) TemporaryRegion(com.liferay.ide.xml.search.ui.editor.TemporaryRegion) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 22 with ITextHover

use of org.eclipse.jface.text.ITextHover in project liferay-ide by liferay.

the class LiferayCustomXmlViewerConfiguration method getTextHover.

@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
    ITextHover textHover = null;
    /*
		 * Returns a default problem, annotation, and best match hover depending
		 * on stateMask
		 */
    SSEUIPlugin plugin = SSEUIPlugin.getDefault();
    TextHoverManager.TextHoverDescriptor[] hoverDescs = plugin.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 = createDocumentationHover(contentType);
            } else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) {
                textHover = createDocumentationHover(contentType);
            }
        }
        i++;
    }
    return textHover;
}
Also used : SSEUIPlugin(org.eclipse.wst.sse.ui.internal.SSEUIPlugin) ITextHover(org.eclipse.jface.text.ITextHover) AnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor) ProblemAnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor) ProblemAnnotationHoverProcessor(org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor)

Example 23 with ITextHover

use of org.eclipse.jface.text.ITextHover in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testSingleHover.

@SuppressWarnings("deprecation")
@Test
public void testSingleHover() {
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            hovers.add(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 "test";
                }
            });
            return hovers;
        }
    };
    assertEquals(1, hover.getHovers().size());
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertEquals("test", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 5));
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
}
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) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

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