Search in sources :

Example 1 with AdapterFactoryRegistryExtension

use of org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistryExtension in project webtools.sourceediting by eclipse.

the class EditorModelUtil method addFactoriesTo.

public static void addFactoriesTo(final IStructuredModel structuredModel) {
    if (structuredModel == null)
        return;
    AdapterFactoryRegistry adapterRegistry = SSEUIPlugin.getDefault().getAdapterFactoryRegistry();
    String contentTypeId = structuredModel.getContentTypeIdentifier();
    Iterator adapterFactoryProviders = null;
    if (adapterRegistry instanceof AdapterFactoryRegistryExtension) {
        adapterFactoryProviders = ((AdapterFactoryRegistryExtension) adapterRegistry).getAdapterFactories(contentTypeId);
    } else {
        adapterFactoryProviders = adapterRegistry.getAdapterFactories();
    }
    FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry();
    // $NON-NLS-1$
    Assert.isNotNull(factoryRegistry, SSEUIMessages.EditorModelUtil_0);
    // Add all those appropriate for this particular type of content
    while (adapterFactoryProviders.hasNext()) {
        try {
            final AdapterFactoryProvider provider = (AdapterFactoryProvider) adapterFactoryProviders.next();
            /*
				 * ContentType might have already been checked above, this
				 * check is here for backwards compatability for those that
				 * don't specify a content type
				 */
            if (provider.isFor(structuredModel.getModelHandler())) {
                SafeRunner.run(new // $NON-NLS-1$
                SafeRunnable(// $NON-NLS-1$
                SSEUIMessages.EditorModelUtil_1) {

                    public void run() {
                        provider.addAdapterFactories(structuredModel);
                    }
                });
            }
        } catch (Exception e) {
            Logger.logException(e);
        }
    }
}
Also used : AdapterFactoryProvider(org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryProvider) Iterator(java.util.Iterator) AdapterFactoryRegistry(org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry) FactoryRegistry(org.eclipse.wst.sse.core.internal.model.FactoryRegistry) AdapterFactoryRegistryExtension(org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistryExtension) AdapterFactoryRegistry(org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry)

Aggregations

Iterator (java.util.Iterator)1 FactoryRegistry (org.eclipse.wst.sse.core.internal.model.FactoryRegistry)1 AdapterFactoryProvider (org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryProvider)1 AdapterFactoryRegistry (org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistry)1 AdapterFactoryRegistryExtension (org.eclipse.wst.sse.ui.internal.provisional.registry.AdapterFactoryRegistryExtension)1