Search in sources :

Example 31 with IRegion

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

the class SwaggerTemplateContext method createTemplateTranslator.

protected TemplateTranslator createTemplateTranslator() {
    try {
        int offset = getStart();
        IRegion lineRegion = getDocument().getLineInformationOfOffset(offset);
        String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
        int i = 0;
        // support for array items
        StringBuilder indentation = new StringBuilder();
        while (i < line.length()) {
            char indentSymbol = line.charAt(i);
            if (Character.isWhitespace(indentSymbol)) {
                indentation.append(indentSymbol);
                i++;
            } else if ('-' == indentSymbol) {
                // array item
                indentation.append(' ');
                i++;
            } else {
                break;
            }
        }
        if (i != 0)
            return new IndentationAwareTemplateTranslator(indentation.toString());
        return new TemplateTranslator();
    } catch (BadLocationException ex) {
        return new TemplateTranslator();
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) TemplateTranslator(org.eclipse.jface.text.templates.TemplateTranslator)

Example 32 with IRegion

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

the class TextDocumentMarkerResolution method run.

public void run(IMarker marker) {
    try {
        IResource resource = marker.getResource();
        if (resource.getType() != IResource.FILE) {
            throw new CoreException(createStatus(null, "The editor is not a File: " + resource.getName()));
        }
        IFile file = (IFile) resource;
        ITextEditor editor = openTextEditor(file);
        IDocument document = editor.getDocumentProvider().getDocument(new FileEditorInput(file));
        if (document == null) {
            throw new CoreException(createStatus(null, "The document is null"));
        }
        IRegion region = processFix(document, marker);
        if (region != null) {
            editor.selectAndReveal(region.getOffset(), region.getLength());
        }
    } catch (CoreException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 33 with IRegion

use of org.eclipse.jface.text.IRegion in project dbeaver by serge-rider.

the class TextUtils method isEmptyLine.

public static boolean isEmptyLine(IDocument document, int line) throws BadLocationException {
    IRegion region = document.getLineInformation(line);
    if (region == null || region.getLength() == 0) {
        return true;
    }
    String str = document.get(region.getOffset(), region.getLength());
    return str.trim().length() == 0;
}
Also used : IRegion(org.eclipse.jface.text.IRegion)

Example 34 with IRegion

use of org.eclipse.jface.text.IRegion in project dbeaver by serge-rider.

the class NavigateObjectHandler method getCurrentHyperlink.

private IHyperlink getCurrentHyperlink(SQLEditorBase editor) {
    SQLHyperlinkDetector hyperlinkDetector = new SQLHyperlinkDetector(editor, editor.getSyntaxManager());
    ITextSelection selection = (ITextSelection) editor.getTextViewer().getSelection();
    IRegion curRegion = new Region(selection.getOffset(), 0);
    IHyperlink[] hyperLinks = hyperlinkDetector.detectHyperlinks(editor.getTextViewer(), curRegion, false);
    return ArrayUtils.isEmpty(hyperLinks) ? null : hyperLinks[0];
}
Also used : SQLHyperlinkDetector(org.jkiss.dbeaver.ui.editors.sql.syntax.SQLHyperlinkDetector) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) IRegion(org.eclipse.jface.text.IRegion)

Example 35 with IRegion

use of org.eclipse.jface.text.IRegion in project translationstudio8 by heartsome.

the class CellDisplayValueSearchUtil method findCell.

static CellRegion findCell(final ILayer layer, final IConfigRegistry configRegistry, final PositionCoordinate[] cellsToSearch, final Object valueToMatch, final ICellSearchStrategy cellSearchStrategy) {
    final List<PositionCoordinate> cellCoordinates = Arrays.asList(cellsToSearch);
    // Find cell
    CellRegion targetCoordinate = null;
    String stringValue = valueToMatch.toString();
    final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
    for (int cellIndex = 0; cellIndex < cellCoordinates.size(); cellIndex++) {
        final PositionCoordinate cellCoordinate = cellCoordinates.get(cellIndex);
        final int columnPosition = cellCoordinate.columnPosition;
        final int rowPosition = cellCoordinate.rowPosition;
        // Convert cell's data
        if (displayConverter instanceof TagDisplayConverter) {
            LayerCell cell = new LayerCell(cellCoordinate.getLayer(), cellCoordinate.getColumnPosition(), cellCoordinate.getRowPosition());
            ((TagDisplayConverter) displayConverter).setCell(cell);
        }
        final Object dataValue = displayConverter.canonicalToDisplayValue(layer.getDataValueByPosition(columnPosition, rowPosition));
        // Compare with valueToMatch
        if (dataValue instanceof String) {
            String dataValueString = dataValue.toString();
            IRegion region;
            if ((region = cellSearchStrategy.executeSearch(stringValue, dataValueString)) != null) {
                targetCoordinate = new CellRegion(cellCoordinate, region);
                break;
            }
            ((DefaultCellSearchStrategy) cellSearchStrategy).setStartOffset(-1);
        }
    }
    return targetCoordinate;
}
Also used : CellRegion(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) TagDisplayConverter(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.TagDisplayConverter) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) 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