Search in sources :

Example 91 with ISchedulingRule

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

the class Container method setDefaultCharset.

/* (non-Javadoc)
	 * @see IContainer#setDefaultCharset(String, IProgressMonitor)
	 */
public void setDefaultCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_settingDefaultCharsetContainer, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        // need to get the project as a scheduling rule because we might be
        // creating a new folder/file to hold the project settings
        final ISchedulingRule rule = workspace.getRuleFactory().charsetRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            checkAccessible(getFlags(getResourceInfo(false, false)));
            workspace.beginOperation(true);
            workspace.getCharsetManager().setCharsetFor(getFullPath(), newCharset);
            // now propagate the changes to all children inheriting their setting from this container
            IElementContentVisitor visitor = new IElementContentVisitor() {

                boolean visitedRoot = false;

                public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object elementContents) {
                    if (elementContents == null)
                        return false;
                    IPath nodePath = requestor.requestPath();
                    // that is the condition we are checking later)
                    if (!visitedRoot) {
                        visitedRoot = true;
                        ResourceInfo info = workspace.getResourceInfo(nodePath, false, true);
                        if (info == null)
                            return false;
                        info.incrementCharsetGenerationCount();
                        return true;
                    }
                    // does it already have an encoding explicitly set?
                    if (workspace.getCharsetManager().getCharsetFor(nodePath, false) != null)
                        return false;
                    ResourceInfo info = workspace.getResourceInfo(nodePath, false, true);
                    if (info == null)
                        return false;
                    info.incrementCharsetGenerationCount();
                    return true;
                }
            };
            try {
                new ElementTreeIterator(workspace.getElementTree(), getFullPath()).iterate(visitor);
            } catch (WrappedRuntimeException e) {
                throw (CoreException) e.getTargetException();
            }
            monitor.worked(Policy.opWork);
        } 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 92 with ISchedulingRule

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

the class File method setContents.

/* (non-Javadoc)
	 * @see IFile#setContents(InputStream, int, IProgressMonitor)
	 */
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, fileInfo, 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 : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 93 with ISchedulingRule

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

the class File method appendContents.

/* (non-Javadoc)
	 * @see IFile#appendContents(InputStream, int, IProgressMonitor)
	 */
public void appendContents(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);
        // $NON-NLS-1$
        Assert.isNotNull(content, "Content cannot be null.");
        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, fileInfo, updateFlags, true, 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();
    }
}
Also used : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 94 with ISchedulingRule

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

the class File method create.

/* (non-Javadoc)
	 * @see IFile#create(InputStream, int, IProgressMonitor)
	 */
public void create(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException {
    final boolean monitorNull = monitor == null;
    monitor = Policy.monitorFor(monitor);
    try {
        // $NON-NLS-1$
        String message = monitorNull ? "" : NLS.bind(Messages.resources_creating, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        checkValidPath(path, FILE, true);
        final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            checkDoesNotExist();
            Container parent = (Container) getParent();
            ResourceInfo info = parent.getResourceInfo(false, false);
            parent.checkAccessible(getFlags(info));
            workspace.beginOperation(true);
            IFileStore store = getStore();
            IFileInfo localInfo = store.fetchInfo();
            if (BitMask.isSet(updateFlags, IResource.FORCE)) {
                if (!Workspace.caseSensitive) {
                    if (localInfo.exists()) {
                        String name = getLocalManager().getLocalName(store);
                        if (name == null || localInfo.getName().equals(name)) {
                            delete(true, null);
                        } else {
                            // The file system is not case sensitive and there is already a file
                            // under this location.
                            message = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                            throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
                        }
                    }
                }
            } else {
                if (localInfo.exists()) {
                    // return an appropriate error message for case variant collisions
                    if (!Workspace.caseSensitive) {
                        String name = getLocalManager().getLocalName(store);
                        if (name != null && !localInfo.getName().equals(name)) {
                            message = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                            throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
                        }
                    }
                    message = NLS.bind(Messages.resources_fileExists, store.toString());
                    throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null);
                }
            }
            monitor.worked(Policy.opWork * 40 / 100);
            info = workspace.createResource(this, updateFlags);
            boolean local = content != null;
            if (local) {
                try {
                    internalSetContents(content, localInfo, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork * 60 / 100));
                } catch (CoreException e) {
                    // a problem happened creating the file on disk, so delete from the workspace and disk
                    workspace.deleteResource(this);
                    store.delete(EFS.NONE, null);
                    // rethrow
                    throw e;
                }
            }
            internalSetLocal(local, DEPTH_ZERO);
            if (!local)
                getResourceInfo(true, true).clearModificationStamp();
        } 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 : ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 95 with ISchedulingRule

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

the class Folder method create.

/* (non-Javadoc)
	 * @see IFolder#create(int, boolean, IProgressMonitor)
	 */
public void create(int updateFlags, boolean local, IProgressMonitor monitor) throws CoreException {
    final boolean force = (updateFlags & IResource.FORCE) != 0;
    monitor = Policy.monitorFor(monitor);
    try {
        String message = NLS.bind(Messages.resources_creating, getFullPath());
        monitor.beginTask(message, Policy.totalWork);
        checkValidPath(path, FOLDER, true);
        final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
        try {
            workspace.prepareOperation(rule, monitor);
            IFileStore store = getStore();
            IFileInfo localInfo = store.fetchInfo();
            assertCreateRequirements(store, localInfo, updateFlags);
            workspace.beginOperation(true);
            if (force && !Workspace.caseSensitive && localInfo.exists()) {
                String name = getLocalManager().getLocalName(store);
                if (name == null || localInfo.getName().equals(name)) {
                    delete(true, null);
                } else {
                    // The file system is not case sensitive and a case variant exists at this location
                    String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                    throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null);
                }
            }
            internalCreate(updateFlags, local, Policy.subMonitorFor(monitor, Policy.opWork));
            workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_ZERO, monitor);
        } catch (OperationCanceledException e) {
            workspace.getWorkManager().operationCanceled();
            throw e;
        } finally {
            workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) 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