Search in sources :

Example 41 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.

the class FileBufferDocumentTester method doTestCreate.

private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
    IFile file = (IFile) fTestProject.findMember(filePath);
    System.out.println(fTestProject.getLocation().toOSString());
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath locationPath = file.getLocation();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(locationPath, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
    IDocumentPartitioner setupPartitioner = null;
    if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
        setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    } else {
        setupPartitioner = document.getDocumentPartitioner();
    }
    assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
    bufferManager.disconnect(locationPath, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 42 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.

the class FormatActionDelegate method format.

protected void format(final IProgressMonitor monitor, IResource resource) {
    if (resource instanceof IFile) {
        final IFile file = (IFile) resource;
        // format of the file when it can
        try {
            ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
            ITextFileBuffer buffer = null;
            try {
                if (manager != null) {
                    manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
                    buffer = manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
                }
                if (buffer != null && buffer.isShared()) {
                    Display display = getDisplay();
                    display.syncExec(new Runnable() {

                        public void run() {
                            format(monitor, file);
                        }
                    });
                } else
                    format(monitor, file);
            } finally {
                if (manager != null)
                    manager.disconnect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
            }
        } catch (CoreException e) {
            String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
            fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
        } finally {
            if (monitor != null)
                monitor.done();
        }
    } else if (resource instanceof IContainer) {
        IContainer container = (IContainer) resource;
        try {
            IResource[] members = container.members();
            monitor.beginTask("", members.length);
            for (int i = 0; i < members.length; i++) {
                if (monitor != null && !monitor.isCanceled())
                    format(new SubProgressMonitor(monitor, 1), members[i]);
            }
            monitor.done();
        } catch (CoreException e) {
            String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { resource.getFullPath().toString() });
            fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
        }
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IContainer(org.eclipse.core.resources.IContainer) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) Display(org.eclipse.swt.widgets.Display)

Example 43 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.

the class JavascriptValidationStrategy method getContentType.

private String getContentType() {
    IDocument doc = getDocument();
    if (doc == null)
        return null;
    ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();
    if (textFileBufferManager != null) {
        ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(doc);
        if (textFileBuffer != null && textFileBuffer.getLocation() != null) {
            try {
                IContentType ct = textFileBuffer.getContentType();
                if (ct != null)
                    return ct.getId();
            } catch (CoreException e) {
            // Ignore;
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IContentType(org.eclipse.core.runtime.content.IContentType) IDocument(org.eclipse.jface.text.IDocument)

Example 44 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.

the class FileBufferDocumentTester method doTestCreate.

private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
    IFile file = (IFile) fTestProject.findMember(filePath);
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath fullPath = file.getFullPath();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(fullPath, LocationKind.IFILE, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(fullPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    assertTrue("wrong class of document: " + (document != null ? document.getClass() : null), expectedDocumentClass.isInstance(document));
    assertTrue("document does not implement IDocumentExtension3", document instanceof IDocumentExtension3);
    IDocumentPartitioner actualPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
    assertTrue("wrong partitioner in document: " + actualPartitioner, expectedPartioner.isInstance(actualPartitioner));
    bufferManager.disconnect(fullPath, LocationKind.IFILE, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument)

Example 45 with ITextFileBufferManager

use of org.eclipse.core.filebuffers.ITextFileBufferManager in project webtools.sourceediting by eclipse.

the class TransitionTests method testSoftRevert.

public void testSoftRevert() throws CoreException, IOException {
    // $NON-NLS-1$
    String filePath = "testfiles/xml/EmptyFile.xml";
    IFile file = (IFile) fTestProject.findMember(filePath);
    // $NON-NLS-1$
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath locationPath = file.getLocation();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(locationPath, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    // $NON-NLS-1$
    assertTrue("wrong class of document", document instanceof BasicStructuredDocument);
    // $NON-NLS-1$
    assertTrue("wrong partitioner in document.", ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING) instanceof StructuredTextPartitionerForXML);
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
    try {
        try {
            // $NON-NLS-1$
            document.replace(0, 0, "__");
            // $NON-NLS-1$
            document.replace(2, 0, "<a");
            // $NON-NLS-1$
            document.replace(4, 0, ">");
            // $NON-NLS-1$
            document.replace(5, 0, "  ");
        } catch (BadLocationException e) {
            assertNull(e);
        }
        // $NON-NLS-1$
        document.set("");
    } finally {
        model.releaseFromEdit();
        bufferManager.disconnect(locationPath, null);
    }
}
Also used : StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) IFile(org.eclipse.core.resources.IFile) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IPath(org.eclipse.core.runtime.IPath) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)86 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)65 IDocument (org.eclipse.jface.text.IDocument)53 IPath (org.eclipse.core.runtime.IPath)51 CoreException (org.eclipse.core.runtime.CoreException)36 BadLocationException (org.eclipse.jface.text.BadLocationException)26 IFile (org.eclipse.core.resources.IFile)22 Test (org.junit.Test)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 IOException (java.io.IOException)10 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)10 IResource (org.eclipse.core.resources.IResource)8 Path (org.eclipse.core.runtime.Path)8 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)7 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)6 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)6 TextEdit (org.eclipse.text.edits.TextEdit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 FileNotFoundException (java.io.FileNotFoundException)5 MalformedURLException (java.net.MalformedURLException)5