PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/com.atlassian.connector.eclipse.crucible.ui/src/com/atlassian/connector/eclipse/internal/crucible/ui/wizards/ReviewWizard.java

https://github.com/spingel/mylyn-reviews
Java | 307 lines | 205 code | 58 blank | 44 comment | 54 complexity | 97ed91c7c4f2fc0645db442f24b70bf1 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2009 Atlassian and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Atlassian - initial API and implementation
  10. ******************************************************************************/
  11. package com.atlassian.connector.eclipse.internal.crucible.ui.wizards;
  12. import com.atlassian.connector.eclipse.internal.crucible.core.TaskRepositoryUtil;
  13. import com.atlassian.connector.eclipse.internal.crucible.ui.CrucibleUiPlugin;
  14. import com.atlassian.connector.eclipse.internal.crucible.ui.CrucibleUiUtil;
  15. import com.atlassian.connector.eclipse.team.ui.AtlassianTeamUiPlugin;
  16. import com.atlassian.connector.eclipse.team.ui.ICustomChangesetLogEntry;
  17. import com.atlassian.connector.eclipse.team.ui.ITeamUiResourceConnector;
  18. import com.atlassian.connector.eclipse.team.ui.LocalStatus;
  19. import com.atlassian.connector.eclipse.team.ui.TeamUiUtils;
  20. import com.atlassian.connector.eclipse.ui.commons.DecoratedResource;
  21. import com.atlassian.connector.eclipse.ui.commons.ResourceEditorBean;
  22. import com.atlassian.theplugin.commons.crucible.api.UploadItem;
  23. import com.atlassian.theplugin.commons.crucible.api.model.BasicProject;
  24. import com.atlassian.theplugin.commons.crucible.api.model.PermId;
  25. import com.atlassian.theplugin.commons.crucible.api.model.Review;
  26. import org.eclipse.core.resources.IResource;
  27. import org.eclipse.core.resources.ResourcesPlugin;
  28. import org.eclipse.core.runtime.CoreException;
  29. import org.eclipse.jface.dialogs.MessageDialog;
  30. import org.eclipse.jface.wizard.IWizardPage;
  31. import org.eclipse.jface.wizard.WizardPage;
  32. import org.eclipse.mylyn.internal.tasks.core.LocalTask;
  33. import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
  34. import org.eclipse.mylyn.tasks.core.TaskRepository;
  35. import org.eclipse.mylyn.tasks.ui.TasksUi;
  36. import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
  37. import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard;
  38. import org.eclipse.ui.INewWizard;
  39. import java.util.ArrayList;
  40. import java.util.Arrays;
  41. import java.util.Collection;
  42. import java.util.HashSet;
  43. import java.util.List;
  44. import java.util.Map;
  45. import java.util.Set;
  46. import java.util.SortedSet;
  47. /**
  48. * Wizard for creating a new review
  49. *
  50. * @author Thomas Ehrnhoefer
  51. * @author Pawel Niewiadomski
  52. * @author Jacek Jaroczynski
  53. */
  54. @SuppressWarnings("restriction")
  55. public class ReviewWizard extends NewTaskWizard implements INewWizard {
  56. public enum Type {
  57. ADD_CHANGESET, ADD_PATCH, ADD_WORKSPACE_PATCH, ADD_SCM_RESOURCES, ADD_UPLOAD_ITEMS, ADD_RESOURCES, ADD_COMMENT_TO_FILE;
  58. }
  59. private CrucibleReviewDetailsPage detailsPage;
  60. private Review crucibleReview;
  61. private SelectScmChangesetsPage addChangeSetsPage;
  62. private CrucibleAddPatchPage addPatchPage;
  63. // private WorkspacePatchSelectionPage addWorkspacePatchPage;
  64. private DefineRepositoryMappingsPage defineMappingPage;
  65. private ResourceSelectionPage resourceSelectionPage;
  66. private final Set<Type> types;
  67. private SortedSet<ICustomChangesetLogEntry> preselectedLogEntries;
  68. private String previousPatch;
  69. private String previousPatchRepository;
  70. private final List<IResource> selectedWorkspaceResources = new ArrayList<IResource>();
  71. private IResource[] previousWorkspaceSelection;
  72. private List<UploadItem> uploadItems;
  73. private List<ResourceEditorBean> versionedCommentsToAdd = new ArrayList<ResourceEditorBean>();
  74. private SelectChangesetsFromCruciblePage addChangeSetsFromCruciblePage;
  75. private ITeamUiResourceConnector selectedWorkspaceTeamConnector;
  76. public ReviewWizard(TaskRepository taskRepository, Set<Type> types) {
  77. super(taskRepository, null);
  78. setWindowTitle("New Crucible Review");
  79. setNeedsProgressMonitor(true);
  80. this.types = types;
  81. this.selectedWorkspaceResources.addAll(Arrays.asList((IResource[]) ResourcesPlugin.getWorkspace()
  82. .getRoot()
  83. .getProjects()));
  84. }
  85. public ReviewWizard(Review review, Set<Type> types) {
  86. this(CrucibleUiUtil.getCrucibleTaskRepository(review), types);
  87. this.crucibleReview = review;
  88. }
  89. public ReviewWizard(Review review, Type type) {
  90. this(review, new HashSet<Type>(Arrays.asList(type)));
  91. }
  92. @Override
  93. public void addPages() {
  94. if (types.contains(Type.ADD_CHANGESET)) {
  95. addChangeSetsFromCruciblePage = new SelectChangesetsFromCruciblePage(getTaskRepository(),
  96. preselectedLogEntries);
  97. addPage(addChangeSetsFromCruciblePage);
  98. }
  99. if (types.contains(Type.ADD_PATCH)) {
  100. addPatchPage = new CrucibleAddPatchPage(getTaskRepository());
  101. addPage(addPatchPage);
  102. }
  103. // pre-commit
  104. if (types.contains(Type.ADD_WORKSPACE_PATCH)) {
  105. // addWorkspacePatchPage = new WorkspacePatchSelectionPage(getTaskRepository(), selectedWorkspaceResources);
  106. // addPage(addWorkspacePatchPage);
  107. }
  108. // post-commit for editor selection
  109. if (types.contains(Type.ADD_SCM_RESOURCES)) {
  110. if (selectedWorkspaceResources.size() > 0 && selectedWorkspaceResources.get(0) != null) {
  111. // single SCM integration selection supported
  112. final ITeamUiResourceConnector teamConnector = AtlassianTeamUiPlugin.getDefault()
  113. .getTeamResourceManager()
  114. .getTeamConnector(selectedWorkspaceResources.get(0));
  115. if (teamConnector == null) {
  116. MessageDialog.openInformation(getShell(), CrucibleUiPlugin.PRODUCT_NAME,
  117. "Cannot find Atlassian SCM Integration for '" + selectedWorkspaceResources.get(0).getName()
  118. + "'.");
  119. } else {
  120. boolean missingMapping = false;
  121. Collection<String> scmPaths = new ArrayList<String>();
  122. // TODO use job below if there are plenty of resource (currently it is used for single resource)
  123. for (IResource resource : selectedWorkspaceResources) {
  124. try {
  125. LocalStatus status = teamConnector.getLocalRevision(resource);
  126. if (status.getScmPath() != null && status.getScmPath().length() > 0) {
  127. String scmPath = TeamUiUtils.getScmPath(resource, teamConnector);
  128. if (TaskRepositoryUtil.getMatchingSourceRepository(
  129. TaskRepositoryUtil.getScmRepositoryMappings(getTaskRepository()), scmPath) == null) {
  130. // we need to see mapping page
  131. missingMapping = true;
  132. scmPaths.add(scmPath);
  133. }
  134. }
  135. } catch (CoreException e) {
  136. // resource is probably not under version control
  137. // skip
  138. }
  139. }
  140. if (missingMapping) {
  141. defineMappingPage = new DefineRepositoryMappingsPage(scmPaths, getTaskRepository());
  142. addPage(defineMappingPage);
  143. }
  144. }
  145. }
  146. }
  147. // mixed review
  148. if (types.contains(Type.ADD_RESOURCES)) {
  149. resourceSelectionPage = new ResourceSelectionPage(getTaskRepository(), selectedWorkspaceTeamConnector,
  150. selectedWorkspaceResources);
  151. addPage(resourceSelectionPage);
  152. }
  153. // only add details page if review is not already existing
  154. if (crucibleReview == null) {
  155. detailsPage = new CrucibleReviewDetailsPage(getTaskRepository(), types.contains(Type.ADD_COMMENT_TO_FILE));
  156. addPage(detailsPage);
  157. }
  158. }
  159. @Override
  160. public boolean canFinish() {
  161. if (detailsPage != null) {
  162. return detailsPage.isPageComplete();
  163. }
  164. return super.canFinish();
  165. }
  166. @Override
  167. public boolean performFinish() {
  168. setErrorMessage(null);
  169. crucibleReview = detailsPage.getReview();
  170. LocalTask task = TasksUiInternal.createNewLocalTask("Review: " + crucibleReview.getSummary());
  171. crucibleReview.setPermId(new PermId(task.getTaskId()));
  172. if (detailsPage != null) {
  173. // save project selection
  174. final BasicProject selectedProject = detailsPage.getSelectedProject();
  175. CrucibleUiPlugin.getDefault().updateLastSelectedProject(getTaskRepository(),
  176. selectedProject != null ? selectedProject.getKey() : null);
  177. // save checkbox selections
  178. CrucibleUiPlugin.getDefault().updateAllowAnyoneOption(getTaskRepository(),
  179. detailsPage.isAllowAnyoneToJoin());
  180. CrucibleUiPlugin.getDefault().updateStartReviewOption(getTaskRepository(),
  181. detailsPage.isStartReviewImmediately());
  182. }
  183. if (addPatchPage != null) {
  184. String patchToAdd = addPatchPage.hasPatch() ? addPatchPage.getPatch() : null;
  185. String patchRepositoryToAdd = addPatchPage.hasPatch() ? addPatchPage.getPatchRepository() : null;
  186. if (patchToAdd != null && patchRepositoryToAdd != null && !patchToAdd.equals(previousPatch)
  187. && !patchRepositoryToAdd.equals(previousPatchRepository)) {
  188. // create patch review
  189. }
  190. }
  191. // if (addWorkspacePatchPage != null) {
  192. // final IResource[] selection = addWorkspacePatchPage.getSelection();
  193. //
  194. // if (selection != null && selection.length > 0 && !Arrays.equals(selection, previousWorkspaceSelection)
  195. // && addWorkspacePatchPage.getSelectedTeamResourceConnector() != null) {
  196. // // create pre-commit review
  197. // }
  198. // }
  199. if (addChangeSetsPage != null || addChangeSetsFromCruciblePage != null) {
  200. final Map<String, Set<String>> changesetsToAdd = addChangeSetsPage != null ? addChangeSetsPage.getSelectedChangesets()
  201. : addChangeSetsFromCruciblePage.getSelectedChangesets();
  202. if (changesetsToAdd != null && changesetsToAdd.size() > 0) {
  203. // create review from changeset
  204. }
  205. }
  206. if (types.contains(Type.ADD_SCM_RESOURCES)) {
  207. if (selectedWorkspaceResources != null) {
  208. // create review from editor selection (post-commit)
  209. }
  210. }
  211. if (types.contains(Type.ADD_UPLOAD_ITEMS)) {
  212. if (uploadItems.size() > 0) {
  213. // create review from editor selection (pre-commit)
  214. }
  215. }
  216. if (resourceSelectionPage != null && types.contains(Type.ADD_RESOURCES)) {
  217. final List<DecoratedResource> resources = resourceSelectionPage.getSelection();
  218. if (resources != null && resources.size() > 0) {
  219. // create review from workbench selection (post- and pre-commit)
  220. }
  221. }
  222. TasksUiUtil.openTask(task);
  223. TasksUi.getTaskActivityManager().activateTask(task);
  224. CrucibleUiPlugin.getDefault()
  225. .getActiveReviewManager()
  226. .reviewAdded(task.getRepositoryUrl(), task.getTaskId(), crucibleReview);
  227. return true;
  228. }
  229. private void setErrorMessage(String message) {
  230. IWizardPage page = getContainer().getCurrentPage();
  231. if (page instanceof WizardPage) {
  232. ((WizardPage) page).setErrorMessage(message != null ? message.replace("\n", " ") : null);
  233. }
  234. }
  235. public void setLogEntries(SortedSet<ICustomChangesetLogEntry> logEntries) {
  236. this.preselectedLogEntries = logEntries;
  237. }
  238. public void setRoots(ITeamUiResourceConnector teamConnector, List<IResource> list) {
  239. this.selectedWorkspaceResources.clear();
  240. this.selectedWorkspaceResources.addAll(list);
  241. this.selectedWorkspaceTeamConnector = teamConnector;
  242. }
  243. public void setUploadItems(List<UploadItem> uploadItems) {
  244. this.uploadItems = uploadItems;
  245. }
  246. public void setFilesCommentData(List<ResourceEditorBean> list) {
  247. this.versionedCommentsToAdd = list;
  248. }
  249. }