use of org.eclipse.core.runtime.IProgressMonitor in project che by eclipse.
the class JavaMoveProcessor method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
Assert.isTrue(fMovePolicy.getJavaElementDestination() == null || fMovePolicy.getResourceDestination() == null);
Assert.isTrue(fMovePolicy.getJavaElementDestination() != null || fMovePolicy.getResourceDestination() != null);
try {
final DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.JavaMoveProcessor_change_name) {
@Override
public ChangeDescriptor getDescriptor() {
return fMovePolicy.getDescriptor();
}
@Override
public Change perform(IProgressMonitor pm2) throws CoreException {
Change change = super.perform(pm2);
Change[] changes = getChildren();
for (int index = 0; index < changes.length; index++) {
if (!(changes[index] instanceof TextEditBasedChange))
return null;
}
return change;
}
};
CreateTargetExecutionLog log = null;
if (fCreateTargetQueries instanceof MonitoringCreateTargetQueries) {
final MonitoringCreateTargetQueries queries = (MonitoringCreateTargetQueries) fCreateTargetQueries;
final ICreateTargetQueries delegate = queries.getDelegate();
if (delegate instanceof LoggedCreateTargetQueries)
log = queries.getCreateTargetExecutionLog();
}
if (log != null) {
final Object[] selected = log.getSelectedElements();
for (int index = 0; index < selected.length; index++) {
result.add(new LoggedCreateTargetChange(selected[index], fCreateTargetQueries));
}
}
Change change = fMovePolicy.createChange(pm);
if (change instanceof CompositeChange) {
CompositeChange subComposite = (CompositeChange) change;
result.merge(subComposite);
} else {
result.add(change);
}
return result;
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.IProgressMonitor 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.IProgressMonitor in project che by eclipse.
the class DynamicValidationStateChange method perform.
/**
* {@inheritDoc}
*/
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
final Change[] result = new Change[1];
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
result[0] = DynamicValidationStateChange.super.perform(monitor);
}
};
JavaCore.run(runnable, fSchedulingRule, pm);
return result[0];
}
use of org.eclipse.core.runtime.IProgressMonitor in project generator by mybatis.
the class WorkspaceUtilities method createProject.
private static IProject createProject(String projectName) throws CoreException {
final IProject project = getWorkspaceRoot().getProject(projectName);
IWorkspaceRunnable create = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
project.create(null);
project.open(null);
}
};
getWorkspace().run(create, null);
return project;
}
use of org.eclipse.core.runtime.IProgressMonitor in project generator by mybatis.
the class NewConfigFileWizard method performFinish.
/**
* This method is called when 'Finish' button is pressed in the wizard. We
* will create an operation and run it using wizard as execution context.
*/
public boolean performFinish() {
final String containerName = page.getLocation();
final String fileName = page.getFileName();
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
doFinish(containerName, fileName, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
return true;
}
Aggregations