Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.IDocument


     *
     * @return breakpoint associated with activity in the ruler or <code>null</code>
     */
    protected IBreakpoint getBreakpoint() {
        IAnnotationModel annotationModel = fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
        IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
        if (annotationModel != null) {
            Iterator iterator = annotationModel.getAnnotationIterator();
            while (iterator.hasNext()) {
                Object object = iterator.next();
                if (object instanceof SimpleMarkerAnnotation) {
                    SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
                    IMarker marker = markerAnnotation.getMarker();
                    try {
                        if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {
                            Position position = annotationModel.getPosition(markerAnnotation);
                            int line = document.getLineOfOffset(position.getOffset());
                            if (line == fRulerInfo.getLineOfLastMouseButtonActivity()) {
                                IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
                                if (breakpoint != null) {
                                    return breakpoint;
                                }
View Full Code Here


        if (result[0].endsWith("\n"))
        {
            result[0] = result[0].substring(0, result[0].lastIndexOf("\n"));
        }

        IDocument doc = getEditor().getDocumentProvider().getDocument(getEditor().getEditorInput());
        try
        {
            // Repace the selection with the subroutine call
            doc.replace(selection.getOffset(), selection.getLength(), result[0]);

            int offset = -1;

            FindReplaceDocumentAdapter docFind = new FindReplaceDocumentAdapter(doc);

            IRegion regionEnd =
                docFind.find(selection.getOffset(), "^__END__", true, true, false, true);
            offset = (regionEnd != null) ? regionEnd.getOffset() : doc.getLength();

            String lineSep = getLineSeparator(doc.get());

            // format and insert the new subroutine code
            doc.replace(offset, 0, lineSep + SourceFormatter.format(result[1], getLog()));
        }
        catch (CoreException e)
        {
            log(e.getStatus());
        }
View Full Code Here

    //~ Methods

    protected void doRun()
    {
        IDocument doc = getEditor().getDocumentProvider().getDocument(
            getEditor().getEditorInput());

        if (doc.getLength() == 0) return;

        StringBuffer text = new StringBuffer(doc.get());
        String anchor = getAnchorString(text);

        ISourceViewer viewer = getEditor().getViewer();
        int anchorOffset = getAnchorOffset(viewer, doc);
        // insert an anchor comment at the end of the line with carret
        // we'll find it back to reposition the caret after reformatting
        text.insert(anchorOffset, anchor);

        String formattedText = runFormatter(text);

        if (formattedText == null ||
            formattedText.equals(text.toString()) ||
            formattedText.equals(anchor))
        {
            return;
        }
       
        StringBuffer newText = new StringBuffer(formattedText);
        anchorOffset = newText.indexOf(anchor);
        if (anchorOffset > 0)
        {
            // remove the anchor comment and the preceeding whitespace
            // which might have been inserted by perltidy
            int len = anchor.length() + 1;
            anchorOffset--;
            while (anchorOffset >= 0 &&
                Character.isWhitespace(newText.charAt(anchorOffset)))
            {
                anchorOffset--;
                len++;
            }
            newText.delete(anchorOffset+1, anchorOffset+len);
        }
        else
            anchorOffset = 0;
       
        doc.set(newText.toString());
        viewer.setSelectedRange(anchorOffset, 0);
        viewer.revealRange(anchorOffset, 0);
    }
View Full Code Here

     * @param completionPosition
     *        the context position in the document of the text viewer
     */
    public void complete(ITextViewer viewer, int completionPosition)
    {
        IDocument document = viewer.getDocument();

        if (!(contextType instanceof CompilationUnitContextType)) return;

        Point selection = viewer.getSelectedRange();
        ((CompilationUnitContextType) contextType).setContextParameters(
View Full Code Here

   
    private void assertOkay(PerlEditor editor) throws Exception
    {
        try
        {
            IDocument doc = editor.getViewer().getDocument();
            assertTrue(PartitionTypes.getPerlPartitioner(doc) instanceof PerlPartitioner);           
            assertTrue(editor.getViewer().getAnnotationModel() instanceof PerlSourceAnnotationModel);
        }
        finally
        {
View Full Code Here

    EditorHelper editor = new EditorHelper((ITextEditor) editorPart);
    String line;
    int lineNo = -1;
    int i = 0;
    int length = editor.lineCount();
    IDocument doc = editor.getDocument();
    try {
      while (i < length && lineNo < 0) {
        line = doc.get(doc.getLineOffset(i), doc.getLineLength(i));
        if (line.contains(text)) {
          lineNo = i;
        }
        i++;
      }
View Full Code Here

    options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
    options.put(DefaultCodeFormatterConstants.FORMATTER_JOIN_WRAPPED_LINES, DefaultCodeFormatterConstants.FALSE);

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    TextEdit format = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, text, 0, text.length(), 0, null);
    IDocument document = new Document(text);
    format.apply(document);
    return document.get();
  }
View Full Code Here

public class RSDocumentProvider extends FileDocumentProvider {

  @Override
  protected IDocument createDocument(Object element) throws CoreException {
    IDocument document = super.createDocument(element);
    if (document != null) {
      IDocumentPartitioner partitioner =
        new FastPartitioner(
          new RSPartitionScanner(),
          new String[] {
            RSPartitionScanner.COMMENT });
      partitioner.connect(document);
      document.setDocumentPartitioner(partitioner);
    }
    return document;
  }
View Full Code Here

  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = getWindow(event);
    try {
      ITextEditor editor = getEditor();
      IEditorInput editorInput = editor.getEditorInput();
            IDocument document = editor.getDocumentProvider().getDocument(editorInput);
           
            IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
            IFile file = fileEditorInput.getFile();
           
            createRunScript(window).withContents(document.get(), file, editor.getTitle());
     
      return null;
    } catch (Throwable t) {
      t.printStackTrace();
      new Alerter(window).error("Error running script: "+t.getMessage());
View Full Code Here

    final IFile file = context.mock(IFile.class);
    final IWorkbenchWindow window = context.mock(IWorkbenchWindow.class);
    final ITextEditor editor = context.mock(ITextEditor.class);
    final IFileEditorInput editorInput = context.mock(IFileEditorInput.class);
    final IDocumentProvider documentProvider = context.mock(IDocumentProvider.class);
    final IDocument document = context.mock(IDocument.class);
   
    ExecutionEvent event = new ExecutionEvent();
    final String contents = "contents";
    final String filename = "filename";
   
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.IDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.