Search in sources :

Example 96 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class MoveResourcesProcessor method validateDestination.

/**
	 * Validates if the a destination is valid. This method does not change the destination settings on the refactoring. It is intended to be used
	 * in a wizard to validate user input.
	 *
	 * @param destination the destination to validate
	 * @return returns the resulting status of the validation
	 */
public RefactoringStatus validateDestination(IContainer destination) {
    //$NON-NLS-1$
    Assert.isNotNull(destination, "container is null");
    if (destination instanceof IWorkspaceRoot)
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveResourceProcessor_error_invalid_destination);
    if (!destination.exists()) {
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveResourceProcessor_error_destination_not_exists);
    }
    IPath destinationPath = destination.getFullPath();
    for (int i = 0; i < fResourcesToMove.length; i++) {
        IPath path = fResourcesToMove[i].getFullPath();
        if (path.isPrefixOf(destinationPath) || path.equals(destinationPath)) {
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.MoveResourceProcessor_destination_inside_moved, BasicElementLabels.getPathLabel(path, false)));
        }
        if (path.removeLastSegments(1).equals(destinationPath)) {
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.MoveResourceProcessor_destination_same_as_moved, BasicElementLabels.getPathLabel(path, false)));
        }
    }
    return new RefactoringStatus();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 97 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class ContainerDescription method fromContainer.

protected static ContainerDescription fromContainer(IContainer container, boolean usingVirtualFolder) {
    IPath fullPath = container.getFullPath();
    ContainerDescription firstCreatedParent = null;
    ContainerDescription currentContainerDescription = null;
    // Does the container exist already? If so, then the parent exists and
    // we use the normal creation constructor.
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IContainer currentContainer = (IContainer) root.findMember(fullPath);
    if (currentContainer != null) {
        return (ContainerDescription) ResourceDescription.fromResource(container);
    }
    // Create container descriptions for any uncreated parents in the given
    // path.
    currentContainer = root;
    for (int i = 0; i < fullPath.segmentCount(); i++) {
        String currentSegment = fullPath.segment(i);
        IResource resource = currentContainer.findMember(currentSegment);
        if (resource != null) {
            // parent already exists, no need to create a description for it
            currentContainer = (IContainer) resource;
        } else {
            if (i == 0) {
                // parent does not exist and it is a project
                firstCreatedParent = new ProjectDescription(root.getProject(currentSegment));
                currentContainerDescription = firstCreatedParent;
            } else {
                IFolder folderHandle = currentContainer.getFolder(new Path(currentSegment));
                ContainerDescription currentFolder;
                currentFolder = new FolderDescription(folderHandle, usingVirtualFolder);
                currentContainer = folderHandle;
                if (currentContainerDescription != null) {
                    currentContainerDescription.addMember(currentFolder);
                }
                currentContainerDescription = currentFolder;
                if (firstCreatedParent == null) {
                    firstCreatedParent = currentFolder;
                }
            }
        }
    }
    return firstCreatedParent;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 98 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class ContainerUndoState method fromContainer.

/**
	 * Create a container description from the specified container handle that
	 * can be used to create the container. The returned ContainerState
	 * should represent any non-existing parents in addition to the specified
	 * container.
	 *
	 * @param container
	 *            the handle of the container to be described
	 * @return a container description describing the container and any
	 *         non-existing parents.
	 */
public static ContainerUndoState fromContainer(IContainer container) {
    IPath fullPath = container.getFullPath();
    ContainerUndoState firstCreatedParent = null;
    ContainerUndoState currentContainerDescription = null;
    // Does the container exist already? If so, then the parent exists and
    // we use the normal creation constructor.
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IContainer currentContainer = (IContainer) root.findMember(fullPath);
    if (currentContainer != null) {
        return (ContainerUndoState) ResourceUndoState.fromResource(container);
    }
    // Create container descriptions for any uncreated parents in the given
    // path.
    currentContainer = root;
    for (int i = 0; i < fullPath.segmentCount(); i++) {
        String currentSegment = fullPath.segment(i);
        IResource resource = currentContainer.findMember(currentSegment);
        if (resource != null) {
            // parent already exists, no need to create a description for it
            currentContainer = (IContainer) resource;
        } else {
            if (i == 0) {
                // parent does not exist and it is a project
                firstCreatedParent = new ProjectUndoState(root.getProject(currentSegment));
                currentContainerDescription = firstCreatedParent;
            } else {
                IFolder folderHandle = currentContainer.getFolder(new Path(currentSegment));
                ContainerUndoState currentFolder = new FolderUndoState(folderHandle);
                currentContainer = folderHandle;
                if (currentContainerDescription != null) {
                    currentContainerDescription.addMember(currentFolder);
                }
                currentContainerDescription = currentFolder;
                if (firstCreatedParent == null) {
                    firstCreatedParent = currentFolder;
                }
            }
        }
    }
    return firstCreatedParent;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 99 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class FileDescription method createResourceHandle.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.internal.ide.undo.ResourceDescription#createResourceHandle()
	 */
public IResource createResourceHandle() {
    IWorkspaceRoot workspaceRoot = parent.getWorkspace().getRoot();
    IPath fullPath = parent.getFullPath().append(name);
    return workspaceRoot.getFile(fullPath);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath)

Example 100 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class FolderDescription method createResourceHandle.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.internal.ide.undo.ContainerDescription#createResourceHandle()
	 */
public IResource createResourceHandle() {
    IWorkspaceRoot workspaceRoot = getWorkspace().getRoot();
    IPath folderPath = parent.getFullPath().append(name);
    return workspaceRoot.getFolder(folderPath);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10