* if <code>true</code>, the repository will be deleted from disk
*/
protected void removeRepository(final ExecutionEvent event,
final boolean delete) {
IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
IWorkbenchSiteProgressService service = CommonUtils.getService(activeSite, IWorkbenchSiteProgressService.class);
// get selected nodes
final List<RepositoryNode> selectedNodes;
try {
selectedNodes = getSelectedNodes(event);
} catch (ExecutionException e) {
Activator.handleError(e.getMessage(), e, true);
return;
}
boolean deleteWorkingDir = false;
boolean removeProjects = false;
final List<IProject> projectsToDelete = findProjectsToDelete(selectedNodes);
if (delete) {
if (selectedNodes.size() > 1) {
return;
} else if (selectedNodes.size() == 1) {
Repository repository = selectedNodes.get(0).getObject();
if (repository.isBare()) {
// simple confirm dialog
String title = UIText.RemoveCommand_ConfirmDeleteBareRepositoryTitle;
String message = NLS
.bind(
UIText.RemoveCommand_ConfirmDeleteBareRepositoryMessage,
repository.getDirectory().getPath());
if (!MessageDialog.openConfirm(getShell(event), title,
message))
return;
} else {
// confirm dialog with check box
// "delete also working directory"
DeleteRepositoryConfirmDialog dlg = new DeleteRepositoryConfirmDialog(
getShell(event), repository, projectsToDelete.size());
if (dlg.open() != Window.OK)
return;
deleteWorkingDir = dlg.shouldDeleteWorkingDir();
removeProjects = dlg.shouldRemoveProjects();
}
}
}
else {
if (!projectsToDelete.isEmpty()) {
final boolean[] confirmedCanceled = new boolean[] { false,
false };
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
confirmedCanceled[0] = confirmProjectDeletion(
projectsToDelete, event);
} catch (OperationCanceledException e) {
confirmedCanceled[1] = true;
}
}
});
if (confirmedCanceled[1])
return;
removeProjects = confirmedCanceled[0];
}
}
final boolean deleteWorkDir = deleteWorkingDir;
final boolean removeProj = removeProjects;
Job job = new WorkspaceJob(UIText.RemoveCommand_RemoveRepositoriesJob) {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage);
if (removeProj) {
// confirmed deletion
deleteProjects(delete, projectsToDelete,
monitor);
}
for (RepositoryNode node : selectedNodes) {
util.removeDir(node.getRepository().getDirectory());
}
if (delete) {
try {
deleteRepositoryContent(selectedNodes, deleteWorkDir);
} catch (IOException e) {
return Activator.createErrorStatus(e.getMessage(), e);
}
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
if (JobFamilies.REPOSITORY_DELETE.equals(family))
return true;
else
return super.belongsTo(family);
}
};
service.schedule(job);
}