1 11 package org.eclipse.team.ui.mapping; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.core.commands.IHandler; 18 import org.eclipse.jface.action.IContributionItem; 19 import org.eclipse.jface.action.IMenuManager; 20 import org.eclipse.team.core.mapping.ISynchronizationContext; 21 import org.eclipse.team.internal.ui.mapping.CommonMenuManager; 22 import org.eclipse.team.internal.ui.synchronize.actions.OpenWithActionGroup; 23 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 24 import org.eclipse.ui.*; 25 import org.eclipse.ui.actions.ActionContext; 26 import org.eclipse.ui.navigator.*; 27 28 46 public class SynchronizationActionProvider extends CommonActionProvider { 47 48 52 public static final String MERGE_ACTION_ID = "org.eclipse.team.ui.mergeAction"; 54 58 public static final String OVERWRITE_ACTION_ID = "org.eclipse.team.ui.overwriteAction"; 60 64 public static final String MARK_AS_MERGE_ACTION_ID = "org.eclipse.team.ui.markAsMergeAction"; 66 private Map handlers = new HashMap (); 67 private OpenWithActionGroup openWithActions; 68 69 public void init(ICommonActionExtensionSite site) { 70 super.init(site); 71 initialize(); 72 } 73 74 83 protected void initialize() { 84 initializeOpenActions(); 85 } 86 87 96 protected void initializeOpenActions() { 97 ICommonViewerSite cvs = getActionSite().getViewSite(); 98 ISynchronizePageConfiguration configuration = getSynchronizePageConfiguration(); 99 if (cvs instanceof ICommonViewerWorkbenchSite && configuration != null) { 100 ICommonViewerWorkbenchSite cvws = (ICommonViewerWorkbenchSite) cvs; 101 final IWorkbenchPartSite wps = cvws.getSite(); 102 if (wps instanceof IViewSite) { 103 openWithActions = new OpenWithActionGroup(configuration, false); 104 } 105 } 106 } 107 108 114 protected final ISynchronizePageConfiguration getSynchronizePageConfiguration() { 115 return (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION); 116 } 117 118 124 protected final IExtensionStateModel getExtensionStateModel() { 125 return getActionSite().getExtensionStateModel(); 126 } 127 128 134 protected final ISynchronizationContext getSynchronizationContext() { 135 return (ISynchronizationContext)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT); 136 } 137 138 145 protected void registerHandler(String actionId, IHandler handler) { 146 handlers.put(actionId, handler); 147 } 148 149 152 public void fillContextMenu(IMenuManager menu) { 153 super.fillContextMenu(menu); 154 if (menu instanceof CommonMenuManager) { 155 CommonMenuManager manager = (CommonMenuManager) menu; 156 for (Iterator iter = handlers.keySet().iterator(); iter.hasNext();) { 157 String actionId = (String ) iter.next(); 158 manager.registerHandler(actionId, (IHandler)handlers.get(actionId)); 159 } 160 } 161 final IContributionItem fileGroup = menu.find(ISynchronizePageConfiguration.FILE_GROUP); 162 if (openWithActions != null && fileGroup != null) { 163 openWithActions.fillContextMenu(menu, fileGroup.getId()); 164 } 165 } 166 167 170 public void fillActionBars(IActionBars actionBars) { 171 super.fillActionBars(actionBars); 172 if (openWithActions != null) openWithActions.fillActionBars(actionBars); 173 } 174 175 public void updateActionBars() { 176 super.updateActionBars(); 177 if (openWithActions != null) openWithActions.updateActionBars(); 178 } 179 180 public void setContext(ActionContext context) { 181 super.setContext(context); 182 if (openWithActions != null) openWithActions.setContext(context); 183 } 184 185 188 public void dispose() { 189 super.dispose(); 190 if (openWithActions != null) openWithActions.dispose(); 191 for (Iterator iter = handlers.values().iterator(); iter.hasNext();) { 192 IHandler handler = (IHandler) iter.next(); 193 if (handler instanceof MergeActionHandler) { 194 MergeActionHandler mah = (MergeActionHandler) handler; 195 mah.dispose(); 196 } 197 } 198 } 199 200 205 public ICommonActionExtensionSite getExtensionSite() { 206 return getActionSite(); 207 } 208 209 } 210 | Popular Tags |