Search in sources :

Example 56 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class MultiStateTextFileChange method getCurrentDocument.

/**
	 * Returns a document representing the current state of the buffer,
	 * prior to the application of the change.
	 * <p>
	 * The returned document should not be modified.
	 * </p>
	 *
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @return the current document, or the empty document
	 * @throws CoreException
	 *             if no document could be acquired
	 */
public final IDocument getCurrentDocument(IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    IDocument result = null;
    //$NON-NLS-1$
    monitor.beginTask("", 2);
    try {
        result = acquireDocument(new SubProgressMonitor(monitor, 1));
    } finally {
        if (result != null)
            releaseDocument(result, new SubProgressMonitor(monitor, 1));
    }
    monitor.done();
    if (result == null)
        result = new Document();
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 57 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class CompositeChange method initializeValidationData.

/**
	 * {@inheritDoc}
	 * <p>
	 * The composite change sends <code>initializeValidationData</code> to all its
	 * children.
	 * </p>
	 * <p>
	 * Client are allowed to extend this method.
	 * </p>
	 */
public void initializeValidationData(IProgressMonitor pm) {
    //$NON-NLS-1$
    pm.beginTask("", fChanges.size());
    for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) {
        Change change = (Change) iter.next();
        change.initializeValidationData(new SubProgressMonitor(pm, 1));
        pm.worked(1);
    }
}
Also used : Iterator(java.util.Iterator) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 58 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class PerformChangeOperation method executeChange.

/**
	 * Actually executes the change.
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @throws CoreException if an unexpected error occurs during
	 *  change execution
	 */
protected void executeChange(IProgressMonitor pm) throws CoreException {
    fChangeExecuted = false;
    if (!fChange.isEnabled())
        return;
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            boolean undoInitialized = false;
            try {
                //$NON-NLS-1$
                monitor.beginTask("", 10);
                fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
                if (fValidationStatus.hasFatalError())
                    return;
                boolean aboutToPerformChangeCalled = false;
                try {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        fUndoManager.aboutToPerformChange(fChange);
                        aboutToPerformChangeCalled = true;
                    }
                    fChangeExecutionFailed = true;
                    fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
                    fChangeExecutionFailed = false;
                    fChangeExecuted = true;
                } finally {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        if (aboutToPerformChangeCalled)
                            fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
                    }
                }
                fChange.dispose();
                if (fUndoChange != null) {
                    fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                    undoInitialized = true;
                }
                if (fUndoManager != null) {
                    if (fUndoChange != null) {
                        fUndoManager.addUndo(fUndoName, fUndoChange);
                    } else {
                        fUndoManager.flush();
                    }
                }
            } catch (CoreException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } catch (RuntimeException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } finally {
                monitor.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 59 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class TextChange method getCurrentDocument.

//---- Method to access the current content of the text change ---------
/**
	 * Returns the document this text change is associated to. The
	 * document returned is computed at the point in time when this
	 * method is called. So calling this method multiple times may
	 * return different document instances.
	 * <p>
	 * The returned document must not be modified by the client. Doing
	 * so will result in an unexpected behavior when the change is
	 * performed.
	 * </p>
	 *
	 * @param pm a progress monitor to report progress or <code>null</code>
	 *  if no progress reporting is desired
	 * @return the document this change is working on
	 *
	 * @throws CoreException if the document can't be acquired
	 */
public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    IDocument result = null;
    //$NON-NLS-1$
    pm.beginTask("", 2);
    try {
        result = acquireDocument(new SubProgressMonitor(pm, 1));
    } finally {
        if (result != null)
            releaseDocument(result, new SubProgressMonitor(pm, 1));
    }
    pm.done();
    return result;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 60 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class CompositeResourceMapping method getTraversals.

/* (non-Javadoc)
	 * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.internal.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 100 * mappings.length);
        List<ResourceTraversal> result = new ArrayList<ResourceTraversal>();
        for (int i = 0; i < mappings.length; i++) {
            ResourceMapping mapping = mappings[i];
            result.addAll(Arrays.asList(mapping.getTraversals(context, new SubProgressMonitor(monitor, 100))));
        }
        return result.toArray(new ResourceTraversal[result.size()]);
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12