PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/com.atlassian.connector.eclipse.crucible.ui/src/com/atlassian/connector/eclipse/internal/crucible/ui/CrucibleUiPlugin.java

https://github.com/spingel/mylyn-reviews
Java | 222 lines | 131 code | 50 blank | 41 comment | 15 complexity | c1522706dffe45386e96effc0c44eaf0 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;
  12. import com.atlassian.connector.eclipse.internal.crucible.core.client.CrucibleClient;
  13. import com.atlassian.connector.eclipse.ui.commons.ResourceSelectionTree.TreeViewMode;
  14. import org.eclipse.jface.dialogs.IDialogSettings;
  15. import org.eclipse.jface.dialogs.MessageDialogWithToggle;
  16. import org.eclipse.mylyn.tasks.core.TaskRepository;
  17. import org.eclipse.mylyn.tasks.ui.TasksUi;
  18. import org.eclipse.ui.plugin.AbstractUIPlugin;
  19. import org.osgi.framework.BundleContext;
  20. /**
  21. * The activator class controls the plug-in life cycle
  22. *
  23. * @author Shawn Minto
  24. */
  25. public class CrucibleUiPlugin extends AbstractUIPlugin {
  26. // The plug-in ID
  27. public static final String PLUGIN_ID = "com.atlassian.connector.eclipse.crucible.ui";
  28. public static final String REVIEW_PERSPECTIVE_ID = PLUGIN_ID + ".reviewPerspective";
  29. public static final String COMMENT_VIEW_ID = PLUGIN_ID + ".commentView";
  30. public static final String EXPLORER_VIEW_ID = PLUGIN_ID + ".explorerView";
  31. public static final String PRODUCT_NAME = "Atlassian Crucible Connector";
  32. private static final String DEFAULT_PROJECT = "defaultProject";
  33. private static final String ALLOW_ANYONE_TO_JOIN = "allowAnyoneToJoin";
  34. private static final String START_REVIEW = "startReview";
  35. // The shared instance
  36. private static CrucibleUiPlugin plugin;
  37. private static CrucibleClient client;
  38. private ActiveReviewManager activeReviewManager;
  39. private SwitchingPerspectiveReviewActivationListener switchingPerspectivesListener;
  40. private AvatarImages avatarImages;
  41. /**
  42. * The constructor
  43. */
  44. public CrucibleUiPlugin() {
  45. }
  46. /*
  47. * (non-Javadoc)
  48. *
  49. * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
  50. */
  51. @Override
  52. public void start(BundleContext context) throws Exception {
  53. super.start(context);
  54. plugin = this;
  55. switchingPerspectivesListener = new SwitchingPerspectiveReviewActivationListener();
  56. activeReviewManager = new ActiveReviewManager(true);
  57. activeReviewManager.addReviewActivationListener(switchingPerspectivesListener);
  58. avatarImages = new AvatarImages();
  59. enableActiveReviewManager();
  60. plugin.getPreferenceStore().setDefault(CrucibleUiConstants.PREFERENCE_ACTIVATE_REVIEW,
  61. MessageDialogWithToggle.PROMPT);
  62. }
  63. /*
  64. * (non-Javadoc)
  65. *
  66. * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
  67. */
  68. @Override
  69. public void stop(BundleContext context) throws Exception {
  70. disableActiveReviewManager();
  71. activeReviewManager.dispose();
  72. activeReviewManager = null;
  73. avatarImages.dispose();
  74. avatarImages = null;
  75. plugin = null;
  76. super.stop(context);
  77. }
  78. /**
  79. * Returns the shared instance
  80. *
  81. * @return the shared instance
  82. */
  83. public static CrucibleUiPlugin getDefault() {
  84. return plugin;
  85. }
  86. public ActiveReviewManager getActiveReviewManager() {
  87. return activeReviewManager;
  88. }
  89. /**
  90. * Method for testing purposes
  91. */
  92. public void disableActiveReviewManager() {
  93. if (activeReviewManager != null) {
  94. TasksUi.getTaskActivityManager().removeActivationListener(activeReviewManager);
  95. }
  96. }
  97. /**
  98. * Method for testing purposes
  99. */
  100. public void enableActiveReviewManager() {
  101. if (activeReviewManager != null) {
  102. TasksUi.getTaskActivityManager().addActivationListener(activeReviewManager);
  103. }
  104. }
  105. public boolean getPreviousChangesetReviewSelection() {
  106. return plugin.getPreferenceStore().getBoolean(CrucibleUiConstants.PREVIOUS_CHANGESET_REVIEW_SELECTION);
  107. }
  108. public boolean getPreviousPatchReviewSelection() {
  109. return plugin.getPreferenceStore().getBoolean(CrucibleUiConstants.PREVIOUS_PATCH_REVIEW_SELECTION);
  110. }
  111. public boolean getPreviousWorkspacePatchReviewSelection() {
  112. return plugin.getPreferenceStore().getBoolean(CrucibleUiConstants.PREVIOUS_WORKSPACE_PATCH_REVIEW_SELECTION);
  113. }
  114. public void setPreviousChangesetReviewSelection(boolean value) {
  115. plugin.getPreferenceStore().setValue(CrucibleUiConstants.PREVIOUS_CHANGESET_REVIEW_SELECTION, value);
  116. }
  117. public void setPreviousPatchReviewSelection(boolean value) {
  118. plugin.getPreferenceStore().setValue(CrucibleUiConstants.PREVIOUS_PATCH_REVIEW_SELECTION, value);
  119. }
  120. public void setPreviousWorkspacePatchReviewSelection(boolean value) {
  121. plugin.getPreferenceStore().setValue(CrucibleUiConstants.PREVIOUS_WORKSPACE_PATCH_REVIEW_SELECTION, value);
  122. }
  123. public TreeViewMode getResourcesTreeViewMode() {
  124. int mode = plugin.getPreferenceStore().getInt(CrucibleUiConstants.PREFERENCE_RESOURCE_TREE_VIEW_MODE);
  125. for (TreeViewMode treeMode : TreeViewMode.values()) {
  126. if (treeMode.ordinal() == mode) {
  127. return treeMode;
  128. }
  129. }
  130. return TreeViewMode.MODE_COMPRESSED_FOLDERS;
  131. }
  132. public void setResourcesTreeViewMode(TreeViewMode mode) {
  133. plugin.getPreferenceStore().setValue(CrucibleUiConstants.PREFERENCE_RESOURCE_TREE_VIEW_MODE, mode.ordinal());
  134. }
  135. public IDialogSettings getDialogSettingsSection(String name) {
  136. IDialogSettings dialogSettings = getDialogSettings();
  137. IDialogSettings section = dialogSettings.getSection(name);
  138. if (section == null) {
  139. section = dialogSettings.addNewSection(name);
  140. }
  141. return section;
  142. }
  143. public AvatarImages getAvatarsCache() {
  144. return this.avatarImages;
  145. }
  146. public void updateLastSelectedProject(TaskRepository repository, String projectKey) {
  147. repository.setProperty(DEFAULT_PROJECT, projectKey);
  148. }
  149. public String getLastSelectedProjectKey(TaskRepository repository) {
  150. return repository.getProperty(DEFAULT_PROJECT);
  151. }
  152. public boolean getAllowAnyoneOption(TaskRepository repository) {
  153. final String prop = repository.getProperty(ALLOW_ANYONE_TO_JOIN);
  154. return prop != null && Boolean.valueOf(prop);
  155. }
  156. public void updateAllowAnyoneOption(TaskRepository taskRepository, boolean allowAnyone) {
  157. taskRepository.setProperty(ALLOW_ANYONE_TO_JOIN, String.valueOf(allowAnyone));
  158. }
  159. public boolean getStartReviewOption(TaskRepository repository) {
  160. final String prop = repository.getProperty(START_REVIEW);
  161. return prop != null && Boolean.valueOf(prop);
  162. }
  163. public void updateStartReviewOption(TaskRepository taskRepository, boolean startReview) {
  164. taskRepository.setProperty(START_REVIEW, String.valueOf(startReview));
  165. }
  166. public static CrucibleClient getClient(TaskRepository taskRepository) {
  167. if (client == null) {
  168. client = new CrucibleClient();
  169. }
  170. return client;
  171. }
  172. }