Search in sources :

Example 1 with IDocumentSetupParticipant

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

the class ExtensionsRegistry method getDocumentSetupParticipants.

/**
 * Returns the set of setup participants for the given file name or extension.
 *
 * @param nameOrExtension the name or extension to be used for lookup
 * @return the sharable set of document setup participants
 */
protected List<IDocumentSetupParticipant> getDocumentSetupParticipants(String nameOrExtension) {
    Set<IConfigurationElement> set = fSetupParticipantDescriptors.get(nameOrExtension);
    if (set == null)
        return null;
    List<IDocumentSetupParticipant> participants = new ArrayList<>();
    Iterator<IConfigurationElement> e = set.iterator();
    while (e.hasNext()) {
        IConfigurationElement entry = e.next();
        IDocumentSetupParticipant participant = getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class);
        if (participant != null)
            participants.add(participant);
    }
    return participants;
}
Also used : ArrayList(java.util.ArrayList) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 2 with IDocumentSetupParticipant

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

the class ExtensionsRegistry method doGetDocumentSetupParticipants.

/**
 * Returns the set of setup participants for the given content types.
 *
 * @param contentTypes the contentTypes to be used for lookup
 * @return the sharable set of document setup participants
 */
private List<IDocumentSetupParticipant> doGetDocumentSetupParticipants(IContentType[] contentTypes) {
    Set<IConfigurationElement> resultSet = new HashSet<>();
    int i = 0;
    while (i < contentTypes.length) {
        Set<IConfigurationElement> set = fSetupParticipantDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
        if (set != null)
            resultSet.addAll(set);
    }
    List<IDocumentSetupParticipant> participants = new ArrayList<>();
    Iterator<IConfigurationElement> e = resultSet.iterator();
    while (e.hasNext()) {
        IConfigurationElement entry = e.next();
        IDocumentSetupParticipant participant = getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class);
        if (participant != null)
            participants.add(participant);
    }
    return participants.isEmpty() ? null : participants;
}
Also used : ArrayList(java.util.ArrayList) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HashSet(java.util.HashSet)

Example 3 with IDocumentSetupParticipant

use of org.eclipse.core.filebuffers.IDocumentSetupParticipant 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 4 with IDocumentSetupParticipant

use of org.eclipse.core.filebuffers.IDocumentSetupParticipant 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)4 ArrayList (java.util.ArrayList)2 IDocumentSetupParticipantExtension (org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)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 HashSet (java.util.HashSet)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1