Example usage for org.eclipse.jdt.core BufferChangedEvent BufferChangedEvent

List of usage examples for org.eclipse.jdt.core BufferChangedEvent BufferChangedEvent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core BufferChangedEvent BufferChangedEvent.

Prototype

public BufferChangedEvent(IBuffer buffer, int offset, int length, String text) 

Source Link

Document

Creates a new buffer changed event indicating that the given buffer has changed.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.Buffer.java

License:Open Source License

/**
 * Append the <code>text</code> to the actual content, the gap is moved
 * to the end of the <code>text</code>.
 *//*from  w  ww  .j  a v  a 2 s. c o m*/
public void append(char[] text) {
    if (!isReadOnly()) {
        if (text == null || text.length == 0) {
            return;
        }
        int length = getLength();
        synchronized (this.lock) {
            if (this.contents == null)
                return;
            moveAndResizeGap(length, text.length);
            System.arraycopy(text, 0, this.contents, length, text.length);
            this.gapStart += text.length;
            this.flags |= F_HAS_UNSAVED_CHANGES;
        }
        notifyChanged(new BufferChangedEvent(this, length, 0, new String(text)));
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.Buffer.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IBuffer// w  w w .  j  ava 2s  .co  m
 */
public void close() {
    BufferChangedEvent event = null;
    synchronized (this.lock) {
        if (isClosed())
            return;
        event = new BufferChangedEvent(this, 0, 0, null);
        this.contents = null;
        this.flags |= F_IS_CLOSED;
    }
    notifyChanged(event); // notify outside of synchronized block
    synchronized (this) { // ensure that no other thread is adding/removing a listener at the same time (https://bugs.eclipse.org/bugs/show_bug.cgi?id=126673)
        this.changeListeners = null;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.Buffer.java

License:Open Source License

/**
 * Replaces <code>length</code> characters starting from <code>position</code> with <code>text<code>.
 * After that operation, the gap is placed at the end of the
 * inserted <code>text</code>.
 *//*from   w  w  w  .  j a  va 2s  .  c  o m*/
public void replace(int position, int length, char[] text) {
    if (!isReadOnly()) {
        int textLength = text == null ? 0 : text.length;
        synchronized (this.lock) {
            if (this.contents == null)
                return;

            // move gap
            moveAndResizeGap(position + length, textLength - length);

            // overwrite
            int min = Math.min(textLength, length);
            if (min > 0) {
                System.arraycopy(text, 0, this.contents, position, min);
            }
            if (length > textLength) {
                // enlarge the gap
                this.gapStart -= length - textLength;
            } else if (textLength > length) {
                // shrink gap
                this.gapStart += textLength - length;
                System.arraycopy(text, 0, this.contents, position, textLength);
            }
            this.flags |= F_HAS_UNSAVED_CHANGES;
        }
        String string = null;
        if (textLength > 0) {
            string = new String(text);
        }
        notifyChanged(new BufferChangedEvent(this, position, length, string));
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.Buffer.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IBuffer/*from  ww w.j a va  2s  . com*/
 */
public void setContents(char[] newContents) {
    // allow special case for first initialization
    // after creation by buffer factory
    if (this.contents == null) {
        synchronized (this.lock) {
            this.contents = newContents;
            this.flags &= ~(F_HAS_UNSAVED_CHANGES);
        }
        return;
    }

    if (!isReadOnly()) {
        String string = null;
        if (newContents != null) {
            string = new String(newContents);
        }
        synchronized (this.lock) {
            if (this.contents == null)
                return; // ignore if buffer is closed (as per spec)
            this.contents = newContents;
            this.flags |= F_HAS_UNSAVED_CHANGES;
            this.gapStart = -1;
            this.gapEnd = -1;
        }
        BufferChangedEvent event = new BufferChangedEvent(this, 0, getLength(), string);
        notifyChanged(event);
    }
}

From source file:org.jboss.tools.vscode.java.internal.DocumentAdapter.java

License:Open Source License

@Override
public void close() {
    synchronized (lock) {
        if (fIsClosed)
            return;

        fIsClosed = true;/*from   w w  w  .j ava  2  s . co  m*/
        fDocument.removeDocumentListener(this);

        if (fTextFileBuffer != null) {
            try {
                ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
                manager.disconnect(fFile.getFullPath(), LocationKind.NORMALIZE, null);
            } catch (CoreException x) {
                // ignore
            }
            fTextFileBuffer = null;
        }

        fireBufferChanged(new BufferChangedEvent(this, 0, 0, null));
        fBufferListeners.clear();
        fDocument = null;
    }
}

From source file:org.jboss.tools.vscode.java.internal.DocumentAdapter.java

License:Open Source License

@Override
public void documentChanged(DocumentEvent event) {
    fireBufferChanged(new BufferChangedEvent(this, event.getOffset(), event.getLength(), event.getText()));
}