Java Code Examples for org.eclipse.core.resources.mapping.ResourceMapping

The following examples show how to use org.eclipse.core.resources.mapping.ResourceMapping. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public static ResourceMapping create(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.TYPE:
			return create((IType)element);
		case IJavaElement.COMPILATION_UNIT:
			return create((ICompilationUnit)element);
		case IJavaElement.CLASS_FILE:
			return create((IClassFile)element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return create((IPackageFragment)element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return create((IPackageFragmentRoot)element);
		case IJavaElement.JAVA_PROJECT:
			return create((IJavaProject)element);
		case IJavaElement.JAVA_MODEL:
			return create((IJavaModel)element);
		default:
			return null;
	}

}
 
Example 2
Source Project: xds-ide   Source File: XdsVirtualContainer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public synchronized Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
	Object adapted = XdsElementCommons.adaptToResource(new IResourceAccess() {
		@Override
		public IResource getResource() throws CoreException {
			return resource;
		}
	}, adapter);
	if (adapted != null){
		return adapted;
	}
	
	if (ResourceMapping.class.equals(adapter)) {
		return XdsElementUtils.createResourceMappingFrom(children, this);
	}
	else if (File.class.equals(adapter)) {
		return new File(getPath()); // TODO : convert path to java.io.File
	}
	
	return null;
}
 
Example 3
Source Project: APICloud-Studio   Source File: TeamAction.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the selected resources.
 * 
 * @return the selected resources
 */
protected IResource[] getSelectedResources() {
	ArrayList resourceArray = new ArrayList();
	IResource[] resources = (IResource[])getSelectedResources(IResource.class);
	for (int i = 0; i < resources.length; i++) resourceArray.add(resources[i]);
	ResourceMapping[] resourceMappings = (ResourceMapping[])getSelectedAdaptables(selection, ResourceMapping.class);
	for (int i = 0; i < resourceMappings.length; i++) {
		ResourceMapping resourceMapping = (ResourceMapping)resourceMappings[i];
		try {
			ResourceTraversal[] traversals = resourceMapping.getTraversals(null, null);
			for (int j = 0; j < traversals.length; j++) {
				IResource[] traversalResources = traversals[j].getResources();
				for (int k = 0; k < traversalResources.length; k++) {
					if (!resourceArray.contains(traversalResources[k]))
						resourceArray.add(traversalResources[k]);
				}
			}
		} catch (CoreException e) {
			SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
		}
	}		
	IResource[] selectedResources = new IResource[resourceArray.size()];
	resourceArray.toArray(selectedResources);
	return selectedResources;
}
 
Example 4
public static ResourceMapping create(IJavaElement element) {
	switch (element.getElementType()) {
		case IJavaElement.TYPE:
			return create((IType)element);
		case IJavaElement.COMPILATION_UNIT:
			return create((ICompilationUnit)element);
		case IJavaElement.CLASS_FILE:
			return create((IClassFile)element);
		case IJavaElement.PACKAGE_FRAGMENT:
			return create((IPackageFragment)element);
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return create((IPackageFragmentRoot)element);
		case IJavaElement.JAVA_PROJECT:
			return create((IJavaProject)element);
		case IJavaElement.JAVA_MODEL:
			return create((IJavaModel)element);
		default:
			return null;
	}

}
 
Example 5
/**
 * {@inheritDoc}
 */
public Object getAdapter(final Object adaptable, final Class adapter) {
	if (adaptable instanceof JavaModelProvider) {
		if (adapter == IResourceMappingMerger.class)
			return new JavaModelMerger((ModelProvider) adaptable);
		else if (adapter == ISynchronizationCompareAdapter.class)
			return new JavaSynchronizationCompareAdapter();
	} else if (adaptable instanceof RefactoringHistory) {
		if (adapter == ResourceMapping.class)
			return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable);
		else if (adapter == IResource.class)
			return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable).getResource();
	} else if (adaptable instanceof RefactoringDescriptorProxy) {
		if (adapter == ResourceMapping.class)
			return new JavaRefactoringDescriptorResourceMapping((RefactoringDescriptorProxy) adaptable);
	}
	return null;
}
 
Example 6
Source Project: n4js   Source File: WorkingSet.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
default <T> T getAdapter(final Class<T> adapter) {

	if (IWorkingSet.class == adapter || ResourceMapping.class == adapter) {
		return (T) new WorkingSetAdapter(this);
	}

	return Platform.getAdapterManager().getAdapter(this, adapter);
}
 
Example 7
@Override
public boolean contains(ResourceMapping mapping) {
	if (mapping instanceof JavaElementResourceMapping) {
		JavaElementResourceMapping javaMapping = (JavaElementResourceMapping) mapping;
		IJavaElement element = getJavaElement();
		IJavaElement other = javaMapping.getJavaElement();
		if (other != null && element != null) {
			return element.getPath().isPrefixOf(other.getPath());
		}
	}
	return false;
}
 
Example 8
public static ResourceMapping create(final IPackageFragment pack) {
	// test if in an archive
	IPackageFragmentRoot root= (IPackageFragmentRoot)pack.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	if (!root.isArchive() && !root.isExternal()) {
		return new PackageFragmentResourceMapping(pack);
	}
	return null;
}
 
Example 9
public static ResourceMapping create(IClassFile classFile) {
	// test if in a archive
	IPackageFragmentRoot root= (IPackageFragmentRoot)classFile.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
	if (!root.isArchive() && !root.isExternal()) {
		return new ClassFileResourceMapping(classFile);
	}
	return null;
}
 
Example 10
public static ResourceMapping create(IType type) {
	// top level types behave like the CU
	IJavaElement parent= type.getParent();
	if (parent instanceof ICompilationUnit) {
		return create((ICompilationUnit)parent);
	}
	return null;
}
 
Example 11
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) {
	ReorgExecutionLog log= getAdapter(ReorgExecutionLog.class);
	if (log != null) {
		log.markAsProcessed(unit);
		log.markAsProcessed(mapping);
	}
}
 
Example 12
@Override
public Change perform(IProgressMonitor monitor) throws CoreException {
	ResourceMapping mapping= JavaElementResourceMapping.create(fOldCu);
	final Change result= super.perform(monitor);
	markAsExecuted(fOldCu, mapping);
	return result;
}
 
Example 13
Source Project: eclipse.jdt.ls   Source File: CopyModifications.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void copy(IPackageFragmentRoot sourceFolder, CopyArguments javaArgs, CopyArguments resourceArgs) {
	add(sourceFolder, javaArgs, null);
	ResourceMapping mapping= JavaElementResourceMapping.create(sourceFolder);
	if (mapping != null) {
		add(mapping, resourceArgs, null);
	}
	IResource sourceResource= sourceFolder.getResource();
	if (sourceResource != null) {
		getResourceModifications().addCopyDelta(sourceResource, resourceArgs);
		IFile classpath= getClasspathFile((IResource) resourceArgs.getDestination());
		if (classpath != null) {
			getResourceModifications().addChanged(classpath);
		}
	}
}
 
Example 14
Source Project: eclipse.jdt.ls   Source File: CopyModifications.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void copy(ICompilationUnit unit, CopyArguments javaArgs, CopyArguments resourceArgs) {
	add(unit, javaArgs, null);
	ResourceMapping mapping= JavaElementResourceMapping.create(unit);
	if (mapping != null) {
		add(mapping, resourceArgs, null);
	}
	if (unit.getResource() != null) {
		getResourceModifications().addCopyDelta(unit.getResource(), resourceArgs);
	}
}
 
Example 15
@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();
	}
}
 
Example 16
private void markAsExecuted(IPackageFragmentRoot root, ResourceMapping mapping) {
	ReorgExecutionLog log= getAdapter(ReorgExecutionLog.class);
	if (log != null) {
		log.markAsProcessed(root);
		log.markAsProcessed(mapping);
	}
}
 
Example 17
@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();
	}
}
 
Example 18
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) {
	ReorgExecutionLog log= getAdapter(ReorgExecutionLog.class);
	if (log != null) {
		log.markAsProcessed(unit);
		log.markAsProcessed(mapping);
	}
}
 
Example 19
Source Project: eclipse.jdt.ls   Source File: PackageReorgChange.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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();
	}
}
 
Example 20
Source Project: eclipse.jdt.ls   Source File: PackageReorgChange.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void markAsExecuted(IPackageFragment pack, ResourceMapping mapping) {
	ReorgExecutionLog log= getAdapter(ReorgExecutionLog.class);
	if (log != null) {
		log.markAsProcessed(pack);
		log.markAsProcessed(mapping);
	}
}
 
Example 21
Source Project: xds-ide   Source File: ResourceUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static IResource[] getResourcesFrom(ResourceMapping mapping) {
   	List<IResource> resources = new ArrayList<IResource>();
	try {
		ResourceTraversal[] traversals = mapping.getTraversals(null, null);
		for (ResourceTraversal traversal : traversals) {
			resources.addAll(Arrays.asList(traversal.getResources()));
		}
	} catch (CoreException e) {
		LogHelper.logError(e);
	}
	return resources.toArray(new IResource[0]);
}
 
Example 22
Source Project: xds-ide   Source File: ResourceProblemDecorator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public ResourcesProblemSource(ResourceMapping mapping, IResource resPrj) {
	this(ResourceUtils.getResourcesFrom(mapping));
	if (resPrj != null) {
	    // add resPrj to array - it may have its own marker 
	    IResource[] rr = new IResource[resources.length + 1];
	    rr[0] = resPrj;
	    System.arraycopy(resources, 0, rr, 1, resources.length);
	    resources = rr;
	}
}
 
Example 23
Source Project: xds-ide   Source File: XdsProject.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public synchronized Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
	if (ResourceMapping.class.equals(adapter)) {
		return XdsElementUtils.createResourceMappingFrom(children, this);
	}
	
	return super.getAdapter(adapter);
}
 
Example 24
Source Project: gama   Source File: OpenActionProvider.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addOpenWithMenu(final IMenuManager aMenu) {
	final IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();
	if (ss == null || ss.size() != 1) { return; }
	final Object o = ss.getFirstElement();
	// first try IResource
	IAdaptable openable = CloseResourceAction.getAdapter(o, IResource.class);
	// otherwise try ResourceMapping
	if (openable == null) {
		openable = CloseResourceAction.getAdapter(o, ResourceMapping.class);
	} else if (((IResource) openable).getType() != IResource.FILE) {
		openable = null;
	}
	if (openable != null) {
		// Create a menu flyout.
		final IMenuManager submenu =
				new MenuManager(WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label,
						ICommonMenuConstants.GROUP_OPEN_WITH);
		submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
		submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
		submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

		// Add the submenu.
		if (submenu.getItems().length > 2 && submenu.isEnabled()) {
			aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
		}
	}
}
 
Example 25
/**
 * Returns the resource for the given input object, or
 * null if there is no resource associated with it.
 *
 * @param object  the object to find the resource for
 * @return the resource for the given object, or null
 */
private IResource getResource(Object object) {
	if (object instanceof ResourceMapping) {
		object = ((ResourceMapping) object).getModelObject();
		return getModelObjectResource(object);
	}
	if (object instanceof IResource) {
		return (IResource) object;
	}
	if (object instanceof IAdaptable) {
		return (IResource) ((IAdaptable) object).getAdapter(
			IResource.class);
	}
	return null;
}
 
Example 26
private void markAsExecuted(ICompilationUnit unit, ResourceMapping mapping) {
	ReorgExecutionLog log= (ReorgExecutionLog) getAdapter(ReorgExecutionLog.class);
	if (log != null) {
		log.markAsProcessed(unit);
		log.markAsProcessed(mapping);
	}
}
 
Example 27
@Override
public Change perform(IProgressMonitor monitor) throws CoreException {
	ResourceMapping mapping= JavaElementResourceMapping.create(fOldCu);
	final Change result= super.perform(monitor);
	markAsExecuted(fOldCu, mapping);
	return result;
}
 
Example 28
public void copy(IPackageFragmentRoot sourceFolder, CopyArguments javaArgs, CopyArguments resourceArgs) {
	add(sourceFolder, javaArgs, null);
	ResourceMapping mapping= JavaElementResourceMapping.create(sourceFolder);
	if (mapping != null) {
		add(mapping, resourceArgs, null);
	}
	IResource sourceResource= sourceFolder.getResource();
	if (sourceResource != null) {
		getResourceModifications().addCopyDelta(sourceResource, resourceArgs);
		IFile classpath= getClasspathFile((IResource) resourceArgs.getDestination());
		if (classpath != null) {
			getResourceModifications().addChanged(classpath);
		}
	}
}
 
Example 29
public void copy(ICompilationUnit unit, CopyArguments javaArgs, CopyArguments resourceArgs) {
	add(unit, javaArgs, null);
	ResourceMapping mapping= JavaElementResourceMapping.create(unit);
	if (mapping != null) {
		add(mapping, resourceArgs, null);
	}
	if (unit.getResource() != null) {
		getResourceModifications().addCopyDelta(unit.getResource(), resourceArgs);
	}
}
 
Example 30
public INewNameQuery createNewCompilationUnitNameQuery(final ICompilationUnit cu, final String initialSuggestedName) {
	return new INewNameQuery() {
		public String getNewName() throws OperationCanceledException {
			String result= fDelegate.createNewCompilationUnitNameQuery(cu, initialSuggestedName).getNewName();
			String newName= JavaModelUtil.getRenamedCUName(cu, result);
			fExecutionLog.setNewName(cu, newName);
			ResourceMapping mapping= JavaElementResourceMapping.create(cu);
			if (mapping != null) {
				fExecutionLog.setNewName(mapping, newName);
			}
			return result;
		}
	};
}