Search in sources :

Example 21 with IFileBuffer

use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.

the class GenericFileBufferOperationRunner method computeCommitRule.

protected ISchedulingRule computeCommitRule(IFileBuffer[] fileBuffers) {
    ArrayList<ISchedulingRule> list = new ArrayList<>();
    for (IFileBuffer fileBuffer : fileBuffers) {
        ISchedulingRule rule = fileBuffer.computeCommitRule();
        if (rule != null)
            list.add(rule);
    }
    ISchedulingRule[] rules = new ISchedulingRule[list.size()];
    list.toArray(rules);
    return new MultiRule(rules);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ArrayList(java.util.ArrayList) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 22 with IFileBuffer

use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method test13_3.

/*
	 * Test IFileBufferListener#stateValidationChanged
	 */
@Test
public void test13_3() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isStateValidated;

        @Override
        public void stateValidationChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isStateValidated = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            fileBuffer.validateState(null, null);
            fileBuffer.resetStateValidation();
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 2);
                assertTrue(listener.buffer == fileBuffer);
                assertFalse(listener.isStateValidated);
            }
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 23 with IFileBuffer

use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method test13_1.

/*
	 * Test IFileBufferListener#stateValidationChanged
	 */
@Test
public void test13_1() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isStateValidated;

        @Override
        public void stateValidationChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isStateValidated = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            fileBuffer.validateState(null, null);
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 1);
                assertTrue(listener.buffer == fileBuffer);
                assertTrue(listener.isStateValidated);
            }
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 24 with IFileBuffer

use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method test11_1.

/*
	 * Test IFileBufferListener#dirtyStateChanged
	 */
@Test
public void test11_1() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        public boolean isDirty;

        @Override
        public void dirtyStateChanged(IFileBuffer buf, boolean state) {
            ++count;
            this.buffer = buf;
            this.isDirty = state;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            IDocument document = fileBuffer.getDocument();
            document.replace(0, 0, "prefix");
            assertTrue(listener.count == 1);
            assertTrue(listener.buffer == fileBuffer);
            assertTrue(listener.isDirty);
            fileBuffer.commit(null, true);
            assertTrue(listener.count == 2);
            assertTrue(listener.buffer == fileBuffer);
            assertFalse(listener.isDirty);
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 25 with IFileBuffer

use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method test17_3.

/*
	 * Test IFileBufferListener#stateChanging for internal changes
	 */
@Test
public void test17_3() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        @Override
        public void stateChanging(IFileBuffer buf) {
            ++count;
            this.buffer = buf;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connect(fPath, LocationKind.NORMALIZE, null);
        try {
            fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
            IDocument document = fileBuffer.getDocument();
            document.replace(0, 0, "prefix");
            fileBuffer.commit(null, true);
            assertTrue(listener.count == 1);
            assertTrue(listener.buffer == fileBuffer);
        } finally {
            fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)47 Test (org.junit.Test)38 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)37 IDocument (org.eclipse.jface.text.IDocument)10 ArrayList (java.util.ArrayList)3 IStateValidationSupport (org.eclipse.core.filebuffers.IStateValidationSupport)3 PrintStream (java.io.PrintStream)2 PrintWriter (java.io.PrintWriter)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1