1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import org.eclipse.core.resources.mapping.ResourceMapping; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.jface.action.*; 16 import org.eclipse.jface.dialogs.MessageDialog; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.team.core.diff.IThreeWayDiff; 19 import org.eclipse.team.core.mapping.*; 20 import org.eclipse.team.core.mapping.provider.MergeContext; 21 import org.eclipse.team.core.mapping.provider.SynchronizationContext; 22 import org.eclipse.team.internal.ccvs.ui.*; 23 import org.eclipse.team.internal.ccvs.ui.actions.*; 24 import org.eclipse.team.internal.ccvs.ui.mappings.WorkspaceSubscriberContext.ChangeSetSubscriberScopeManager; 25 import org.eclipse.team.internal.ccvs.ui.subscriber.CVSActionDelegateWrapper; 26 import org.eclipse.team.internal.ui.TeamUIPlugin; 27 import org.eclipse.team.internal.ui.Utils; 28 import org.eclipse.team.internal.ui.mapping.MergeAllActionHandler; 29 import org.eclipse.team.internal.ui.synchronize.*; 30 import org.eclipse.team.ui.TeamUI; 31 import org.eclipse.team.ui.mapping.ITeamContentProviderManager; 32 import org.eclipse.team.ui.mapping.SynchronizationActionProvider; 33 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 34 import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipantActionGroup; 35 import org.eclipse.ui.IMemento; 36 import org.eclipse.ui.PartInitException; 37 38 public class WorkspaceModelParticipant extends 39 CVSModelSynchronizeParticipant implements IChangeSetProvider { 40 41 public static final String VIEWER_ID = "org.eclipse.team.cvs.ui.workspaceSynchronization"; 43 public static final String CONTEXT_MENU_UPDATE_GROUP_1 = "update"; public static final String CONTEXT_MENU_COMMIT_GROUP_1 = "commit"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_2 = "overrideActions"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_3 = "otherActions1"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_4 = "otherActions2"; 49 public static final String ID = "org.eclipse.team.cvs.ui.workspace-participant"; 51 private static final String CTX_CONSULT_CHANGE_SETS = "consultChangeSets"; 53 56 public class WorkspaceMergeActionGroup extends ModelSynchronizeParticipantActionGroup { 57 private WorkspaceCommitAction commitToolbar; 58 59 public void initialize(ISynchronizePageConfiguration configuration) { 60 configuration.setProperty(MERGE_ALL_ACTION_ID, new MergeAllActionHandler(configuration) { 61 protected String getJobName() { 62 String name = getConfiguration().getParticipant().getName(); 63 return NLS.bind(CVSUIMessages.WorkspaceModelParticipant_0, Utils.shortenText(SynchronizeView.MAX_NAME_LENGTH, name)); 64 } 65 66 protected boolean promptToUpdate() { 67 final IResourceDiffTree tree = getMergeContext().getDiffTree(); 68 if (tree.isEmpty()) { 69 return false; 70 } 71 final long count = tree.countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK) + tree.countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK); 72 if (count == 0) 73 return false; 74 final boolean[] result = new boolean[] {true}; 75 TeamUIPlugin.getStandardDisplay().syncExec(new Runnable () { 76 public void run() { 77 String sizeString = Long.toString(count); 78 String message = tree.size() > 1 ? NLS.bind(CVSUIMessages.UpdateAction_promptForUpdateSeveral, new String [] { sizeString }) : NLS.bind(CVSUIMessages.UpdateAction_promptForUpdateOne, new String [] { sizeString }); result[0] = MessageDialog.openQuestion(getConfiguration().getSite().getShell(), NLS.bind(CVSUIMessages.UpdateAction_promptForUpdateTitle, new String [] { sizeString }), message); 80 81 } 82 }); 83 return result[0]; 84 } 85 private IMergeContext getMergeContext() { 86 return ((IMergeContext)getConfiguration().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT)); 87 } 88 protected boolean needsToSaveDirtyEditors() { 89 int option = CVSUIPlugin.getPlugin().getPreferenceStore().getInt(ICVSUIConstants.PREF_SAVE_DIRTY_EDITORS); 90 return option != ICVSUIConstants.OPTION_NEVER; 91 } 92 protected boolean confirmSaveOfDirtyEditor() { 93 int option = CVSUIPlugin.getPlugin().getPreferenceStore().getInt(ICVSUIConstants.PREF_SAVE_DIRTY_EDITORS); 94 return option == ICVSUIConstants.OPTION_PROMPT; 95 } 96 }); 97 super.initialize(configuration); 98 99 int modes = configuration.getSupportedModes(); 100 if ((modes & (ISynchronizePageConfiguration.OUTGOING_MODE | ISynchronizePageConfiguration.BOTH_MODE)) != 0) { 101 appendToGroup( 102 ISynchronizePageConfiguration.P_CONTEXT_MENU, 103 CONTEXT_MENU_COMMIT_GROUP_1, 104 new CommitAction(configuration)); 105 106 commitToolbar = new WorkspaceCommitAction(configuration); 107 appendToGroup( 108 ISynchronizePageConfiguration.P_TOOLBAR_MENU, 109 MERGE_ACTION_GROUP, 110 commitToolbar); 111 117 appendToGroup( 118 ISynchronizePageConfiguration.P_CONTEXT_MENU, 119 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 120 new CVSActionDelegateWrapper(new IgnoreAction(), configuration)); 121 } 122 123 if (!configuration.getSite().isModal()) { 124 appendToGroup( 125 ISynchronizePageConfiguration.P_CONTEXT_MENU, 126 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 127 new CreatePatchAction(configuration)); 128 appendToGroup( 129 ISynchronizePageConfiguration.P_CONTEXT_MENU, 130 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 131 new CVSActionDelegateWrapper(new BranchAction(), configuration)); 132 appendToGroup( 133 ISynchronizePageConfiguration.P_CONTEXT_MENU, 134 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 135 new CVSActionDelegateWrapper(new ShowAnnotationAction(), configuration)); 136 appendToGroup( 137 ISynchronizePageConfiguration.P_CONTEXT_MENU, 138 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 139 new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration)); 140 appendToGroup( 141 ISynchronizePageConfiguration.P_CONTEXT_MENU, 142 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 143 new CVSActionDelegateWrapper(new SetKeywordSubstitutionAction(), configuration)); 144 } 145 } 146 147 150 protected void configureMergeAction(String mergeActionId, Action action) { 151 if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) { 152 Utils.initAction(action, "WorkspaceUpdateAction.", Policy.getActionBundle()); action.setId(ICVSUIConstants.CMD_UPDATE); 154 action.setActionDefinitionId(ICVSUIConstants.CMD_UPDATE); 155 } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) { 156 Utils.initAction(action, "OverrideAndUpdateAction.", Policy.getActionBundle()); } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) { 158 Utils.initAction(action, "ConfirmMergedAction.", Policy.getActionBundle()); } else if (mergeActionId == MERGE_ALL_ACTION_ID) { 160 Utils.initAction(action, "WorkspaceToolbarUpdateAction.", Policy.getActionBundle()); action.setId(ICVSUIConstants.CMD_UPDATE_ALL); 162 action.setActionDefinitionId(ICVSUIConstants.CMD_UPDATE_ALL); 163 } else { 164 super.configureMergeAction(mergeActionId, action); 165 } 166 } 167 168 protected void addToContextMenu(String mergeActionId, Action action, IMenuManager manager) { 169 IContributionItem group = null;; 170 if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) { 171 group = manager.find(CONTEXT_MENU_UPDATE_GROUP_1); 172 } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) { 173 group = manager.find(CONTEXT_MENU_CONTRIBUTION_GROUP_2); 174 } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) { 175 group = manager.find(CONTEXT_MENU_CONTRIBUTION_GROUP_2); 176 } else { 177 super.addToContextMenu(mergeActionId, action, manager); 178 return; 179 } 180 if (group != null) { 181 manager.appendToGroup(group.getId(), action); 182 } else { 183 manager.add(action); 184 } 185 } 186 } 187 188 private WorkspaceChangeSetCapability capability; 189 190 private boolean isConsultChangeSets; 191 192 public WorkspaceModelParticipant() { 193 } 194 195 public WorkspaceModelParticipant(SynchronizationContext context) { 196 super(context); 197 try { 198 setInitializationData(TeamUI.getSynchronizeManager().getParticipantDescriptor("org.eclipse.team.cvs.ui.workspace-participant")); } catch (CoreException e) { 200 TeamUIPlugin.log(e); 201 } 202 setSecondaryId(Long.toString(System.currentTimeMillis())); 203 isConsultChangeSets = isConsultChangeSets(context.getScopeManager()); 204 } 205 206 209 protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { 210 configuration.setProperty(ISynchronizePageConfiguration.P_VIEWER_ID, VIEWER_ID); 211 super.initializeConfiguration(configuration); 212 } 213 214 217 protected ModelSynchronizeParticipantActionGroup createMergeActionGroup() { 218 return new WorkspaceMergeActionGroup(); 219 } 220 221 224 protected MergeContext restoreContext(ISynchronizationScopeManager manager) { 225 return WorkspaceSubscriberContext.createContext(manager, ISynchronizationContext.THREE_WAY); 226 } 227 228 231 protected ISynchronizationScopeManager createScopeManager(ResourceMapping[] mappings) { 232 return WorkspaceSubscriberContext.createWorkspaceScopeManager(mappings, true, isConsultChangeSets); 233 } 234 235 public ChangeSetCapability getChangeSetCapability() { 236 if (capability == null) { 237 capability = new WorkspaceChangeSetCapability(); 238 } 239 return capability; 240 } 241 242 public void saveState(IMemento memento) { 243 super.saveState(memento); 244 memento.putString(CTX_CONSULT_CHANGE_SETS, Boolean.toString(isConsultChangeSets)); 245 } 246 247 public void init(String secondaryId, IMemento memento) throws PartInitException { 248 try { 249 String consult = memento.getString(CTX_CONSULT_CHANGE_SETS); 250 if (consult != null) 251 isConsultChangeSets = Boolean.valueOf(consult).booleanValue(); 252 } finally { 253 super.init(secondaryId, memento); 254 } 255 } 256 257 private boolean isConsultChangeSets(ISynchronizationScopeManager manager) { 258 if (manager instanceof ChangeSetSubscriberScopeManager) { 259 ChangeSetSubscriberScopeManager man = (ChangeSetSubscriberScopeManager) manager; 260 return man.isConsultSets(); 261 } 262 return false; 263 } 264 265 } 266 | Popular Tags |