Search in sources :

Example 1 with ITextHover

use of org.eclipse.jface.text.ITextHover in project eclipse.platform.text by eclipse.

the class CompositeTextHover method getHoverInfo2.

@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion requestRegion) {
    this.currentHovers = new LinkedHashMap<>();
    for (ITextHover hover : this.allHovers) {
        IRegion currentRegion = this.regions.get(hover);
        if (currentRegion == null) {
            continue;
        }
        Object res = hover instanceof ITextHoverExtension2 ? ((ITextHoverExtension2) hover).getHoverInfo2(textViewer, currentRegion) : hover.getHoverInfo(textViewer, currentRegion);
        if (res != null) {
            this.currentHovers.put(hover, res);
        }
    }
    if (this.currentHovers.isEmpty()) {
        return null;
    } else if (this.currentHovers.size() == 1) {
        return this.currentHovers.values().iterator().next();
    } else {
        return this.currentHovers;
    }
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) ITextHoverExtension2(org.eclipse.jface.text.ITextHoverExtension2) IRegion(org.eclipse.jface.text.IRegion)

Example 2 with ITextHover

use of org.eclipse.jface.text.ITextHover 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)));
}
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) ITextViewer(org.eclipse.jface.text.ITextViewer) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 3 with ITextHover

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

the class AbstractCompositeHoverTest method testNullHoverList.

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

        @Override
        protected List<ITextHover> createHovers() {
            return null;
        }
    };
    assertEquals(null, hover.getHovers());
    assertNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertNull(hover.getHoverControlCreator());
    assertNull(hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNull(hover.getHoverInfo2(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) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 4 with ITextHover

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

the class AbstractCompositeHoverTest method testEmptyHoverList.

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

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

Example 5 with ITextHover

use of org.eclipse.jface.text.ITextHover in project webtools.sourceediting by eclipse.

the class BestMatchHover method createTextHoversList.

/**
 * Create a list of text hovers applicable to this best match hover
 * processor
 *
 * @return List of ITextHover - in abstract class this is empty list
 */
private List createTextHoversList() {
    List hoverList = new ArrayList();
    // best match
    if (Logger.isTracing(DebugInfoHoverProcessor.TRACEFILTER)) {
        hoverList.add(new DebugInfoHoverProcessor());
    }
    hoverList.add(new ProblemAnnotationHoverProcessor());
    if (fPartitionType != null && fTagInfoHovers == null) {
        List extendedTextHover = ExtendedConfigurationBuilder.getInstance().getConfigurations(ExtendedConfigurationBuilder.DOCUMENTATIONTEXTHOVER, fPartitionType);
        fTagInfoHovers = (ITextHover[]) extendedTextHover.toArray(new ITextHover[extendedTextHover.size()]);
    }
    if (fTagInfoHovers != null) {
        for (int i = 0; i < fTagInfoHovers.length; i++) {
            hoverList.add(fTagInfoHovers[i]);
        }
    }
    hoverList.add(new AnnotationHoverProcessor());
    return hoverList;
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

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