Search in sources :

Example 26 with IContainer

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);
        }
    }
}
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 27 with IContainer

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);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) HashSet(java.util.HashSet)

Example 28 with IContainer

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));
}
Also used : ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 29 with IContainer

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;
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 30 with IContainer

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);
    }
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9