use of org.eclipse.core.resources.IContainer 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.IContainer in project che by eclipse.
the class MoveModifications method move.
public void move(IPackageFragment pack, MoveArguments args) throws CoreException {
add(pack, args, null);
if (pack.getResource() == null)
return;
IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) args.getDestination();
if (javaDestination.getResource() == null)
return;
IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
if (!pack.hasSubpackages() && !newPack.exists()) {
// we can do a simple move
IContainer resourceDestination = newPack.getResource().getParent();
createIncludingParents(resourceDestination);
getResourceModifications().addMove(pack.getResource(), new MoveArguments(resourceDestination, args.getUpdateReferences()));
} else {
IContainer resourceSource = (IContainer) pack.getResource();
IContainer resourceDestination = (IContainer) newPack.getResource();
createIncludingParents(resourceDestination);
MoveArguments arguments = new MoveArguments(resourceDestination, args.getUpdateReferences());
IResource[] resourcesToMove = collectResourcesOfInterest(pack);
Set<IResource> allMembers = new HashSet<IResource>(Arrays.asList(resourceSource.members()));
for (int i = 0; i < resourcesToMove.length; i++) {
IResource toMove = resourcesToMove[i];
getResourceModifications().addMove(toMove, arguments);
allMembers.remove(toMove);
}
for (Iterator<IResource> iter = allMembers.iterator(); iter.hasNext(); ) {
IResource element = iter.next();
if (element instanceof IFile) {
getResourceModifications().addDelete(element);
iter.remove();
}
}
if (allMembers.isEmpty()) {
getResourceModifications().addDelete(resourceSource);
}
}
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class OverwriteHelper method confirmPackageFragmentRootOverwritting.
private void confirmPackageFragmentRootOverwritting(IConfirmQuery skipQuery, IConfirmQuery overwriteQuery) {
List<IPackageFragmentRoot> toNotOverwrite = new ArrayList<IPackageFragmentRoot>(1);
for (int i = 0; i < fRoots.length; i++) {
IPackageFragmentRoot root = fRoots[i];
if (canOverwrite(root)) {
if (root.getResource() instanceof IContainer) {
if (!skip(JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT), skipQuery))
toNotOverwrite.add(root);
} else {
if (!overwrite(root.getResource(), overwriteQuery))
toNotOverwrite.add(root);
}
}
}
IPackageFragmentRoot[] roots = toNotOverwrite.toArray(new IPackageFragmentRoot[toNotOverwrite.size()]);
fRoots = ArrayTypeConverter.toPackageFragmentRootArray(ReorgUtils.setMinus(fRoots, roots));
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class OverwriteHelper method willOverwrite.
/*
* Will resource override a member of destination?
*/
private boolean willOverwrite(IResource resource) {
if (resource == null)
return false;
IResource destinationResource = ResourceUtil.getResource(fDestination);
if (destinationResource.equals(resource.getParent()))
return false;
if (destinationResource instanceof IContainer) {
IContainer container = (IContainer) destinationResource;
IResource member = container.findMember(resource.getName());
if (member == null || !member.exists())
return false;
return true;
}
return false;
}
use of org.eclipse.core.resources.IContainer in project che by eclipse.
the class CoreUtility method createFolder.
/**
* Creates a folder and all parent folders if not existing.
* Project must exist.
* <code> org.eclipse.ui.dialogs.ContainerGenerator</code> is too heavy
* (creates a runnable)
* @param folder the folder to create
* @param force a flag controlling how to deal with resources that
* are not in sync with the local file system
* @param local a flag controlling whether or not the folder will be local
* after the creation
* @param monitor the progress monitor
* @throws CoreException thrown if the creation failed
*/
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
if (!folder.exists()) {
IContainer parent = folder.getParent();
if (parent instanceof IFolder) {
createFolder((IFolder) parent, force, local, null);
}
folder.create(force, local, monitor);
}
}
Aggregations