Search in sources :

Example 1 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class File method setContents.

@Override
public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_settingContents, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        //            if (workspace.shouldValidate)
        //                workspace.validateSave(this);
        final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            ResourceInfo info = getResourceInfo(false, false);
            //                checkAccessible(getFlags(info));
            workspace.beginOperation(true);
            //                IFileInfo fileInfo = getStore().fetchInfo();
            internalSetContents(content, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork));
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
        FileUtil.safeClose(content);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 2 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Resource method delete.

@Override
public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        //            String message = NLS.bind(Messages.resources_deleting, getFullPath());
        //            monitor.beginTask("", Policy.totalWork * 1000); //$NON-NLS-1$
        //            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();
                workspace.delete(this);
            //                    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());
        //update any aliases of this resource
        //note that deletion of a linked resource cannot affect other resources
        //                if (!wasLinked)
        //                    workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor);
        //                if (getType() == PROJECT) {
        //                     make sure the rule factory is cleared on project deletion
        //                    ((Rules) workspace.getRuleFactory()).setRuleFactory((IProject) this, null);
        //                     make sure project deletion is remembered
        //                    workspace.getSaveManager().requestSnapshot();
        //                }
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork * 1000));
        }
    } finally {
        monitor.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 3 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Resource method isConflicting.

@Override
public boolean isConflicting(ISchedulingRule rule) {
    if (this == rule)
        return true;
    //must not schedule at same time as notification
    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 (isConflicting(children[i]))
            return true;
        return false;
    }
    if (!(rule instanceof IResource))
        return false;
    IResource resource = (IResource) rule;
    if (!workspace.equals(resource.getWorkspace()))
        return false;
    IPath otherPath = resource.getFullPath();
    return path.isPrefixOf(otherPath) || otherPath.isPrefixOf(path);
}
Also used : IPath(org.eclipse.core.runtime.IPath) MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 4 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Resource method contains.

@Override
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;
    IResource resource = (IResource) rule;
    if (!workspace.equals(resource.getWorkspace()))
        return false;
    return path.isPrefixOf(resource.getFullPath());
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 5 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.

the class Rules method validateEditRule.

/**
	 * Combines rules for each parameter to validateEdit from the corresponding
	 * rule factories.
	 */
public ISchedulingRule validateEditRule(IResource[] resources) {
    if (resources.length == 0)
        return null;
    //optimize rule for single file
    if (resources.length == 1) {
        if (resources[0].getType() == IResource.ROOT)
            return root;
        return factoryFor(resources[0]).validateEditRule(resources);
    }
    //gather rules for each resource from appropriate factory
    HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>();
    IResource[] oneResource = new IResource[1];
    for (int i = 0; i < resources.length; i++) {
        if (resources[i].getType() == IResource.ROOT)
            return root;
        oneResource[0] = resources[i];
        ISchedulingRule rule = factoryFor(resources[i]).validateEditRule(oneResource);
        if (rule != null)
            rules.add(rule);
    }
    if (rules.isEmpty())
        return null;
    if (rules.size() == 1)
        return rules.iterator().next();
    ISchedulingRule[] ruleArray = rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) 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