Search in sources :

Example 61 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer in project liferay-ide by liferay.

the class XmlSearchTestsUtils method getHyperLinks.

private static IHyperlink[] getHyperLinks(IFile file, int nodeType, String... nodeNames) throws Exception {
    List<IHyperlink> retval = new ArrayList<IHyperlink>();
    IDOMModel domModel = null;
    Node targetNode = null;
    final StructuredTextViewer viewer = getEditor(file).getTextViewer();
    final SourceViewerConfiguration conf = getSourceViewerConfiguraionFromExtensionPoint(file);
    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);
        targetNode = getElementByAttr(elements, attrName).getAttributes().getNamedItem(attrName);
        elements = domModel.getDocument().getElementsByTagName(elementName);
    } else {
        return new IHyperlink[0];
    }
    assertNotNull(targetNode);
    viewer.refresh();
    final IHyperlinkDetector[] hyperlinkDetectors = conf.getHyperlinkDetectors(viewer);
    final IRegion region = getRegion(targetNode);
    for (IHyperlinkDetector detector : hyperlinkDetectors) {
        IHyperlink[] tempHyperlinks = detector.detectHyperlinks(viewer, region, true);
        if (tempHyperlinks != null && tempHyperlinks.length > 0) {
            retval.addAll(Arrays.asList(tempHyperlinks));
        }
    }
    domModel.releaseFromRead();
    return retval.toArray(new IHyperlink[0]);
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) IRegion(org.eclipse.jface.text.IRegion) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Example 62 with StructuredTextViewer

use of org.eclipse.wst.sse.ui.internal.StructuredTextViewer 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)

Aggregations

StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)62 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)21 IDocument (org.eclipse.jface.text.IDocument)19 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)18 IFile (org.eclipse.core.resources.IFile)14 SourceViewer (org.eclipse.jface.text.source.SourceViewer)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)14 Composite (org.eclipse.swt.widgets.Composite)13 Shell (org.eclipse.swt.widgets.Shell)13 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)12 StructuredTextViewerConfiguration (org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration)9 LineStyleProvider (org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider)8 ArrayList (java.util.ArrayList)7 BadLocationException (org.eclipse.jface.text.BadLocationException)6 Position (org.eclipse.jface.text.Position)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6 List (java.util.List)5 Action (org.eclipse.jface.action.Action)4 IContributionManager (org.eclipse.jface.action.IContributionManager)4 Separator (org.eclipse.jface.action.Separator)4