Codota Logo
ISourceViewer
Code IndexAdd Codota to your IDE (free)

How to use
ISourceViewer
in
org.eclipse.jface.text.source

Best Java code snippets using org.eclipse.jface.text.source.ISourceViewer (Showing top 20 results out of 315)

  • Common ways to obtain ISourceViewer
private void myMethod () {
ISourceViewer i =
  • Codota IconIQuickAssistInvocationContext quickAssistContext;quickAssistContext.getSourceViewer()
  • Codota IconCompilationUnitEditor fEditor;fEditor.getViewer()
  • Codota IconJavaEditor javaEditor;javaEditor.getViewer()
  • Smart code suggestions by Codota
}
origin: org.eclipse.jdt/org.eclipse.jdt.ui

public void install() {
  ISourceViewer sourceViewer= getSourceViewer();
  if (sourceViewer == null)
    return;
  StyledText text= sourceViewer.getTextWidget();
  if (text == null || text.isDisposed())
    return;
  sourceViewer.addTextInputListener(this);
  IDocument document= sourceViewer.getDocument();
  if (document != null)
    document.addDocumentListener(this);
}
origin: org.eclipse.platform/org.eclipse.jface.text

/**
 * Retrieves the annotation model from the given source viewer.
 *
 * @param sourceViewer the source viewer
 * @return the source viewer's annotation model or <code>null</code> if none can be found
 * @since 3.0
 */
protected IAnnotationModel findAnnotationModel(ISourceViewer sourceViewer) {
  if(sourceViewer != null)
    return sourceViewer.getAnnotationModel();
  return null;
}
origin: org.eclipse.xtext/ui

@Override
public void verifyKey(VerifyEvent event) {
  if (matched && event.keyCode == 27) {
    Point range = sourceViewer.getSelectedRange();
    try {
      sourceViewer.getDocument().replace(range.x - longForm.length(), longForm.length(), shortcut);
      sourceViewer.setSelectedRange(range.x - longForm.length() + shortcut.length(), 0);
      matched = false;
    } catch (BadLocationException e) {
      handleBadLocationException(e);
    }
  }
}
origin: org.eclipse.xtext/ui

private void restorePosition() {
  if (storedPosition != null && !storedPosition.isDeleted() && viewer.getDocument() != null) {
    viewer.setSelectedRange(storedPosition.offset, storedPosition.length);
    viewer.revealRange(storedPosition.offset, storedPosition.length);
  }
  storedPosition = null;
}
origin: org.eclipse/org.eclipse.jdt.ui

public void setInformation(String content) {
  super.setInformation(content);
  IDocument doc= getViewer().getDocument();
  if (doc == null)
    return;
  // ensure that we can scroll enough
  ensureScrollable();
  String start= null;
  if (IJavaPartitions.JAVA_DOC.equals(fPartition)) {
    start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
  } else if (IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(fPartition)) {
    start= "/*" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
  }
  if (start != null) {
    try {
      doc.replace(0, 0, start);
      int startLen= start.length();
      getViewer().setDocument(doc, startLen, doc.getLength() - startLen);
    } catch (BadLocationException e) {
      // impossible
      Assert.isTrue(false);
    }
  }
  getViewer().getTextWidget().setHorizontalPixel(fHorizontalScrollPixel);
}
origin: org.eclipse/org.eclipse.ui.workbench.texteditor

/**
 * Selects and reveals the specified ranges in this text editor.
 *
 * @param selectionStart the offset of the selection
 * @param selectionLength the length of the selection
 * @param revealStart the offset of the revealed range
 * @param revealLength the length of the revealed range
 * @since 3.0
 */
protected void selectAndReveal(int selectionStart, int selectionLength, int revealStart, int revealLength) {
  if (fSourceViewer == null)
    return;
  ISelection selection= getSelectionProvider().getSelection();
  if (selection instanceof ITextSelection) {
    ITextSelection textSelection= (ITextSelection) selection;
    if (textSelection.getOffset() != 0 || textSelection.getLength() != 0)
      markInNavigationHistory();
  }
  StyledText widget= fSourceViewer.getTextWidget();
  widget.setRedraw(false);
  {
    adjustHighlightRange(revealStart, revealLength);
    fSourceViewer.revealRange(revealStart, revealLength);
    fSourceViewer.setSelectedRange(selectionStart, selectionLength);
    markInNavigationHistory();
  }
  widget.setRedraw(true);
}
origin: org.eclipse.xtext/org.eclipse.xtext.junit4

protected XtextEditor openEditor(String string) throws Exception {
  int cursor = string.indexOf('|');
  String fileExtension = getFileExtension();
  IFile file = createFile("foo/myfile" + files.size() + "." + fileExtension, string.replace("|", ""));
  files.add(file);
  XtextEditor editor = openEditor(file);
  editor.getInternalSourceViewer().setSelectedRange(cursor, 0);
  editor.getInternalSourceViewer().getTextWidget().setFocus();
  return editor;
}

origin: stackoverflow.com

 ISourceViewer sourceViewer = getSourceViewer(); // Get your SourceViewer

StyledText styledText = sourceViewer.getTextWidget();

int docOffset = 0;
if (sourceViewer instanceof ITextViewerExtension5) {
  ITextViewerExtension5 extension = (ITextViewerExtension5)sourceViewer;
  docOffset = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
} 
else {
  int offset = sourceViewer.getVisibleRegion().getOffset();
  docOffset = offset + styledText.getCaretOffset();
}

IDocument document = sourceViewer.getDocument();

int currentLine = document.getLineOfOffset(docOffset);
origin: org.eclipse.platform/org.eclipse.jface.text

/**
 * Returns the {@link StyledText} widget where the annotation must be drawn.
 *
 * @return the {@link StyledText} widget where the annotation must be drawn.
 */
public StyledText getTextWidget() {
  return fViewer.getTextWidget();
}
origin: org.apache.directory.studio/ldapbrowser.common

/**
 * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
 */
public void setDocument( IDocument document )
{
  if ( sourceViewer.getAnnotationModel() == null )
  {
    IAnnotationModel model = new AnnotationModel();
    sourceViewer.setDocument( sourceViewer.getDocument(), model );
  }
  // add annotation painter
  if ( paintManager == null && sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
  {
    AnnotationPainter ap = new AnnotationPainter( sourceViewer, null );
    ap.addAnnotationType( "DEFAULT" ); //$NON-NLS-1$
    ap.setAnnotationTypeColor( "DEFAULT", BrowserCommonActivator.getDefault().getColor( new RGB( 255, 0, 0 ) ) ); //$NON-NLS-1$
    sourceViewer.getAnnotationModel().addAnnotationModelListener( ap );
    FilterCharacterPairMatcher cpm = new FilterCharacterPairMatcher( sourceViewer, parser );
    MatchingCharacterPainter mcp = new MatchingCharacterPainter( sourceViewer, cpm );
    mcp.setColor( BrowserCommonActivator.getDefault().getColor( new RGB( 159, 159, 159 ) ) );
    paintManager = new PaintManager( sourceViewer );
    paintManager.addPainter( ap );
    paintManager.addPainter( mcp );
  }
}
origin: org.eclipse/org.eclipse.jdt.ui

  private boolean isMasked(int offset) {
    IDocument document= getSourceViewer().getDocument();
    try {
      return fEscapeCharacter == document.getChar(offset - 1);
    } catch (BadLocationException e) {
    }
    return false;
  }
}
origin: org.eclipse.jdt/org.eclipse.jdt.ui

private static final IRegion getSignedSelection(ISourceViewer sourceViewer) {
  Point viewerSelection= sourceViewer.getSelectedRange();
  StyledText text= sourceViewer.getTextWidget();
  Point selection= text.getSelectionRange();
  if (text.getCaretOffset() == selection.x) {
    viewerSelection.x= viewerSelection.x + viewerSelection.y;
    viewerSelection.y= -viewerSelection.y;
  }
  return new Region(viewerSelection.x, viewerSelection.y);
}
origin: org.eclipse/org.eclipse.ui.workbench.texteditor

  fSourceViewer.setDocument(document, model);
  fSourceViewer.setEditable(isEditable());
  fSourceViewer.showAnnotations(model != null);
  fInitialCaret= fSourceViewer.getTextWidget().getCaret();
  fSourceViewer.getTextWidget().invokeAction(ST.TOGGLE_OVERWRITE);
handleInsertModeChanged();
origin: org.eclipse.xtext/ui

/**
 * @since 2.3
 */
protected void selectAndRevealQuickfix(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations, List<ICompletionProposal> completionProposals) {
  if (completionProposals.isEmpty()) {
    return;
  }
  if (invocationContext instanceof QuickAssistInvocationContext && !((QuickAssistInvocationContext) invocationContext).isSuppressSelection()) {
    ISourceViewer sourceViewer = invocationContext.getSourceViewer();
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    Iterator<Annotation> iterator = applicableAnnotations.iterator();
    while(iterator.hasNext()){
      Position pos = annotationModel.getPosition(iterator.next());
      if (pos != null) {
        sourceViewer.setSelectedRange(pos.getOffset(), pos.getLength());
        sourceViewer.revealRange(pos.getOffset(), pos.getLength());
        break;
      }
    }
  }
}
origin: org.eclipse.xtext/ui

public void assistSessionStarted(ContentAssistEvent event) {
  Point selectedRange = viewer.getSelectedRange();
  storePosition(selectedRange.x, selectedRange.y);
}
origin: org.eclipse.platform/org.eclipse.jface.text

/**
 * Returns for the widget line number for the given document line number.
 *
 * @param line the absolute line number
 * @return the line number relative to the viewer's visible region
 * @throws BadLocationException if <code>line</code> is not valid in the viewer's document
 */
private int getWidgetLineNumber(int line) throws BadLocationException {
  if (fSourceViewer instanceof ITextViewerExtension5) {
    ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
    return extension.modelLine2WidgetLine(line);
  }
  IRegion region= fSourceViewer.getVisibleRegion();
  int firstLine= fSourceViewer.getDocument().getLineOfOffset(region.getOffset());
  return line - firstLine;
}
origin: org.eclipse.platform/org.eclipse.ui.workbench.texteditor

/**
 * Perform the next completion.
 */
private void completeNext() {
  try {
    fDocument.replace(fLastCompletion.startOffset, fLastCompletion.length, fLastCompletion.next()); //next() will already advance
  } catch (BadLocationException e) {
    // we should never get here. different from other places to notify the user.
    log(e);
    clearState();
    return;
  }
  // move the caret to the insertion point
  ISourceViewer sourceViewer= ((AbstractTextEditor) getTextEditor()).getSourceViewer();
  sourceViewer.setSelectedRange(fLastCompletion.startOffset + fLastCompletion.length, 0);
  sourceViewer.revealRange(fLastCompletion.startOffset, fLastCompletion.length);
  fExitStrategy.arm(((AbstractTextEditor) getTextEditor()).getSourceViewer());
}
origin: RepreZen/KaiZen-OpenAPI-Editor

  @Override
  public void propertyChange(PropertyChangeEvent event) {
    if (colorPreferenceKeys.contains(event.getProperty())) {
      if (getSourceViewer() instanceof SourceViewer) {
        ((SourceViewer) getSourceViewer()).unconfigure();
        initializeEditor();
        getSourceViewer().configure(sourceViewerConfiguration);
      }
    }
  }
};
origin: org.eclipse.mylyn.commons/workbench

/** Configures annotation model for spell checking. */
private void configureAsEditor(ISourceViewer viewer, Document document) {
  IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
  final SourceViewerDecorationSupport support = new SourceViewerDecorationSupport(viewer, null, annotationAccess,
      EditorsUI.getSharedTextColors());
  Iterator<?> e = new MarkerAnnotationPreferences().getAnnotationPreferences().iterator();
  while (e.hasNext()) {
    support.setAnnotationPreference((AnnotationPreference) e.next());
  }
  support.install(EditorsUI.getPreferenceStore());
  viewer.getTextWidget().addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent e) {
      support.uninstall();
    }
  });
  AnnotationModel annotationModel = new AnnotationModel();
  viewer.setDocument(document, annotationModel);
}
origin: org.eclipse.xtext/org.eclipse.xtext.junit4

protected ISourceViewer getSourceViewer(Shell shell, final IXtextDocument xtextDocument,
    XtextSourceViewerConfiguration configuration) {
  XtextSourceViewer.Factory factory = get(XtextSourceViewer.Factory.class);
  ISourceViewer sourceViewer = factory.createSourceViewer(shell, null, null, false, 0);
  sourceViewer.configure(configuration);
  sourceViewer.setDocument(xtextDocument);
  return sourceViewer;
}
org.eclipse.jface.text.sourceISourceViewer

Javadoc

In addition to the text viewer functionality a source viewer supports:
  • visual annotations based on an annotation model
  • visual range indication
  • management of text viewer add-ons
  • explicit configuration
It is assumed that range indication and visual annotations are shown inside the same presentation area. There are no assumptions about whether this area is different from the viewer's text widget.

As the visibility of visual annotations can dynamically be changed, it is assumed that the annotation presentation area can dynamically be hidden if it is different from the text widget.

In order to provide backward compatibility for clients of ISourceViewer, extension interfaces are used as a means of evolution. The following extension interfaces exist:

  • org.eclipse.jface.text.source.ISourceViewerExtension since version 2.1 introducing the concept of an annotation overview.
  • org.eclipse.jface.text.source.ISourceViewerExtension2 since version 3.0 allowing source viewers to roll back a previously performed configuration and allows access to the viewer's visual annotation model.
  • org.eclipse.jface.text.source.ISourceViewerExtension3 since version 3.2 introducing the concept of a quick assist assistant and providing access to the quick assist invocation context as well as the current annotation hover.
  • org.eclipse.jface.text.source.ISourceViewerExtension4 since version 3.4 introducing API to access a minimal set of content assistant APIs.

Clients may implement this interface and its extension interfaces or use the default implementation provided by org.eclipse.jface.text.source.SourceViewer.

Most used methods

  • getTextWidget
  • getDocument
  • getAnnotationModel
    Returns this viewer's annotation model. Use ISourceViewerExtension2#getVisualAnnotationModel()in ord
  • getSelectedRange
  • configure
    Configures the source viewer using the given configuration. Prior to 3.0 this method can only be cal
  • setSelectedRange
  • setDocument
    Sets the given document as this viewer's text model and the given annotation model as the model for
  • revealRange
  • addTextInputListener
  • getVisibleRegion
  • removeTextInputListener
  • addTextListener
  • removeTextInputListener,
  • addTextListener,
  • invalidateTextPresentation,
  • getSelectionProvider,
  • getTopIndex,
  • removeTextListener,
  • setEditable,
  • setTopIndex,
  • getTextOperationTarget,
  • addViewportListener

Popular in Java

  • Parsing JSON documents to java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • getExternalFilesDir (Context)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • PrintWriter (java.io)
    Prints formatted representations of objects to a text-output stream. This class implements all of th
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • JTextField (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now