Search in sources :

Example 81 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method createLink.

/* (non-Javadoc)
	 * @see org.eclipse.core.resources.IFolder#createLink(URI, int, IProgressMonitor)
	 * @see org.eclipse.core.resources.IFile#createLink(URI, int, IProgressMonitor)
	 */
public void createLink(URI localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(localLocation);
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.links_creating, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        Policy.checkCanceled(monitor);
        checkValidPath(path, FOLDER, true);
        final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            IFileInfo fileInfo = assertLinkRequirements(localLocation, updateFlags);
            workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_CREATE, this));
            workspace.beginOperation(true);
            // replace existing resource, if applicable
            if ((updateFlags & REPLACE) != 0) {
                IResource existing = workspace.getRoot().findMember(getFullPath());
                if (existing != null)
                    workspace.deleteResource(existing);
            }
            ResourceInfo info = workspace.createResource(this, false);
            if ((updateFlags & IResource.HIDDEN) != 0)
                info.set(M_HIDDEN);
            info.set(M_LINK);
            localLocation = FileUtil.canonicalURI(localLocation);
            getLocalManager().link(this, localLocation, fileInfo);
            monitor.worked(Policy.opWork * 5 / 100);
            // save the location in the project description
            Project project = (Project) getProject();
            boolean changed = project.internalGetDescription().setLinkLocation(getProjectRelativePath(), new LinkDescription(this, localLocation));
            if (changed)
                project.writeDescription(IResource.NONE);
            monitor.worked(Policy.opWork * 5 / 100);
            // refresh to discover any new resources below this linked location
            if (getType() != IResource.FILE) {
                // refresh either in background or foreground
                if ((updateFlags & IResource.BACKGROUND_REFRESH) != 0) {
                    workspace.refreshManager.refresh(this);
                    monitor.worked(Policy.opWork * 90 / 100);
                } else {
                    refreshLocal(DEPTH_INFINITE, Policy.subMonitorFor(monitor, Policy.opWork * 90 / 100));
                }
            } else
                monitor.worked(Policy.opWork * 90 / 100);
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 82 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method contains.

/*
	 *  (non-Javadoc)
	 * @see ISchedulingRule#contains(ISchedulingRule)
	 */
public boolean contains(ISchedulingRule rule) {
    if (this == rule)
        return true;
    // must allow notifications to nest in all resource rules
    if (rule.getClass().equals(WorkManager.NotifyRule.class))
        return true;
    if (rule instanceof MultiRule) {
        MultiRule multi = (MultiRule) rule;
        ISchedulingRule[] children = multi.getChildren();
        for (int i = 0; i < children.length; i++) if (!contains(children[i]))
            return false;
        return true;
    }
    if (!(rule instanceof IResource))
        return false;
    return path.isPrefixOf(((IResource) rule).getFullPath());
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 83 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method delete.

/* (non-Javadoc)
	 * @see IResource#delete(int, IProgressMonitor)
	 */
public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_deleting, getFullPath());
        // $NON-NLS-1$
        monitor.beginTask("", Policy.totalWork * 1000);
        monitor.subTask(message);
        final ISchedulingRule rule = workspace.getRuleFactory().deleteRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            // if there is no resource then there is nothing to delete so just return
            if (!exists())
                return;
            workspace.beginOperation(true);
            broadcastPreDeleteEvent();
            // when a project is being deleted, flush the build order in case there is a problem
            if (this.getType() == IResource.PROJECT)
                workspace.flushBuildOrder();
            final IFileStore originalStore = getStore();
            boolean wasLinked = isLinked();
            message = Messages.resources_deleteProblem;
            MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, null);
            WorkManager workManager = workspace.getWorkManager();
            ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags);
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                unprotectedDelete(tree, updateFlags, monitor);
            } finally {
                workManager.endUnprotected(depth);
            }
            if (getType() == ROOT) {
                // need to clear out the root info
                workspace.getMarkerManager().removeMarkers(this, IResource.DEPTH_ZERO);
                getPropertyManager().deleteProperties(this, IResource.DEPTH_ZERO);
                getResourceInfo(false, false).clearSessionProperties();
            }
            // Invalidate the tree for further use by clients.
            tree.makeInvalid();
            if (!tree.getStatus().isOK())
                throw new ResourceException(tree.getStatus());
            // note that deletion of a linked resource cannot affect other resources
            if (!wasLinked)
                workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor);
            // make sure the rule factory is cleared on project deletion
            if (getType() == PROJECT)
                ((Rules) workspace.getRuleFactory()).setRuleFactory((IProject) this, null);
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork * 1000));
        }
    } finally {
        monitor.done();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 84 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method move.

/* (non-Javadoc)
	 * @see IResource#move(IPath, int, IProgressMonitor)
	 */
public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_moving, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        Policy.checkCanceled(monitor);
        destination = makePathAbsolute(destination);
        checkValidPath(destination, getType(), false);
        Resource destResource = workspace.newResource(destination, getType());
        final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destResource);
        try {
            workspace.prepareOperation(rule, monitor);
            // The following assert method throws CoreExceptions as stated in the IResource.move API
            // and assert for programming errors. See checkMoveRequirements for more information.
            assertMoveRequirements(destination, getType(), updateFlags);
            workspace.beginOperation(true);
            broadcastPreMoveEvent(destResource, updateFlags);
            IFileStore originalStore = getStore();
            message = Messages.resources_moveProblem;
            MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null);
            WorkManager workManager = workspace.getWorkManager();
            ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags);
            boolean success = false;
            int depth = 0;
            try {
                depth = workManager.beginUnprotected();
                success = unprotectedMove(tree, destResource, updateFlags, monitor);
            } finally {
                workManager.endUnprotected(depth);
            }
            // Invalidate the tree for further use by clients.
            tree.makeInvalid();
            // update any aliases of this resource and the destination
            if (success) {
                workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor);
                workspace.getAliasManager().updateAliases(destResource, destResource.getStore(), IResource.DEPTH_INFINITE, monitor);
            }
            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 : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 85 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.

the class Resource method refreshLocal.

/* (non-Javadoc)
	 * @see IResource#refreshLocal(int, IProgressMonitor)
	 */
public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        boolean isRoot = getType() == ROOT;
        String message = isRoot ? Messages.resources_refreshingRoot : NLS.bind(Messages.resources_refreshing, getFullPath());
        // $NON-NLS-1$
        monitor.beginTask("", Policy.totalWork);
        monitor.subTask(message);
        boolean build = false;
        final ISchedulingRule rule = workspace.getRuleFactory().refreshRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            if (!isRoot && !getProject().isAccessible())
                return;
            workspace.beginOperation(true);
            if (getType() == IResource.PROJECT || getType() == IResource.ROOT)
                workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_REFRESH, this));
            build = getLocalManager().refresh(this, depth, true, Policy.subMonitorFor(monitor, Policy.opWork));
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } catch (Error e) {
            // support to track down Bug 95089
            Policy.log(e);
            throw e;
        } catch (RuntimeException e) {
            // support to track down Bug 95089
            Policy.log(e);
            throw e;
        } finally {
            workspace.endOperation(rule, build, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)116 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)41 CoreException (org.eclipse.core.runtime.CoreException)40 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)32 IWorkspace (org.eclipse.core.resources.IWorkspace)30 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 PersistenceException (org.talend.commons.exception.PersistenceException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IStatus (org.eclipse.core.runtime.IStatus)17 Status (org.eclipse.core.runtime.Status)15 IResource (org.eclipse.core.resources.IResource)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 ArrayList (java.util.ArrayList)13 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)12 Job (org.eclipse.core.runtime.jobs.Job)12 IFile (org.eclipse.core.resources.IFile)11 HashSet (java.util.HashSet)10 IPath (org.eclipse.core.runtime.IPath)10 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)10 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)10