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();
}
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;
}
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;
}
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);
}
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);
}
Aggregations