org.eclipse.jface.text.ITextViewerExtension5 Java Examples
The following examples show how to use
org.eclipse.jface.text.ITextViewerExtension5.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuickOutlinePopupDialog.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayoutFactory.fillDefaults().applyTo(composite); fPage.createControl(composite); // Try to select the current item we're on in editor in the outline ISourceViewer viewer = fEditor.getISourceViewer(); int offset = viewer.getTextWidget().getCaretOffset(); if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 v5 = (ITextViewerExtension5) viewer; offset = v5.widgetOffset2ModelOffset(offset); } if (offset != -1) { fPage.revealPosition(offset); } GridDataFactory.fillDefaults().hint(320, 240).applyTo(composite); return composite; }
Example #2
Source File: WhitespaceCharacterPainter.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Convert a document offset to the corresponding widget offset. * * @param documentOffset * @return widget offset */ private int getWidgetOffset(int documentOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.modelOffset2WidgetOffset(documentOffset); } IRegion visible = fTextViewer.getVisibleRegion(); int widgetOffset = documentOffset - visible.getOffset(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset; }
Example #3
Source File: RenameRefactoringPopup.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected Point computePopupLocation() { if (popup == null || popup.isDisposed()) return null; LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition(); if (position == null) return null; ISourceViewer viewer = editor.getInternalSourceViewer(); ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer; int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset); StyledText textWidget = viewer.getTextWidget(); Point pos = textWidget.getLocationAtOffset(widgetOffset); Point pSize = getExtent(); pSize.y += HAH + 1; pos.x -= HAO; pos.y += textWidget.getLineHeight(widgetOffset); Point dPos = textWidget.toDisplay(pos); Rectangle displayBounds = textWidget.getDisplay().getClientArea(); Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize); Geometry.moveInside(dPopupRect, displayBounds); return new Point(dPopupRect.x, dPopupRect.y); }
Example #4
Source File: AbstractThemeableEditor.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public int getCaretOffset() { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) { return -1; } StyledText styledText = sourceViewer.getTextWidget(); if (styledText == null) { return -1; } if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; return extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } int offset = sourceViewer.getVisibleRegion().getOffset(); return offset + styledText.getCaretOffset(); }
Example #5
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Convert a document offset to the corresponding widget offset. * * @param viewer the text viewer * @param documentOffset the document offset * @return widget offset * @since 3.6 */ private int getWidgetOffset(ITextViewer viewer, int documentOffset) { if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5)viewer; return extension.modelOffset2WidgetOffset(documentOffset); } IRegion visible= viewer.getVisibleRegion(); int widgetOffset= documentOffset - visible.getOffset(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset; }
Example #6
Source File: CommandExecutionUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private static void setCaretOffset(ITextViewer textViewer, int docOffset) { if (textViewer instanceof ITextViewerExtension5) { docOffset = ((ITextViewerExtension5) textViewer).modelOffset2WidgetOffset(docOffset); } textViewer.getTextWidget().setCaretOffset(docOffset); }
Example #7
Source File: CommandExecutionUtils.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private static int getCaretOffset(ITextViewer textViewer) { StyledText textWidget = textViewer.getTextWidget(); int caretOffset = textWidget.getCaretOffset(); if (textViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer; return extension.widgetOffset2ModelOffset(caretOffset); } return caretOffset; }
Example #8
Source File: LineBackgroundPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Returns the location of the caret as offset in the source viewer's input document. * * @return the caret location */ private int getModelCaret() { int widgetCaret = fViewer.getTextWidget().getCaretOffset(); if (fViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer; return extension.widgetOffset2ModelOffset(widgetCaret); } IRegion visible = fViewer.getVisibleRegion(); return widgetCaret + visible.getOffset(); }
Example #9
Source File: JavaMoveLinesAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>. * As a special case, a selection is considered contained even if it extends over the visible * region, but the extension stays on a partially contained line and contains only white space. * * @param selection the selection to be checked * @param viewer the viewer displaying a visible region of <code>selection</code>'s document. * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise. */ private boolean containedByVisibleRegion(ITextSelection selection, ISourceViewer viewer) { int min= selection.getOffset(); int max= min + selection.getLength(); IDocument document= viewer.getDocument(); IRegion visible; if (viewer instanceof ITextViewerExtension5) visible= ((ITextViewerExtension5) viewer).getModelCoverage(); else visible= viewer.getVisibleRegion(); int visOffset= visible.getOffset(); try { if (visOffset > min) { if (document.getLineOfOffset(visOffset) != selection.getStartLine()) return false; if (!isWhitespace(document.get(min, visOffset - min))) { showStatus(); return false; } } int visEnd= visOffset + visible.getLength(); if (visEnd < max) { if (document.getLineOfOffset(visEnd) != selection.getEndLine()) return false; if (!isWhitespace(document.get(visEnd, max - visEnd))) { showStatus(); return false; } } return true; } catch (BadLocationException e) { } return false; }
Example #10
Source File: JDTQuickMenuCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IRegion modelRange2WidgetRange(IRegion region) { ISourceViewer viewer= fEditor.getViewer(); if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5)viewer; return extension.modelRange2WidgetRange(region); } IRegion visibleRegion= viewer.getVisibleRegion(); int start= region.getOffset() - visibleRegion.getOffset(); int end= start + region.getLength(); if (end > visibleRegion.getLength()) end= visibleRegion.getLength(); return new Region(start, end - start); }
Example #11
Source File: TextViewerMoveLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>. * As a special case, a selection is considered contained even if it extends over the visible * region, but the extension stays on a partially contained line and contains only white space. * * @param selection the selection to be checked * @param viewer the viewer displaying a visible region of <code>selection</code>'s document. * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise. */ private boolean containedByVisibleRegion(ITextSelection selection, ITextViewer viewer) { int min= selection.getOffset(); int max= min + selection.getLength(); IDocument document= viewer.getDocument(); IRegion visible; if (viewer instanceof ITextViewerExtension5) visible= ((ITextViewerExtension5) viewer).getModelCoverage(); else visible= viewer.getVisibleRegion(); int visOffset= visible.getOffset(); try { if (visOffset > min) { if (document.getLineOfOffset(visOffset) != selection.getStartLine()) return false; if (!isWhitespace(document.get(min, visOffset - min))) { return false; } } int visEnd= visOffset + visible.getLength(); if (visEnd < max) { if (document.getLineOfOffset(visEnd) != selection.getEndLine()) return false; if (!isWhitespace(document.get(visEnd, max - visEnd))) { return false; } } return true; } catch (BadLocationException e) { } return false; }
Example #12
Source File: AbstractJavaCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a style range for the text viewer. * * @param viewer the text viewer * @return the new style range for the text viewer or <code>null</code> * @since 3.6 */ private StyleRange createStyleRange(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return null; int widgetCaret= text.getCaretOffset(); int modelCaret= 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; modelCaret= extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion= viewer.getVisibleRegion(); modelCaret= widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= getReplacementOffset() + getReplacementLength()) return null; int length= getReplacementOffset() + getReplacementLength() - modelCaret; Color foreground= getForegroundColor(); Color background= getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example #13
Source File: MarkUtils.java From e4macs with Eclipse Public License 1.0 | 5 votes |
public static int widget2ModelOffset(ISourceViewer viewer, int widgetOffset) { int result = widgetOffset; try { if (viewer instanceof ITextViewerExtension5) { result = ((ITextViewerExtension5) viewer).widgetOffset2ModelOffset(result); } } catch (Exception e) { } return result; }
Example #14
Source File: MarkUtils.java From e4macs with Eclipse Public License 1.0 | 5 votes |
public static int model2WidgetOffset(ISourceViewer viewer, int modelOffset) { int result = modelOffset; try { if (viewer instanceof ITextViewerExtension5) { result = ((ITextViewerExtension5) viewer).modelOffset2WidgetOffset(result); } } catch (Exception e) { } return result; }
Example #15
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 5 votes |
/** * Check if the given widget line is a folded line. * * @param widgetLine * the widget line number * @return <code>true</code> if the line is folded */ private boolean isFoldedLine(int widgetLine) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; int modelLine = extension.widgetLine2ModelLine(widgetLine); int widgetLine2 = extension.modelLine2WidgetLine(modelLine + 1); return widgetLine2 == -1; } return false; }
Example #16
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 5 votes |
/** * Convert a document offset to the corresponding widget offset. * * @param documentOffset * the document offset * @return widget offset */ private int getWidgetOffset(int documentOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.modelOffset2WidgetOffset(documentOffset); } IRegion visible = fTextViewer.getVisibleRegion(); int widgetOffset = documentOffset - visible.getOffset(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset; }
Example #17
Source File: IndentGuidePainter.java From IndentGuide with MIT License | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * the widget offset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example #18
Source File: PyCompletionPresentationUpdater.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private StyleRange createStyleRange(ITextViewer viewer, int initialOffset, int len) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return null; } int widgetCaret = text.getCaretOffset(); int modelCaret = 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; modelCaret = extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion = viewer.getVisibleRegion(); modelCaret = widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= initialOffset + len) { return null; } int length = initialOffset + len - modelCaret; Color foreground = getForegroundColor(); Color background = getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
Example #19
Source File: WhitespaceCharacterPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Check if the given widget line is a folded line. * * @param widgetLine * the widget line number * @return <code>true</code> if the line is folded */ private boolean isFoldedLine(int widgetLine) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; int modelLine = extension.widgetLine2ModelLine(widgetLine); int widgetLine2 = extension.modelLine2WidgetLine(modelLine + 1); return widgetLine2 == -1; } return false; }
Example #20
Source File: TMPresentationReconciler.java From tm4e with Eclipse Public License 1.0 | 5 votes |
/** * Translates the given text event into the corresponding range of the viewer's * document. * * @param e * the text event * @return the widget region corresponding the region of the given event or * <code>null</code> if none * @since 2.1 */ private IRegion widgetRegion2ModelRegion(TextEvent e) { String text = e.getText(); int length = text == null ? 0 : text.length(); if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); } IRegion visible = viewer.getVisibleRegion(); return new Region(e.getOffset() + visible.getOffset(), length); }
Example #21
Source File: MarkRegionTargetWithoutStatusline.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Tells whether the given offset is visible in the given text viewer. * * @param viewer * the text viewer * @param offset * the offset to check * @return <code>true</code> if the given offset is visible in the given text viewer */ protected boolean isVisible(ITextViewer viewer, int offset) { if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; return extension.modelOffset2WidgetOffset(offset) >= 0; } IRegion region = viewer.getVisibleRegion(); int vOffset = region.getOffset(); return (vOffset <= offset && offset <= vOffset + region.getLength()); }
Example #22
Source File: TextViewerJoinLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Adjusts the highlight range so that at least the specified range * is highlighted. * <p> * Subclasses may re-implement this method.</p> * * @param offset the offset of the range which at least should be highlighted * @param length the length of the range which at least should be highlighted */ protected void adjustHighlightRange(ITextViewer viewer, int offset, int length) { if (viewer == null) return; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; extension.exposeModelRange(new Region(offset, length)); } else if (!isVisible(viewer, offset, length)) { viewer.resetVisibleRegion(); } }
Example #23
Source File: TextViewerJoinLinesAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean isVisible(ITextViewer viewer, int offset, int length) { if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; IRegion overlap= extension.modelRange2WidgetRange(new Region(offset, length)); return overlap != null; } return viewer.overlapsWithVisibleRegion(offset, length); }
Example #24
Source File: HierarchyInformationPresenter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected IRegion modelRange2WidgetRange(IRegion region) { if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; return extension.modelRange2WidgetRange(region); } IRegion visibleRegion = sourceViewer.getVisibleRegion(); int start = region.getOffset() - visibleRegion.getOffset(); int end = start + region.getLength(); if (end > visibleRegion.getLength()) end = visibleRegion.getLength(); return new Region(start, end - start); }
Example #25
Source File: IndentGuidesPainter.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Check if the given widget line is a folded line. * * @param widgetLine * the widget line number * @return <code>true</code> if the line is folded */ private boolean isFoldedLine(int widgetLine) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; int modelLine = extension.widgetLine2ModelLine(widgetLine); int widgetLine2 = extension.modelLine2WidgetLine(modelLine + 1); return widgetLine2 == -1; } return false; }
Example #26
Source File: IndentGuidesPainter.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Convert a document offset to the corresponding widget offset. * * @param documentOffset * the document offset * @return widget offset */ private int getWidgetOffset(int documentOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.modelOffset2WidgetOffset(documentOffset); } IRegion visible = fTextViewer.getVisibleRegion(); int widgetOffset = documentOffset - visible.getOffset(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset; }
Example #27
Source File: IndentGuidesPainter.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * the widget offset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example #28
Source File: TypeScriptEditor.java From typescript.java with MIT License | 5 votes |
@Override public int getCursorOffset() { ISourceViewer sourceViewer = getSourceViewer(); StyledText styledText = sourceViewer.getTextWidget(); if (styledText == null) { return 0; } if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; return extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } else { int offset = sourceViewer.getVisibleRegion().getOffset(); return offset + styledText.getCaretOffset(); } }
Example #29
Source File: WhitespaceCharacterPainter.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Convert a widget offset to the corresponding document offset. * * @param widgetOffset * @return document offset */ private int getDocumentOffset(int widgetOffset) { if (fTextViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer; return extension.widgetOffset2ModelOffset(widgetOffset); } IRegion visible = fTextViewer.getVisibleRegion(); if (widgetOffset > visible.getLength()) { return -1; } return widgetOffset + visible.getOffset(); }
Example #30
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Computes and returns the source reference that includes the caret and * serves as provider for the outline page selection and the editor range * indication. * * @return the computed source reference * @since 3.0 */ protected ISourceReference computeHighlightRangeSourceReference() { ISourceViewer sourceViewer= getSourceViewer(); if (sourceViewer == null) return null; StyledText styledText= sourceViewer.getTextWidget(); if (styledText == null) return null; int caret= 0; if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5)sourceViewer; caret= extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } else { int offset= sourceViewer.getVisibleRegion().getOffset(); caret= offset + styledText.getCaretOffset(); } IJavaElement element= getElementAt(caret, false); if ( !(element instanceof ISourceReference)) return null; if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) { IImportDeclaration declaration= (IImportDeclaration) element; IImportContainer container= (IImportContainer) declaration.getParent(); ISourceRange srcRange= null; try { srcRange= container.getSourceRange(); } catch (JavaModelException e) { } if (srcRange != null && srcRange.getOffset() == caret) return container; } return (ISourceReference) element; }