use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class SelectionUtilsTest method getSelectedResourcesShouldUseAllTraversals.
@Test
public void getSelectedResourcesShouldUseAllTraversals() throws Exception {
IResource resource1 = mock(IResource.class);
IResource resource2 = mock(IResource.class);
ResourceTraversal traversal1 = new ResourceTraversal(new IResource[] { resource1 }, 1, 0);
ResourceTraversal traversal2 = new ResourceTraversal(new IResource[] { resource2 }, 1, 0);
ResourceMapping mapping = mock(ResourceMapping.class);
when(mapping.getTraversals(null, null)).thenReturn(new ResourceTraversal[] { traversal1, traversal2 });
StructuredSelection selection = new StructuredSelection(mapping);
IResource[] result = SelectionUtils.getSelectedResources(selection);
assertEquals(2, result.length);
assertEquals(resource1, result[0]);
assertEquals(resource2, result[1]);
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class LabelEventJob method getResource.
// -------- Helper methods --------
private static IResource getResource(Object actElement) {
Object element = actElement;
if (element instanceof ResourceMapping) {
element = ((ResourceMapping) element).getModelObject();
}
IResource resource = null;
if (element instanceof IResource) {
resource = (IResource) element;
} else if (element instanceof IAdaptable) {
final IAdaptable adaptable = (IAdaptable) element;
resource = AdapterUtils.adapt(adaptable, IResource.class);
if (resource == null) {
final IContributorResourceAdapter adapter = AdapterUtils.adapt(adaptable, IContributorResourceAdapter.class);
if (adapter != null)
resource = adapter.getAdaptedResource(adaptable);
}
}
return resource;
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.
the class SaveFilter method isDescendantOfRoots.
/**
* Return whether the given saveable contains any resources that
* are descendants of the root resources.
* @param saveable the saveable
* @return whether the given saveable contains any resources that
* are descendants of the root resources
*/
private boolean isDescendantOfRoots(Saveable saveable) {
// First, try and adapt the saveable to a resource mapping.
ResourceMapping mapping = ResourceUtil.getResourceMapping(saveable);
if (mapping != null) {
try {
ResourceTraversal[] traversals = mapping.getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
for (int i = 0; i < traversals.length; i++) {
ResourceTraversal traversal = traversals[i];
IResource[] resources = traversal.getResources();
for (int j = 0; j < resources.length; j++) {
IResource resource = resources[j];
if (isDescendantOfRoots(resource)) {
return true;
}
}
}
} catch (CoreException e) {
Activator.logError(NLS.bind("An internal error occurred while determining the resources for {0}", saveable.getName()), // $NON-NLS-1$
e);
}
} else {
// If there is no mapping, try to adapt to a resource or file directly
IFile file = ResourceUtil.getFile(saveable);
if (file != null) {
return isDescendantOfRoots(file);
}
}
return false;
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project che by eclipse.
the class CompilationUnitReorgChange method perform.
@Override
public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
pm.beginTask(getName(), 1);
try {
ICompilationUnit unit = getCu();
ResourceMapping mapping = JavaElementResourceMapping.create(unit);
Change result = doPerformReorg(new SubProgressMonitor(pm, 1));
markAsExecuted(unit, mapping);
return result;
} finally {
pm.done();
}
}
use of org.eclipse.core.resources.mapping.ResourceMapping in project che by eclipse.
the class PackageReorgChange method perform.
@Override
public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
pm.beginTask(getName(), 1);
try {
IPackageFragment pack = getPackage();
ResourceMapping mapping = JavaElementResourceMapping.create(pack);
final Change result = doPerformReorg(pm);
markAsExecuted(pack, mapping);
return result;
} finally {
pm.done();
}
}
Aggregations