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);
}
}
}
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();
}
}
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;
}
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()]);
}
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);
}
Aggregations