1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.mapping.ResourceMapping; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.RepositoryProvider; 20 import org.eclipse.team.core.RepositoryProviderType; 21 import org.eclipse.team.internal.ui.Utils; 22 import org.eclipse.team.internal.ui.registry.TeamDecoratorDescription; 23 import org.eclipse.team.internal.ui.registry.TeamDecoratorManager; 24 import org.eclipse.team.ui.mapping.*; 25 import org.eclipse.ui.PlatformUI; 26 27 39 public abstract class TeamStateProvider implements ITeamStateProvider { 40 41 private ListenerList listeners = new ListenerList(ListenerList.IDENTITY); 42 43 51 public boolean isDecorationEnabled(Object element) { 52 ResourceMapping mapping = Utils.getResourceMapping(element); 53 if (mapping != null) { 54 IProject[] projects = mapping.getProjects(); 55 return internalIsDecorationEnabled(projects); 56 } 57 return false; 58 } 59 60 68 public int getDecoratedStateMask(Object element) { 69 ResourceMapping mapping = Utils.getResourceMapping(element); 70 if (mapping != null) { 71 IProject[] projects = mapping.getProjects(); 72 return internalGetDecoratedStateMask(projects); 73 } 74 return 0; 75 } 76 77 80 public void addDecoratedStateChangeListener(ITeamStateChangeListener listener) { 81 listeners.add(listener); 82 } 83 84 87 public void removeDecoratedStateChangeListener(ITeamStateChangeListener listener) { 88 listeners.remove(listener); 89 } 90 91 95 protected final void fireStateChangeEvent(final ITeamStateChangeEvent event) { 96 Object [] allListeners = listeners.getListeners(); 97 for (int i = 0; i < allListeners.length; i++) { 98 final ITeamStateChangeListener listener = (ITeamStateChangeListener)allListeners[i]; 99 SafeRunner.run(new ISafeRunnable() { 100 public void run() throws Exception { 101 listener.teamStateChanged(event); 102 } 103 public void handleException(Throwable exception) { 104 } 106 }); 107 } 108 } 109 110 private int internalGetDecoratedStateMask(IProject[] projects) { 111 int stateMask = 0; 112 String [] providerIds = getProviderIds(projects); 113 for (int i = 0; i < providerIds.length; i++) { 114 String providerId = providerIds[i]; 115 stateMask |= internalGetDecoratedStateMask(providerId); 116 } 117 return stateMask; 118 } 119 120 private int internalGetDecoratedStateMask(String providerId) { 121 TeamDecoratorDescription decoratorDescription = TeamDecoratorManager 122 .getInstance().getDecoratorDescription(providerId); 123 if (decoratorDescription != null) 124 return decoratorDescription.getDecoratedDirectionFlags(); 125 return 0; 126 } 127 128 private String [] getProviderIds(IProject[] projects) { 129 Set providerIds = new HashSet (); 130 for (int i = 0; i < projects.length; i++) { 131 IProject project = projects[i]; 132 String id = getProviderId(project); 133 if (id != null) 134 providerIds.add(id); 135 } 136 return (String []) providerIds.toArray(new String [providerIds.size()]); 137 } 138 139 private String getProviderId(IProject project) { 140 RepositoryProvider provider = RepositoryProvider.getProvider(project); 141 if (provider != null) 142 return provider.getID(); 143 return null; 144 } 145 146 private boolean internalIsDecorationEnabled(IProject[] projects) { 147 String [] providerIds = getProviderIds(projects); 148 for (int i = 0; i < providerIds.length; i++) { 149 String providerId = providerIds[i]; 150 if (internalIsDecorationEnabled(providerId)) { 151 return true; 152 } 153 } 154 return false; 155 } 156 157 private boolean internalIsDecorationEnabled(String providerId) { 158 String decoratorId = getDecoratorId(providerId); 159 if (decoratorId != null) { 160 return PlatformUI.getWorkbench().getDecoratorManager().getEnabled( 161 decoratorId); 162 } 163 return false; 164 } 165 166 private String getDecoratorId(String providerId) { 167 TeamDecoratorDescription decoratorDescription = TeamDecoratorManager 168 .getInstance().getDecoratorDescription(providerId); 169 if (decoratorDescription != null) 170 return decoratorDescription.getDecoratorId(); 171 return null; 172 } 173 174 } 175 | Popular Tags |