Search in sources :

Example 1 with IDocumentSetupParticipantExtension

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

the class ResourceTextFileBufferManager method createEmptyDocument.

public IDocument createEmptyDocument(final IFile file) {
    IDocument documentFromFactory = createEmptyDocumentFromFactory(file);
    final IDocument document;
    if (documentFromFactory != null)
        document = documentFromFactory;
    else
        document = new SynchronizableDocument();
    // Set the initial line delimiter
    if (document instanceof IDocumentExtension4) {
        String initalLineDelimiter = getLineDelimiterPreference(file);
        if (initalLineDelimiter != null)
            ((IDocumentExtension4) document).setInitialLineDelimiter(initalLineDelimiter);
    }
    final IDocumentSetupParticipant[] participants = ((ResourceExtensionRegistry) fRegistry).getDocumentSetupParticipants(file);
    if (participants != null) {
        for (final IDocumentSetupParticipant participant : participants) {
            ISafeRunnable runnable = new ISafeRunnable() {

                @Override
                public void run() throws Exception {
                    if (participant instanceof IDocumentSetupParticipantExtension)
                        ((IDocumentSetupParticipantExtension) participant).setup(document, file.getFullPath(), LocationKind.IFILE);
                    else
                        participant.setup(document);
                    if (document.getDocumentPartitioner() != null) {
                        String message = NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
                        IStatus status = new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
                        FileBuffersPlugin.getDefault().getLog().log(status);
                    }
                }

                @Override
                public void handleException(Throwable t) {
                    IStatus status = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.TextFileBufferManager_error_documentSetupFailed, t);
                    FileBuffersPlugin.getDefault().getLog().log(status);
                }
            };
            SafeRunner.run(runnable);
        }
    }
    return document;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IDocumentSetupParticipantExtension(org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IDocumentSetupParticipantExtension

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

the class TextFileBufferManager method createEmptyDocument.

@Override
public IDocument createEmptyDocument(final IPath location, final LocationKind locationKind) {
    IDocument documentFromFactory = createDocumentFromFactory(location, locationKind);
    final IDocument document;
    if (documentFromFactory != null)
        document = documentFromFactory;
    else
        document = new SynchronizableDocument();
    if (location == null)
        return document;
    // Set the initial line delimiter
    if (document instanceof IDocumentExtension4) {
        String initalLineDelimiter = getLineDelimiterPreference(location, locationKind);
        if (initalLineDelimiter != null)
            ((IDocumentExtension4) document).setInitialLineDelimiter(initalLineDelimiter);
    }
    final IDocumentSetupParticipant[] participants = fRegistry.getDocumentSetupParticipants(location, locationKind);
    if (participants != null) {
        for (final IDocumentSetupParticipant participant : participants) {
            ISafeRunnable runnable = new ISafeRunnable() {

                @Override
                public void run() throws Exception {
                    if (participant instanceof IDocumentSetupParticipantExtension)
                        ((IDocumentSetupParticipantExtension) participant).setup(document, location, locationKind);
                    else
                        participant.setup(document);
                    if (document.getDocumentPartitioner() != null) {
                        String message = NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
                        IStatus status = new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
                        FileBuffersPlugin.getDefault().getLog().log(status);
                    }
                }

                @Override
                public void handleException(Throwable t) {
                    IStatus status = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.TextFileBufferManager_error_documentSetupFailed, t);
                    FileBuffersPlugin.getDefault().getLog().log(status);
                }
            };
            SafeRunner.run(runnable);
        }
    }
    return document;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IDocumentSetupParticipantExtension(org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDocumentSetupParticipant (org.eclipse.core.filebuffers.IDocumentSetupParticipant)2 IDocumentSetupParticipantExtension (org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension)2 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IDocument (org.eclipse.jface.text.IDocument)2 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)2