Package org.eclipse.ui.texteditor

Examples of org.eclipse.ui.texteditor.IDocumentProvider


            .getTextOperations();

        IFile file = currentActiveEditor.getFile();

        FileEditorInput input = new FileEditorInput(file);
        IDocumentProvider provider = EditorManager.getDocumentProvider(input);

        try {
            provider.connect(input);
        } catch (CoreException e) {
            log.error("Could not connect to a document provider on file '"
                + file.toString() + "':", e);
            return;
        }

        try {
            IDocument doc = provider.getDocument(input);
            if (doc == null) {
                log.error("Could not connect to a document provider on file '"
                    + file.toString() + "':", new StackTrace());
                return;
            }

            for (ITextOperation textOp : textOps) {
                try {
                    if (textOp instanceof DeleteOperation)
                        doc.replace(textOp.getPosition(),
                            textOp.getTextLength(), "");
                    if (textOp instanceof InsertOperation)
                        doc.replace(textOp.getPosition(), 0, textOp.getText());
                } catch (BadLocationException e) {
                    log.error("Invalid location for " + textOp);
                }
            }
        } finally {
            provider.disconnect(input);
        }
    }
View Full Code Here


            public void run() {

                IFile file = docPath.getFile();

                IDocument doc;
                IDocumentProvider provider = null;
                FileEditorInput input = null;
                if (!file.exists()) {
                    doc = null;
                } else {
                    input = new FileEditorInput(file);
                    provider = EditorManager.getDocumentProvider(input);
                    try {
                        provider.connect(input);
                        doc = provider.getDocument(input);
                    } catch (CoreException e) {
                        log.warn("Could not check checksum of file "
                            + docPath.toString());
                        provider = null;
                        doc = null;
                    }
                }

                try {
                    // Null means that the document does not exist locally
                    if (doc == null) {
                        if (localEditors.contains(docPath)) {
                            log.error("EditorManager is in an inconsistent state. "
                                + "It is reporting a locally open editor but no"
                                + " document could be found on disk: "
                                + docPath);
                        }
                        if (!remoteEditors.contains(docPath)) {
                            /*
                             * Since buddies do not report this document as
                             * open, they are right (and our EditorPool might be
                             * confused)
                             */
                            return;
                        }
                    }

                    // Update listener management
                    missingDocuments.remove(docPath);

                    DocumentChecksum checksum = docsChecksums.get(docPath);
                    if (checksum == null) {
                        checksum = new DocumentChecksum(docPath);
                        docsChecksums.put(docPath, checksum);
                    }

                    /*
                     * Potentially bind to null doc, which will set the Checksum
                     * to represent a missing file (existsFile() == false)
                     */
                    checksum.bind(doc);
                    checksum.update();

                    // Sent an checksum to everybody
                    ChecksumActivity checksumActivity = new ChecksumActivity(
                        sarosSession.getLocalUser(), checksum.getPath(),
                        checksum.getHash(), checksum.getLength());

                    sarosSession.activityCreated(checksumActivity);

                } finally {
                    if (provider != null) {
                        provider.disconnect(input);
                    }
                }

            }
        });
View Full Code Here

        if (!file.exists()) {
            return true;
        }

        FileEditorInput input = new FileEditorInput(file);
        IDocumentProvider provider = EditorManager.getDocumentProvider(input);

        try {
            provider.connect(input);
        } catch (CoreException e) {
            log.warn("Could not check checksum of file " + path.toString());
            return false;
        }

        try {
            IDocument doc = provider.getDocument(input);

            // if doc is still null give up
            if (doc == null) {
                log.warn("Could not check checksum of file " + path.toString());
                return false;
            }

            if ((doc.getLength() != checksum.getLength())
                || (doc.get().hashCode() != checksum.getHash())) {

                log.debug(String.format(
                    "Inconsistency detected: %s L(%d %s %d) H(%x %s %x)", path
                        .toString(), doc.getLength(),
                    doc.getLength() == checksum.getLength() ? "==" : "!=",
                    checksum.getLength(), doc.get().hashCode(), doc.get()
                        .hashCode() == checksum.getHash() ? "==" : "!=",
                    checksum.getHash()));

                return true;
            }
        } finally {
            provider.disconnect(input);
        }
        return false;
    }
View Full Code Here

        log.trace(".connect(" + file.getProjectRelativePath().toOSString()
            + ") invoked");

        if (!isConnected(file)) {
            FileEditorInput input = new FileEditorInput(file);
            IDocumentProvider documentProvider = getDocumentProvider(input);
            try {
                documentProvider.connect(input);
            } catch (CoreException e) {
                log.error("Error connecting to a document provider on file '"
                    + file.toString() + "':", e);
            }
            connectedFiles.add(file);
View Full Code Here

                + file.getFullPath().toOSString());
            return;
        }

        FileEditorInput input = new FileEditorInput(file);
        IDocumentProvider documentProvider = getDocumentProvider(input);
        documentProvider.disconnect(input);

        connectedFiles.remove(file);
    }
View Full Code Here

        /*
         * TODO Investigate if this is really needed here
         */
        {
            IEditorInput input = changedEditor.getEditorInput();
            IDocumentProvider provider = getDocumentProvider(input);
            IAnnotationModel model = provider.getAnnotationModel(input);
            contributionAnnotationManager.splitAnnotation(model, offset);
        }
    }
View Full Code Here

    protected void replaceText(SPath path, int offset, String replacedText,
        String text, User source) {

        IFile file = path.getFile();
        FileEditorInput input = new FileEditorInput(file);
        IDocumentProvider provider = getDocumentProvider(input);

        try {
            provider.connect(input);
        } catch (CoreException e) {
            log.error(
                "Could not connect document provider for file: "
                    + file.toString(), e);
            // TODO Trigger a consistency recovery
            return;
        }

        try {
            IDocument doc = provider.getDocument(input);
            if (doc == null) {
                log.error("Could not connect document provider for file: "
                    + file.toString(), new StackTrace());
                // TODO Trigger a consistency recovery
                return;
            }

            // Check if the replaced text is really there.
            if (log.isDebugEnabled()) {

                String is;
                try {
                    is = doc.get(offset, replacedText.length());
                    if (!is.equals(replacedText)) {
                        log.error("replaceText should be '"
                            + StringEscapeUtils.escapeJava(replacedText)
                            + "' is '" + StringEscapeUtils.escapeJava(is) + "'");
                    }
                } catch (BadLocationException e) {
                    // Ignore, because this is going to fail again just below
                }
            }

            // Try to replace
            try {
                doc.replace(offset, replacedText.length(), text);
            } catch (BadLocationException e) {
                log.error(String.format(
                    "Could not apply TextEdit at %d-%d of document "
                        + "with length %d.\nWas supposed to replace"
                        + " '%s' with '%s'.", offset,
                    offset + replacedText.length(), doc.getLength(),
                    replacedText, text));
                return;
            }
            lastRemoteEditTimes.put(path, System.currentTimeMillis());

            for (IEditorPart editorPart : editorPool.getEditors(path)) {

                if (editorPart instanceof ITextEditor) {
                    ITextEditor textEditor = (ITextEditor) editorPart;
                    IAnnotationModel model = textEditor.getDocumentProvider()
                        .getAnnotationModel(textEditor.getEditorInput());
                    contributionAnnotationManager.insertAnnotation(model,
                        offset, text.length(), source);
                }
            }
            IAnnotationModel model = provider.getAnnotationModel(input);
            contributionAnnotationManager.insertAnnotation(model, offset,
                text.length(), source);
        } finally {
            provider.disconnect(input);
        }
    }
View Full Code Here

        }

        editorListenerDispatch.userWithWriteAccessEditorSaved(path, true);

        FileEditorInput input = new FileEditorInput(file);
        IDocumentProvider provider = getDocumentProvider(input);

        if (!provider.canSaveDocument(input)) {
            /*
             * This happens when a file which is already saved is saved again by
             * a buddy
             */
            log.debug(".saveText File " + file.getName()
                + " does not need to be saved");
            return;
        }

        log.trace(".saveText File " + file.getName() + " will be saved");

        try {
            provider.connect(input);
        } catch (CoreException e) {
            log.error("Could not connect to a document provider on file '"
                + file.toString() + "':", e);
            return;
        }

        try {
            IDocument doc = provider.getDocument(input);

            // TODO Why do we need to connect to the annotation model here?
            IAnnotationModel model = provider.getAnnotationModel(input);
            if (model != null)
                model.connect(doc);

            log.trace("EditorManager.saveText Annotations on the IDocument "
                + "are set");

            // dirtyStateListener.enabled = false;

            /*
             * BlockingProgressMonitor monitor = new BlockingProgressMonitor();
             *
             * try { provider.saveDocument(monitor, input, doc, true);
             * log.debug("Saved document: " + path); } catch (CoreException e) {
             * log.error("Failed to save document: " + path, e); }
             *
             * // Wait for saving to be done try { if (!monitor.await(10)) {
             * log.warn("Timeout expired on saving document: " + path); } }
             * catch (InterruptedException e) {
             * log.error("Code not designed to be interruptable", e);
             * Thread.currentThread().interrupt(); }
             *
             * if (monitor.isCanceled()) {
             * log.warn("Saving was canceled by buddy: " + path); }
             */
            // dirtyStateListener.enabled = true;

            if (model != null)
                model.disconnect(doc);

            log.trace("EditorManager.saveText File " + file.getName()
                + " will be reseted");

        } finally {
            provider.disconnect(input);
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    protected void removeAllAnnotations(IEditorPart editor,
        Predicate<SarosAnnotation> predicate) {
        IEditorInput input = editor.getEditorInput();
        IDocumentProvider provider = getDocumentProvider(input);
        IAnnotationModel model = provider.getAnnotationModel(input);

        if (model == null) {
            return;
        }
View Full Code Here

            return;
        }

        ITextEditor textEditor = (ITextEditor) editorPart;

        IDocumentProvider docProvider = textEditor.getDocumentProvider();

        if (docProvider != null) {
            IEditorInput input = textEditor.getEditorInput();
            IAnnotationModel model = docProvider.getAnnotationModel(input);

            if (model == null) {
                return;
            }
            if (selection.isEmpty()) {
                setSelectionAnnotation(source, model, null, null);
                return;
            }

            if (following) {
                reveal(editorPart, selection);
            }
            /*
             * If the selection's length is 0 it will be displayed as a cursor.
             * It is moved one character to the left if the offset is at the end
             * of the line but not already at the start of the line. So the
             * cursor is not displayed in completely empty lines. :-(
             */
            int offset = selection.getOffset();
            int length = selection.getLength();
            boolean isCursor = length == 0;

            if (isCursor) {
                IDocument document = docProvider.getDocument(input);
                if (document != null && document.getLength() != 0) {
                    try {
                        IRegion lineInfo = document
                            .getLineInformationOfOffset(offset);
                        int lineLength = lineInfo.getLength();
View Full Code Here

TOP

Related Classes of org.eclipse.ui.texteditor.IDocumentProvider

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.