use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class MoveResourceChange method perform.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
*/
public final Change perform(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
try {
if (monitor == null)
monitor = new NullProgressMonitor();
monitor.beginTask(getName(), 4);
Change deleteUndo = null;
// delete destination if required
IResource resourceAtDestination = fTarget.findMember(fSource.getName());
if (resourceAtDestination != null && resourceAtDestination.exists()) {
deleteUndo = performDestinationDelete(resourceAtDestination, new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
// move resource
long currentStamp = fSource.getModificationStamp();
IPath destinationPath = fTarget.getFullPath().append(fSource.getName());
fSource.move(destinationPath, IResource.KEEP_HISTORY | IResource.SHALLOW, new SubProgressMonitor(monitor, 2));
resourceAtDestination = ResourcesPlugin.getWorkspace().getRoot().findMember(destinationPath);
// restore timestamp at destination
if (fStampToRestore != IResource.NULL_STAMP) {
resourceAtDestination.revertModificationStamp(fStampToRestore);
}
// restore file at source
if (fRestoreSourceChange != null) {
performSourceRestore(new SubProgressMonitor(monitor, 1));
} else {
monitor.worked(1);
}
return new MoveResourceChange(resourceAtDestination, fSource.getParent(), currentStamp, deleteUndo);
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class MultiStateUndoChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized"));
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class MultiStateUndoChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
return new NullChange();
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
// perform the changes
LinkedList list = new LinkedList();
for (int index = 0; index < fUndos.length; index++) {
UndoEdit edit = fUndos[index];
UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
list.addFirst(redo);
}
// try to restore the document content stamp
boolean success = ContentStamps.set(document, fContentStampToRestore);
if (needsSaving()) {
buffer.commit(pm, false);
if (!success) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class ProcessorBasedRefactoring method checkInitialConditions.
/**
* {@inheritDoc}
*/
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
RefactoringStatus result = new RefactoringStatus();
//$NON-NLS-1$
pm.beginTask("", 10);
pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_initial_conditions);
result.merge(getProcessor().checkInitialConditions(new SubProgressMonitor(pm, 8)));
if (result.hasFatalError()) {
pm.done();
return result;
}
pm.done();
return result;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.
the class ProcessorBasedRefactoring method createChange.
/**
* {@inheritDoc}
*/
public Change createChange(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", fParticipants.size() + 3);
pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_create_change);
Change processorChange = getProcessor().createChange(new SubProgressMonitor(pm, 1));
if (pm.isCanceled())
throw new OperationCanceledException();
fTextChangeMap = new HashMap();
addToTextChangeMap(processorChange);
List /*<Change>*/
changes = new ArrayList();
List /*<Change>*/
preChanges = new ArrayList();
Map /*<Change, RefactoringParticipant>*/
participantMap = new HashMap();
for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
final RefactoringParticipant participant = (RefactoringParticipant) iter.next();
try {
//$NON-NLS-1$
final PerformanceStats stats = PerformanceStats.getStats(PERF_CREATE_CHANGES, getName() + ", " + participant.getName());
stats.startRun();
Change preChange = participant.createPreChange(new SubProgressMonitor(pm, 1));
Change change = participant.createChange(new SubProgressMonitor(pm, 1));
stats.endRun();
if (preChange != null) {
if (fPreChangeParticipants == null)
fPreChangeParticipants = new ArrayList();
fPreChangeParticipants.add(participant);
preChanges.add(preChange);
participantMap.put(preChange, participant);
addToTextChangeMap(preChange);
}
if (change != null) {
changes.add(change);
participantMap.put(change, participant);
addToTextChangeMap(change);
}
} catch (CoreException e) {
disableParticipant(participant, e);
throw e;
} catch (OperationCanceledException e) {
throw e;
} catch (RuntimeException e) {
disableParticipant(participant, e);
throw e;
}
if (pm.isCanceled())
throw new OperationCanceledException();
}
fTextChangeMap = null;
Change postChange = getProcessor().postCreateChange((Change[]) changes.toArray(new Change[changes.size()]), new SubProgressMonitor(pm, 1));
ProcessorChange result = new ProcessorChange(getName());
result.addAll((Change[]) preChanges.toArray(new Change[preChanges.size()]));
result.add(processorChange);
result.addAll((Change[]) changes.toArray(new Change[changes.size()]));
result.setParticipantMap(participantMap);
result.setPreChangeParticipants(fPreChangeParticipants);
if (postChange != null)
result.add(postChange);
return result;
}
Aggregations