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;
}
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);
}
}
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);
}
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;
}
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();
}
}
Aggregations