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();
}
}
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());
}
}
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;
}
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];
}
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;
}
Aggregations