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;
}
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;
}
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;
}
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;
}
Aggregations