Search in sources :

Example 31 with IFileBuffer

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

the class FileStoreFileBufferFunctions 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            fileBuffer.validateState(null, null);
            fileBuffer.resetStateValidation();
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 2);
                assertTrue(listener.buffer == fileBuffer);
                assertFalse(listener.isStateValidated);
            }
        } finally {
            fManager.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 32 with IFileBuffer

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

the class FileStoreFileBufferFunctions method test16_1.

/*
	 * Test IFileBufferListener#stateChanging for external changes
	 */
@Test
public void test16_1() 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            if (modifyUnderlyingFile()) {
                assertSame(listener.buffer, fileBuffer);
                assertEquals(1, listener.count);
            }
        } finally {
            fManager.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 33 with IFileBuffer

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

the class FileStoreFileBufferFunctions method test17_1.

/*
	 * Test IFileBufferListener#stateChanging for internal changes
	 */
@Test
public void test17_1() 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.getFileStoreTextFileBuffer(fFileStore);
        assertTrue(listener.count == 0 && listener.buffer == null);
        fManager.connectFileStore(fFileStore, null);
        try {
            fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
            fileBuffer.validateState(null, null);
            if (isStateValidationSupported()) {
                assertTrue(listener.count == 1);
                assertTrue(listener.buffer == fileBuffer);
            }
        } finally {
            fManager.disconnectFileStore(fFileStore, null);
        }
    } finally {
        fManager.removeFileBufferListener(listener);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 34 with IFileBuffer

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

the class FileBufferFunctions method testGetFileBuffers.

@Test
public void testGetFileBuffers() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        assertNotNull(buffer);
        IFileBuffer[] fileBuffers = fManager.getFileBuffers();
        assertNotNull(fileBuffers);
        assertEquals(1, fileBuffers.length);
        assertSame(buffer, fileBuffers[0]);
        fileBuffers = fManager.getFileStoreFileBuffers();
        assertNotNull(fileBuffers);
        assertEquals(0, fileBuffers.length);
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Test(org.junit.Test)

Example 35 with IFileBuffer

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

the class ResourceTextFileBufferManager method validateState.

@Override
public void validateState(final IFileBuffer[] fileBuffers, IProgressMonitor monitor, final Object computationContext) throws CoreException {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor progressMonitor) throws CoreException {
            IFileBuffer[] toValidate = findFileBuffersToValidate(fileBuffers);
            validationStateAboutToBeChanged(toValidate);
            try {
                IStatus status = validateEdit(toValidate, computationContext);
                validationStateChanged(toValidate, true, status);
            } catch (RuntimeException x) {
                validationStateChangedFailed(toValidate);
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, computeValidateStateRule(fileBuffers), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer)

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