Search in sources :

Example 1 with IModelProviderDescriptor

use of org.eclipse.core.resources.mapping.IModelProviderDescriptor in project egit by eclipse.

the class ResourceUtil method getResourceMappings.

/**
 * This will query all model providers for those that are enabled on the
 * given resource and list all mappings available for that resource.
 *
 * @param resource
 *            The resource for which we need the associated resource
 *            mappings.
 * @param context
 *            Context from which remote content could be retrieved.
 * @return All mappings available for that file.
 */
public static ResourceMapping[] getResourceMappings(@NonNull IResource resource, ResourceMappingContext context) {
    final IModelProviderDescriptor[] modelDescriptors = ModelProvider.getModelProviderDescriptors();
    final Set<ResourceMapping> mappings = new LinkedHashSet<ResourceMapping>();
    for (IModelProviderDescriptor candidate : modelDescriptors) {
        try {
            final IResource[] resources = candidate.getMatchingResources(new IResource[] { resource });
            if (resources.length > 0) {
                // get mappings from model provider if there are matching resources
                final ModelProvider model = candidate.getModelProvider();
                IgnoreInGitSynchronizations adapter = model.getAdapter(IgnoreInGitSynchronizations.class);
                if (adapter != null) {
                    continue;
                }
                final ResourceMapping[] modelMappings = model.getMappings(resource, context, new NullProgressMonitor());
                for (ResourceMapping mapping : modelMappings) mappings.add(mapping);
            }
        } catch (CoreException e) {
            Activator.logError(e.getMessage(), e);
        }
    }
    return mappings.toArray(new ResourceMapping[mappings.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor) IgnoreInGitSynchronizations(org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations) IResource(org.eclipse.core.resources.IResource)

Example 2 with IModelProviderDescriptor

use of org.eclipse.core.resources.mapping.IModelProviderDescriptor in project polymap4-core by Polymap4.

the class ModelProviderManager method lazyInitialize.

protected void lazyInitialize() {
    if (descriptors != null)
        return;
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_MODEL_PROVIDERS);
    IExtension[] extensions = point.getExtensions();
    descriptors = new HashMap(extensions.length * 2 + 1);
    for (int i = 0, imax = extensions.length; i < imax; i++) {
        IModelProviderDescriptor desc = null;
        try {
            desc = new ModelProviderDescriptor(extensions[i]);
        } catch (CoreException e) {
            Policy.log(e);
        }
        if (desc != null)
            descriptors.put(desc.getId(), desc);
    }
    // do cycle detection now so it only has to be done once
    // cycle detection on a graph subset is a pain
    detectCycles();
}
Also used : IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor) HashMap(java.util.HashMap) IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor)

Example 3 with IModelProviderDescriptor

use of org.eclipse.core.resources.mapping.IModelProviderDescriptor in project che by eclipse.

the class ResourceChangeValidator method getProviders.

private ModelProvider[] getProviders(IResource[] resources) {
    IModelProviderDescriptor[] descriptors = ModelProvider.getModelProviderDescriptors();
    List<ModelProvider> result = new ArrayList<ModelProvider>();
    for (int i = 0; i < descriptors.length; i++) {
        IModelProviderDescriptor descriptor = descriptors[i];
        try {
            IResource[] matchingResources = descriptor.getMatchingResources(resources);
            if (matchingResources.length > 0) {
                result.add(descriptor.getModelProvider());
            }
        } catch (CoreException e) {
            Policy.log(e.getStatus().getSeverity(), NLS.bind("Could not instantiate provider {0}", descriptor.getId()), //$NON-NLS-1$
            e);
        }
    }
    return result.toArray(new ModelProvider[result.size()]);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) ArrayList(java.util.ArrayList) IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor) IResource(org.eclipse.core.resources.IResource)

Aggregations

IModelProviderDescriptor (org.eclipse.core.resources.mapping.IModelProviderDescriptor)3 IResource (org.eclipse.core.resources.IResource)2 ModelProvider (org.eclipse.core.resources.mapping.ModelProvider)2 CoreException (org.eclipse.core.runtime.CoreException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IgnoreInGitSynchronizations (org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations)1