Search in sources :

Example 26 with ResourceMapping

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

the class RepositoryActionHandler method extractProjectsFromMappings.

private Set<IProject> extractProjectsFromMappings(IStructuredSelection selection) {
    Set<IProject> ret = new LinkedHashSet<>();
    for (ResourceMapping mapping : getSelectedAdaptables(selection, ResourceMapping.class)) {
        IProject[] mappedProjects = mapping.getProjects();
        if (mappedProjects != null && mappedProjects.length != 0) {
            // Some mappings (WorkingSetResourceMapping) return the projects
            // in unpredictable order. Sort them like the navigator to
            // correspond to the order the user usually sees.
            List<IProject> projects = new ArrayList<>(Arrays.asList(mappedProjects));
            Collections.sort(projects, CommonUtils.RESOURCE_NAME_COMPARATOR);
            ret.addAll(projects);
        }
    }
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 27 with ResourceMapping

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

the class SelectionUtils method getSelectionContents.

/**
 * Determines a set of either {@link Repository}, {@link IResource}s or
 * {@link IPath}s from a selection. For selection contents that adapt to
 * {@link Repository}, {@link IResource} or {@link ResourceMapping}, the
 * containing {@link Repository}s or {@link IResource}s are included in the
 * result set; otherwise for selection contents that adapt to {@link IPath}
 * these paths are included.
 *
 * @param selection
 *            to process
 * @return the set of {@link Repository}, {@link IResource} and
 *         {@link IPath} objects from the selection; not containing
 *         {@code null} values
 */
@NonNull
private static Set<Object> getSelectionContents(@NonNull IStructuredSelection selection) {
    Set<Object> result = new HashSet<>();
    for (Object o : selection.toList()) {
        Repository r = AdapterUtils.adapt(o, Repository.class);
        if (r != null) {
            result.add(r);
            continue;
        }
        IResource resource = AdapterUtils.adaptToAnyResource(o);
        if (resource != null) {
            result.add(resource);
            continue;
        }
        ResourceMapping mapping = AdapterUtils.adapt(o, ResourceMapping.class);
        if (mapping != null) {
            result.addAll(extractResourcesFromMapping(mapping));
        } else {
            IPath location = AdapterUtils.adapt(o, IPath.class);
            if (location != null) {
                result.add(location);
            }
        }
    }
    return result;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) NonNull(org.eclipse.jgit.annotations.NonNull)

Example 28 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project dbeaver by serge-rider.

the class GITAbstractHandler method extractProjectsFromMappings.

private static Set<IProject> extractProjectsFromMappings(IStructuredSelection selection) {
    Set<IProject> ret = new LinkedHashSet<>();
    for (ResourceMapping mapping : getSelectedAdaptables(selection, ResourceMapping.class)) {
        IProject[] mappedProjects = mapping.getProjects();
        if (mappedProjects != null && mappedProjects.length != 0) {
            // Some mappings (WorkingSetResourceMapping) return the projects
            // in unpredictable order. Sort them like the navigator to
            // correspond to the order the user usually sees.
            List<IProject> projects = new ArrayList<>(Arrays.asList(mappedProjects));
            projects.sort(CommonUtils.RESOURCE_NAME_COMPARATOR);
            ret.addAll(projects);
        }
    }
    return ret;
}
Also used : ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IProject(org.eclipse.core.resources.IProject)

Aggregations

ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)28 IResource (org.eclipse.core.resources.IResource)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 JavaElementResourceMapping (org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping)7 CoreException (org.eclipse.core.runtime.CoreException)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)5 IFile (org.eclipse.core.resources.IFile)4 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 Change (org.eclipse.ltk.core.refactoring.Change)4 File (java.io.File)3 IProject (org.eclipse.core.resources.IProject)3 ResourceMappingContext (org.eclipse.core.resources.mapping.ResourceMappingContext)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3 ResourceChange (org.eclipse.ltk.core.refactoring.resource.ResourceChange)3