Search in sources :

Example 1 with IMoveDeleteHook

use of org.eclipse.core.resources.team.IMoveDeleteHook in project polymap4-core by Polymap4.

the class Project method move.

/* (non-Javadoc)
	 * @see IResource#move(IProjectDescription, int, IProgressMonitor)
	 */
public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(description);
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_moving, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        IProject destination = workspace.getRoot().getProject(description.getName());
        final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destination);
        try {
            workspace.prepareOperation(rule, monitor);
            // and assert for programming errors. See checkMoveRequirements for more information.
            if (!getName().equals(description.getName())) {
                IPath destPath = Path.ROOT.append(description.getName());
                assertMoveRequirements(destPath, IResource.PROJECT, updateFlags);
            }
            checkDescription(destination, description, true);
            workspace.beginOperation(true);
            message = Messages.resources_moveProblem;
            MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null);
            WorkManager workManager = workspace.getWorkManager();
            ResourceTree tree = new ResourceTree(getLocalManager(), workManager.getLock(), status, updateFlags);
            IMoveDeleteHook hook = workspace.getMoveDeleteHook();
            workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags));
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                if (!hook.moveProject(tree, this, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
                    tree.standardMoveProject(this, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2));
            } finally {
                workManager.endUnprotected(depth);
            }
            // Invalidate the tree for further use by clients.
            tree.makeInvalid();
            if (!tree.getStatus().isOK())
                throw new ResourceException(tree.getStatus());
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : IMoveDeleteHook(org.eclipse.core.resources.team.IMoveDeleteHook) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 2 with IMoveDeleteHook

use of org.eclipse.core.resources.team.IMoveDeleteHook in project polymap4-core by Polymap4.

the class Resource method unprotectedMove.

/**
 * Calls the move/delete hook to perform the move.  Since this method calls
 * client code, it is run "unprotected", so the workspace lock is not held.
 * Returns true if resources were actually moved, and false otherwise.
 */
private boolean unprotectedMove(ResourceTree tree, final IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException, ResourceException {
    IMoveDeleteHook hook = workspace.getMoveDeleteHook();
    switch(getType()) {
        case IResource.FILE:
            if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
                tree.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.FOLDER:
            if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
                tree.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.PROJECT:
            IProject project = (IProject) this;
            // if there is no change in name, there is nothing to do so return.
            if (getName().equals(destination.getName()))
                return false;
            IProjectDescription description = project.getDescription();
            description.setName(destination.getName());
            if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
                tree.standardMoveProject(project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
            break;
        case IResource.ROOT:
            String msg = Messages.resources_moveRoot;
            throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), msg));
    }
    return true;
}
Also used : IMoveDeleteHook(org.eclipse.core.resources.team.IMoveDeleteHook)

Aggregations

IMoveDeleteHook (org.eclipse.core.resources.team.IMoveDeleteHook)2 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1