1 11 package org.eclipse.team.internal.ui; 12 13 import java.util.HashMap ; 14 import java.util.HashSet ; 15 import java.util.Map ; 16 import java.util.Set ; 17 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.team.core.RepositoryProvider; 21 import org.eclipse.team.internal.core.TeamPlugin; 22 import org.eclipse.ui.IPluginContribution; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.activities.*; 25 26 32 public class TeamCapabilityHelper { 33 34 38 private Map providerIdToPluginId; 39 40 43 private static TeamCapabilityHelper singleton; 44 45 50 public static TeamCapabilityHelper getInstance() { 51 if (singleton == null) { 52 singleton = new TeamCapabilityHelper(); 53 } 54 return singleton; 55 } 56 57 61 private TeamCapabilityHelper() { 62 providerIdToPluginId = new HashMap (); 63 loadRepositoryProviderIds(); 64 65 IProject [] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); 67 IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport(); 68 for (int i = 0; i < projects.length; i++) { 69 try { 70 processProject(projects[i], workbenchActivitySupport); 71 } catch (CoreException e) { 72 } 74 } 75 } 76 77 80 public void loadRepositoryProviderIds() { 81 providerIdToPluginId.clear(); 82 IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.team.core.repository"); if (point != null) { 84 IExtension[] extensions = point.getExtensions(); 85 for (int i = 0; i < extensions.length; i++) { 86 IExtension extension = extensions[i]; 87 IConfigurationElement[] elements = extension.getConfigurationElements(); 88 for (int j = 0; j < elements.length; j++) { 89 IConfigurationElement element = elements[j]; 90 final String pluginId = extension.getNamespace(); 91 if (element.getName().equals(TeamPlugin.REPOSITORY_EXTENSION)) { 92 final String id = element.getAttribute("id"); if (id == null) { 94 continue; 96 } 97 providerIdToPluginId.put(id, new IPluginContribution() { 98 public String getLocalId() { 99 return id; 100 } 101 public String getPluginId() { 102 return pluginId; 103 } 104 }); 105 } 106 } 107 } 108 } 109 } 110 111 117 protected void processProject(IProject project, IWorkbenchActivitySupport workbenchActivitySupport) throws CoreException { 118 if (!project.isOpen()) 119 return; 120 String id = getProviderIdFor(project); 121 processRepositoryId(id, workbenchActivitySupport); 122 } 123 124 130 public void processRepositoryId(String id, IWorkbenchActivitySupport workbenchActivitySupport) { 131 if (id == null) 132 return; 133 IActivityManager activityManager = workbenchActivitySupport 134 .getActivityManager(); 135 Set activities = new HashSet (activityManager.getEnabledActivityIds()); 136 boolean changed = false; 137 138 IPluginContribution contribution = (IPluginContribution) providerIdToPluginId.get(id); 139 if (contribution == null) 140 return; IIdentifier identifier = activityManager.getIdentifier(WorkbenchActivityHelper.createUnifiedId(contribution)); 142 if (activities.addAll(identifier.getActivityIds())) { 143 changed = true; 144 } 145 146 if (changed) 147 workbenchActivitySupport.setEnabledActivityIds(activities); 148 } 149 150 160 public String getProviderIdFor(IProject project) throws CoreException { 161 if(project.isAccessible()) { 162 Object prop = project.getSessionProperty(TeamPlugin.PROVIDER_PROP_KEY); 164 if(prop != null && prop instanceof RepositoryProvider) { 165 RepositoryProvider provider = (RepositoryProvider) prop; 166 return provider.getID(); 167 } 168 return project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY); 170 } 171 return null; 172 } 173 } 174 | Popular Tags |