Search in sources :

Example 1 with ResourceMapping

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

the class CopyModifications method copy.

public void copy(IPackageFragment pack, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
    add(pack, javaArgs, null);
    ResourceMapping mapping = JavaElementResourceMapping.create(pack);
    if (mapping != null) {
        add(mapping, resourceArgs, null);
    }
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) javaArgs.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    // the new name yet, so we use the current package name.
    if (!pack.hasSubpackages() && (!newPack.exists() || pack.equals(newPack))) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addCopyDelta(pack.getResource(), resourceArgs);
    } else {
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        CopyArguments arguments = new CopyArguments(resourceDestination, resourceArgs.getExecutionLog());
        IResource[] resourcesToCopy = collectResourcesOfInterest(pack);
        for (int i = 0; i < resourcesToCopy.length; i++) {
            IResource toCopy = resourcesToCopy[i];
            getResourceModifications().addCopyDelta(toCopy, arguments);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CopyArguments(org.eclipse.ltk.core.refactoring.participants.CopyArguments) JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 2 with ResourceMapping

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

the class PackageFragmentRootReorgChange method perform.

@Override
public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    pm.beginTask(getName(), 2);
    try {
        String newName = getNewResourceName();
        IPackageFragmentRoot root = getRoot();
        ResourceMapping mapping = JavaElementResourceMapping.create(root);
        final Change result = doPerformReorg(getDestinationProjectPath().append(newName), new SubProgressMonitor(pm, 1));
        markAsExecuted(root, mapping);
        return result;
    } finally {
        pm.done();
    }
}
Also used : JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) ResourceChange(org.eclipse.ltk.core.refactoring.resource.ResourceChange) Change(org.eclipse.ltk.core.refactoring.Change) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 3 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project tmdm-studio-se by Talend.

the class Utilities method internalGetResources.

private static ArrayList internalGetResources(ISelection selection, Class type) {
    ArrayList tmp = new ArrayList();
    if (selection instanceof IStructuredSelection) {
        Object[] s = ((IStructuredSelection) selection).toArray();
        for (int i = 0; i < s.length; i++) {
            IResource resource = null;
            Object o = s[i];
            if (type.isInstance(o)) {
                resource = (IResource) o;
            } else if (o instanceof ResourceMapping) {
                try {
                    ResourceTraversal[] travs = ((ResourceMapping) o).getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
                    if (travs != null) {
                        for (int k = 0; k < travs.length; k++) {
                            IResource[] resources = travs[k].getResources();
                            for (int j = 0; j < resources.length; j++) {
                                if (type.isInstance(resources[j]) && resources[j].isAccessible())
                                    tmp.add(resources[j]);
                            }
                        }
                    }
                } catch (CoreException ex) {
                    log.error(ex.getMessage(), ex);
                }
            } else if (o instanceof IAdaptable) {
                IAdaptable a = (IAdaptable) o;
                Object adapter = a.getAdapter(IResource.class);
                if (type.isInstance(adapter))
                    resource = (IResource) adapter;
            }
            if (resource != null && resource.isAccessible())
                tmp.add(resource);
        }
    }
    return tmp;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) CoreException(org.eclipse.core.runtime.CoreException) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 4 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping 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 5 with ResourceMapping

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

the class GitChangeSetModelProvider method getMappings.

@Override
public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    if (context instanceof GitSubscriberResourceMappingContext) {
        GitSubscriberResourceMappingContext gitContext = (GitSubscriberResourceMappingContext) context;
        GitSynchronizeDataSet gsds = gitContext.getSyncData();
        GitSynchronizeData data = gsds.getData(resource.getProject());
        if (data != null) {
            GitModelObject object = null;
            try {
                object = GitModelObject.createRoot(data);
            } catch (IOException e) {
                Activator.logError(e.getMessage(), e);
            }
            if (object != null) {
                ResourceMapping rm = AdapterUtils.adapt(object, ResourceMapping.class);
                return new ResourceMapping[] { rm };
            }
        }
    }
    return super.getMappings(resource, context, monitor);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IOException(java.io.IOException) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

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