Search in sources :

Example 26 with IRegion

use of org.eclipse.jface.text.IRegion in project tdi-studio-se by Talend.

the class ExpressionComposite method setExpression.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.expressionbuilder.ui.ExpressionController#setExpression(org.talend.designer.rowgenerator.data.Function
     * )
     */
public void setExpression(Function f) {
    String newValue = PERL_FUN_PREFIX;
    if (f != null) {
        final List<Parameter> parameters = f.getParameters();
        if (FunctionManager.isJavaProject()) {
            String fullName = f.getName();
            //$NON-NLS-1$
            newValue = fullName + "(";
            for (Parameter pa : parameters) {
                newValue += pa.getValue() + FUN_PARAM_SEPARATED;
            }
            if (!parameters.isEmpty()) {
                newValue = newValue.substring(0, newValue.length() - 1);
            }
            //$NON-NLS-1$
            newValue += ")";
        } else {
            //$NON-NLS-1$
            newValue += f.getName() + "(";
            for (Parameter pa : parameters) {
                newValue += pa.getValue() + FUN_PARAM_SEPARATED;
            }
            newValue = newValue.substring(0, newValue.length() - 1);
            newValue += PERL_FUN_SUFFIX;
        }
    }
    IRegion region = viewer.getViewerRegion();
    try {
        document.replace(region.getOffset(), region.getLength(), newValue);
    } catch (BadLocationException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : Parameter(org.talend.designer.rowgenerator.data.Parameter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 27 with IRegion

use of org.eclipse.jface.text.IRegion in project tdi-studio-se by Talend.

the class ReconcilerViewer method getAllSnippetsAnnotations.

private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
    Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
    IDocument document = getDocument();
    int curOffset = 0;
    FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
    try {
        //$NON-NLS-1$
        IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
        while (startRegion != null && startRegion.getOffset() >= curOffset) {
            int startLine = document.getLineOfOffset(startRegion.getOffset());
            int startOffset = document.getLineOffset(startLine);
            curOffset = startOffset + document.getLineLength(startLine);
            //$NON-NLS-1$
            IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
            if (endRegion != null) {
                int endLine = document.getLineOfOffset(endRegion.getOffset());
                int endOffset = document.getLineOffset(endLine);
                endOffset += document.getLineLength(endLine);
                curOffset = endOffset;
                String text = document.get(startOffset, endOffset - startOffset);
                ProjectionAnnotation annotation = new ProjectionAnnotation(true);
                annotation.setText(text);
                annotation.setRangeIndication(true);
                annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
            }
            if (curOffset < document.getLength()) {
                //$NON-NLS-1$
                startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
            }
        }
    } catch (BadLocationException e) {
        ExceptionHandler.process(e);
    }
    return annotations;
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 28 with IRegion

use of org.eclipse.jface.text.IRegion in project KaiZen-OpenAPI-Editor by RepreZen.

the class AbstractJsonHyperlinkDetector method getHyperlinkInfo.

protected HyperlinkInfo getHyperlinkInfo(ITextViewer viewer, IRegion region) {
    final JsonDocument document = (JsonDocument) viewer.getDocument();
    IRegion line;
    try {
        line = document.getLineInformationOfOffset(region.getOffset());
    } catch (BadLocationException e) {
        return null;
    }
    String lineContent;
    try {
        lineContent = document.get(line.getOffset(), line.getLength());
    } catch (BadLocationException e) {
        return null;
    }
    if (lineContent == null || emptyToNull(lineContent) == null) {
        return null;
    }
    final int column = region.getOffset() - line.getOffset();
    final IRegion selected = getSelectedRegion(line, lineContent, column);
    String text;
    try {
        text = document.get(selected.getOffset(), selected.getLength());
    } catch (BadLocationException e) {
        return null;
    }
    if (emptyToNull(text) == null || text.trim().equals(":") || text.trim().equals("$ref:")) {
        return null;
    }
    return new HyperlinkInfo(selected, text, column);
}
Also used : JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 29 with IRegion

use of org.eclipse.jface.text.IRegion in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonReferenceHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    URI baseURI = getBaseURI();
    AbstractNode node = doc.getModel().find(pointer);
    JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node);
    if (reference == null) {
        reference = getFactory().create(node);
    }
    if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) {
        return null;
    }
    if (reference.isLocal()) {
        IRegion target = doc.getRegion(reference.getPointer());
        if (target == null) {
            return null;
        }
        return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) };
    } else {
        URI resolved;
        try {
            resolved = baseURI.resolve(reference.getUri());
        } catch (IllegalArgumentException e) {
            // the given string violates RFC 2396
            return null;
        }
        IFile file = DocumentUtils.getWorkspaceFile(resolved);
        if (file != null && file.exists()) {
            return new IHyperlink[] { createFileHyperlink(info.region, info.text, file, reference.getPointer()) };
        }
    }
    return null;
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion)

Example 30 with IRegion

use of org.eclipse.jface.text.IRegion in project KaiZen-OpenAPI-Editor by RepreZen.

the class DefinitionHyperlinkDetector method doDetect.

@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    JsonPointer targetPath;
    if (pointer.toString().matches(REQUIRED_PATTERN)) {
        targetPath = getRequiredPropertyPath(doc, info, pointer);
    } else {
        targetPath = getTagDefinitionPath(doc, info, pointer);
    }
    if (targetPath == null) {
        return null;
    }
    IRegion target = doc.getRegion(targetPath);
    if (target == null) {
        return null;
    }
    return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
Also used : SwaggerHyperlink(com.reprezen.swagedit.core.hyperlinks.SwaggerHyperlink) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) JsonPointer(com.fasterxml.jackson.core.JsonPointer) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IRegion (org.eclipse.jface.text.IRegion)668 BadLocationException (org.eclipse.jface.text.BadLocationException)291 Region (org.eclipse.jface.text.Region)265 IDocument (org.eclipse.jface.text.IDocument)143 Test (org.junit.Test)108 Point (org.eclipse.swt.graphics.Point)76 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)57 ITypedRegion (org.eclipse.jface.text.ITypedRegion)55 Position (org.eclipse.jface.text.Position)50 ArrayList (java.util.ArrayList)37 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)35 IFile (org.eclipse.core.resources.IFile)33 ITextSelection (org.eclipse.jface.text.ITextSelection)32 IEditorPart (org.eclipse.ui.IEditorPart)29 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)24 StyledText (org.eclipse.swt.custom.StyledText)22 CoreException (org.eclipse.core.runtime.CoreException)19 List (java.util.List)18 Document (org.eclipse.jface.text.Document)17 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)17