Search in sources :

Example 46 with ISchedulingRule

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

the class Resource method deleteMarkers.

/* (non-Javadoc)
	 * @see IResource#deleteMarkers(String, boolean, int)
	 */
public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
    final ISchedulingRule rule = workspace.getRuleFactory().markerRule(this);
    try {
        workspace.prepareOperation(rule, null);
        ResourceInfo info = getResourceInfo(false, false);
        checkAccessible(getFlags(info));
        workspace.beginOperation(true);
        workspace.getMarkerManager().removeMarkers(this, type, includeSubtypes, depth);
    } finally {
        workspace.endOperation(rule, false, null);
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 47 with ISchedulingRule

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

the class Workspace method build.

/* (non-Javadoc)
	 * @see IWorkspace#build(int, IProgressMonitor)
	 */
public void build(int trigger, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    final ISchedulingRule rule = getRuleFactory().buildRule();
    try {
        // $NON-NLS-1$
        monitor.beginTask("", Policy.opWork);
        try {
            prepareOperation(rule, monitor);
            beginOperation(true);
            aboutToBuild(this, trigger);
            IStatus result;
            try {
                result = getBuildManager().build(trigger, Policy.subMonitorFor(monitor, Policy.opWork));
            } finally {
                // must fire POST_BUILD if PRE_BUILD has occurred
                broadcastBuildEvent(this, IResourceChangeEvent.POST_BUILD, trigger);
            }
            if (!result.isOK())
                throw new ResourceException(result);
        } finally {
            // building may close the tree, but we are still inside an operation so open it
            if (tree.isImmutable())
                newWorkingTree();
            endOperation(rule, false, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 48 with ISchedulingRule

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

the class Workspace method checkpoint.

/* (non-Javadoc)
	 * @see IWorkspace#checkpoint(boolean)
	 */
public void checkpoint(boolean build) {
    try {
        final ISchedulingRule rule = getWorkManager().getNotifyRule();
        try {
            prepareOperation(rule, null);
            beginOperation(true);
            broadcastPostChange();
        } finally {
            endOperation(rule, build, null);
        }
    } catch (CoreException e) {
        Policy.log(e.getStatus());
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 49 with ISchedulingRule

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

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 rules = new HashSet();
    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 (ISchedulingRule) rules.iterator().next();
    ISchedulingRule[] ruleArray = (ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 50 with ISchedulingRule

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

the class SavedState method processResourceChangeEvents.

public void processResourceChangeEvents(IResourceChangeListener listener) {
    try {
        final ISchedulingRule rule = workspace.getRoot();
        try {
            workspace.prepareOperation(rule, null);
            if (oldTree == null || newTree == null)
                return;
            workspace.beginOperation(true);
            ResourceDelta delta = ResourceDeltaFactory.computeDelta(workspace, oldTree, newTree, Path.ROOT, -1);
            // free trees to prevent memory leak
            forgetTrees();
            workspace.getNotificationManager().broadcastChanges(listener, IResourceChangeEvent.POST_BUILD, delta);
        } finally {
            workspace.endOperation(rule, false, null);
        }
    } catch (CoreException e) {
        // this is unlikely to happen, so, just log it
        Policy.log(e);
    }
}
Also used : ResourceDelta(org.eclipse.core.internal.events.ResourceDelta) 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