Search in sources :

Example 16 with ISchedulingRule

use of org.eclipse.core.runtime.jobs.ISchedulingRule in project tdi-studio-se by Talend.

the class SaveAsBusinessModelWizard method update.

private void update() {
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                assginVlaues(oldProperty, property);
                repositoryFactory.save(oldBusinessProcessItem);
                // assign value
                businessProcessItem = oldBusinessProcessItem;
            } catch (PersistenceException pe) {
                throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "persistance error", //$NON-NLS-1$
                pe));
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        ISchedulingRule schedulingRule = workspace.getRoot();
        // the update the project files need to be done in the workspace runnable to avoid all notification
        // of changes before the end of the modifications.
        workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e.getCause());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 17 with ISchedulingRule

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

the class LastSaveReferenceProvider method readDocument.

/**
 * Reads in the saved document into <code>fReference</code>.
 *
 * @param monitor a progress monitor, or <code>null</code>
 * @param force <code>true</code> if the reference document should also
 *        be read if the current document is <code>null</code>,<code>false</code>
 *        if it should only be updated if it already existed.
 */
private void readDocument(IProgressMonitor monitor, boolean force) {
    // protect against concurrent disposal
    IDocumentProvider prov = fDocumentProvider;
    IEditorInput inp = fEditorInput;
    IDocument doc = fReference;
    ITextEditor editor = fEditor;
    if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
        IStorageEditorInput input = (IStorageEditorInput) inp;
        IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
        if (doc == null)
            if (force || fDocumentRead)
                doc = new Document();
            else
                return;
        IJobManager jobMgr = Job.getJobManager();
        try {
            IStorage storage = input.getStorage();
            // check for null for backward compatibility (we used to check before...)
            if (storage == null)
                return;
            fProgressMonitor = monitor;
            ISchedulingRule rule = getSchedulingRule(storage);
            // delay for any other job requiring the lock on file
            try {
                lockDocument(monitor, jobMgr, rule);
                String encoding;
                if (storage instanceof IEncodedStorage)
                    encoding = ((IEncodedStorage) storage).getCharset();
                else
                    encoding = null;
                boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
                setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
            } finally {
                unlockDocument(jobMgr, rule);
                fProgressMonitor = null;
            }
        } catch (CoreException e) {
            return;
        }
        if (monitor != null && monitor.isCanceled())
            return;
        // update state
        synchronized (fLock) {
            if (fDocumentProvider == provider && fEditorInput == input) {
                // only update state if our provider / input pair has not
                // been updated in between (dispose or setActiveEditor)
                fReference = doc;
                fDocumentRead = true;
                addElementStateListener(editor, prov);
            }
        }
    }
}
Also used : IStorageDocumentProvider(org.eclipse.ui.editors.text.IStorageDocumentProvider) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEncodedStorage(org.eclipse.core.resources.IEncodedStorage) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IStorage(org.eclipse.core.resources.IStorage) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 18 with ISchedulingRule

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

the class GenericFileBufferOperationRunner method computeCommitRule.

protected ISchedulingRule computeCommitRule(IFileBuffer[] fileBuffers) {
    ArrayList<ISchedulingRule> list = new ArrayList<>();
    for (IFileBuffer fileBuffer : fileBuffers) {
        ISchedulingRule rule = fileBuffer.computeCommitRule();
        if (rule != null)
            list.add(rule);
    }
    ISchedulingRule[] rules = new ISchedulingRule[list.size()];
    list.toArray(rules);
    return new MultiRule(rules);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ArrayList(java.util.ArrayList) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 19 with ISchedulingRule

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

the class GenericFileBufferOperationRunner method performOperation.

private void performOperation(IFileBuffer fileBuffer, IFileBufferOperation operation, IProgressMonitor progressMonitor) throws CoreException, OperationCanceledException {
    SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 100);
    ISchedulingRule rule = fileBuffer.computeCommitRule();
    IJobManager manager = Job.getJobManager();
    manager.beginRule(rule, subMonitor.split(1));
    String name = fileBuffer.getLocation().lastSegment();
    subMonitor.setTaskName(name);
    operation.run(fileBuffer, subMonitor.split(99));
    manager.endRule(rule);
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 20 with ISchedulingRule

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

the class GenericFileBufferOperationRunner method commit.

protected void commit(final IFileBuffer[] fileBuffers, final IProgressMonitor progressMonitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 2);
    ISchedulingRule rule = computeCommitRule(fileBuffers);
    Job.getJobManager().beginRule(rule, subMonitor.split(1));
    try {
        doCommit(fileBuffers, subMonitor.split(1));
    } finally {
        Job.getJobManager().endRule(rule);
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)33 CoreException (org.eclipse.core.runtime.CoreException)21 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 IWorkspace (org.eclipse.core.resources.IWorkspace)19 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)19 PersistenceException (org.talend.commons.exception.PersistenceException)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IStatus (org.eclipse.core.runtime.IStatus)9 Status (org.eclipse.core.runtime.Status)8 RepositoryWorkUnit (org.talend.repository.RepositoryWorkUnit)7 HashSet (java.util.HashSet)6 IResource (org.eclipse.core.resources.IResource)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)6 ArrayList (java.util.ArrayList)5 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 HashMap (java.util.HashMap)4 IPath (org.eclipse.core.runtime.IPath)4