Search in sources :

Example 36 with IFileBuffer

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

the class ResourceTextFileBufferManager method computeValidateStateRule.

private ISchedulingRule computeValidateStateRule(IFileBuffer[] fileBuffers) {
    ArrayList<IResource> list = new ArrayList<>();
    for (IFileBuffer fileBuffer : fileBuffers) {
        IResource resource = getWorkspaceFile(fileBuffer);
        if (resource != null)
            list.add(resource);
    }
    IResource[] resources = new IResource[list.size()];
    list.toArray(resources);
    IResourceRuleFactory factory = ResourcesPlugin.getWorkspace().getRuleFactory();
    return factory.validateEditRule(resources);
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ArrayList(java.util.ArrayList) IResourceRuleFactory(org.eclipse.core.resources.IResourceRuleFactory) IResource(org.eclipse.core.resources.IResource)

Example 37 with IFileBuffer

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

the class ResourceTextFileBufferManager method validateEdit.

private IStatus validateEdit(IFileBuffer[] fileBuffers, Object computationContext) {
    ArrayList<IFile> list = new ArrayList<>();
    for (IFileBuffer fileBuffer : fileBuffers) {
        IFile file = getWorkspaceFile(fileBuffer);
        if (file != null)
            list.add(file);
    }
    IFile[] files = new IFile[list.size()];
    list.toArray(files);
    return ResourcesPlugin.getWorkspace().validateEdit(files, computationContext);
}
Also used : IFile(org.eclipse.core.resources.IFile) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ArrayList(java.util.ArrayList)

Example 38 with IFileBuffer

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

the class ResourceTextFileBufferManager method validationStateChanged.

private void validationStateChanged(IFileBuffer[] fileBuffers, boolean validationState, IStatus status) {
    for (IFileBuffer fileBuffer : fileBuffers) {
        if (fileBuffer instanceof IStateValidationSupport) {
            IStateValidationSupport support = (IStateValidationSupport) fileBuffer;
            support.validationStateChanged(validationState, status);
        }
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) IStateValidationSupport(org.eclipse.core.filebuffers.IStateValidationSupport)

Example 39 with IFileBuffer

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

the class FileStoreFileBufferFunctions method test16_2.

/*
	 * Test IFileBufferListener#stateChanging for external changes
	 */
@Test
public void test16_2() 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 (deleteUnderlyingFile()) {
                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 40 with IFileBuffer

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

the class FileStoreFileBufferFunctions method test10.

/*
	 * Test IFileBufferListener#bufferCreated and IFileBufferListener#bufferDisposed
	 */
@Test
public void test10() throws Exception {
    class Listener extends FileBufferListener {

        public IFileBuffer buffer;

        public int count;

        @Override
        public void bufferCreated(IFileBuffer buf) {
            ++count;
            this.buffer = buf;
        }

        @Override
        public void bufferDisposed(IFileBuffer buf) {
            --count;
            this.buffer = buf;
        }
    }
    Listener listener = new Listener();
    fManager.addFileBufferListener(listener);
    try {
        fManager.connectFileStore(fFileStore, null);
        assertTrue(listener.count == 1);
        assertNotNull(listener.buffer);
        IFileBuffer fileBuffer = fManager.getFileStoreFileBuffer(fFileStore);
        assertTrue(listener.buffer == fileBuffer);
        fManager.disconnectFileStore(fFileStore, null);
        assertTrue(listener.count == 0);
        assertTrue(listener.buffer == fileBuffer);
    } finally {
        try {
            fManager.disconnectFileStore(fFileStore, null);
        } finally {
            fManager.removeFileBufferListener(listener);
        }
    }
}
Also used : IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) 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