1 12 package org.eclipse.team.internal.ccvs.ui.subscriber; 13 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.compare.CompareConfiguration; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jface.preference.PreferencePage; 21 import org.eclipse.jface.viewers.ILabelDecorator; 22 import org.eclipse.jface.window.Window; 23 import org.eclipse.team.core.TeamException; 24 import org.eclipse.team.core.diff.IDiff; 25 import org.eclipse.team.core.mapping.provider.ResourceDiffTree; 26 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 27 import org.eclipse.team.internal.ccvs.ui.*; 28 import org.eclipse.team.internal.ccvs.ui.actions.*; 29 import org.eclipse.team.internal.core.subscribers.*; 30 import org.eclipse.team.internal.ui.synchronize.*; 31 import org.eclipse.team.ui.TeamUI; 32 import org.eclipse.team.ui.synchronize.*; 33 import org.eclipse.ui.*; 34 35 public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipant implements IChangeSetProvider { 36 37 public static final String ID = "org.eclipse.team.cvs.ui.cvsworkspace-participant"; 39 43 public static final String TOOLBAR_CONTRIBUTION_GROUP = "toolbar_group_1"; 45 public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_1 = "context_group_1"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_2 = "context_group_2"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_3 = "context_group_3"; public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_4 = "context_group_4"; 50 private WorkspaceChangeSetCapability capability; 51 52 55 public class WorkspaceActionContribution extends SynchronizePageActionGroup { 56 private WorkspaceCommitAction commitToolbar; 57 private WorkspaceUpdateAction updateToolbar; 58 59 public void initialize(ISynchronizePageConfiguration configuration) { 60 super.initialize(configuration); 61 62 updateToolbar = new WorkspaceUpdateAction( 63 configuration, 64 getVisibleRootsSelectionProvider(), 65 "WorkspaceToolbarUpdateAction."); updateToolbar.setPromptBeforeUpdate(true); 67 appendToGroup( 68 ISynchronizePageConfiguration.P_TOOLBAR_MENU, 69 TOOLBAR_CONTRIBUTION_GROUP, 70 updateToolbar); 71 72 commitToolbar = new WorkspaceCommitAction( 73 configuration, 74 getVisibleRootsSelectionProvider(), 75 "WorkspaceToolbarCommitAction."); appendToGroup( 77 ISynchronizePageConfiguration.P_TOOLBAR_MENU, 78 TOOLBAR_CONTRIBUTION_GROUP, 79 commitToolbar); 80 81 appendToGroup( 82 ISynchronizePageConfiguration.P_CONTEXT_MENU, 83 CONTEXT_MENU_CONTRIBUTION_GROUP_1, 84 new WorkspaceUpdateAction(configuration)); 85 appendToGroup( 86 ISynchronizePageConfiguration.P_CONTEXT_MENU, 87 CONTEXT_MENU_CONTRIBUTION_GROUP_1, 88 new WorkspaceCommitAction(configuration)); 89 appendToGroup( 90 ISynchronizePageConfiguration.P_CONTEXT_MENU, 91 CONTEXT_MENU_CONTRIBUTION_GROUP_2, 92 new OverrideAndUpdateAction(configuration)); 93 appendToGroup( 94 ISynchronizePageConfiguration.P_CONTEXT_MENU, 95 CONTEXT_MENU_CONTRIBUTION_GROUP_2, 96 new OverrideAndCommitAction(configuration)); 97 appendToGroup( 98 ISynchronizePageConfiguration.P_CONTEXT_MENU, 99 CONTEXT_MENU_CONTRIBUTION_GROUP_2, 100 new ConfirmMergedAction(configuration)); 101 appendToGroup( 102 ISynchronizePageConfiguration.P_CONTEXT_MENU, 103 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 104 new CVSActionDelegateWrapper(new IgnoreAction(), configuration)); 105 if (!configuration.getSite().isModal()) { 106 appendToGroup( 107 ISynchronizePageConfiguration.P_CONTEXT_MENU, 108 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 109 new CreatePatchAction(configuration)); 110 appendToGroup( 111 ISynchronizePageConfiguration.P_CONTEXT_MENU, 112 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 113 new CVSActionDelegateWrapper(new BranchAction(), configuration)); 114 appendToGroup( 115 ISynchronizePageConfiguration.P_CONTEXT_MENU, 116 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 117 new CVSActionDelegateWrapper(new ShowAnnotationAction(), configuration)); 118 appendToGroup( 119 ISynchronizePageConfiguration.P_CONTEXT_MENU, 120 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 121 new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration)); 122 appendToGroup( 123 ISynchronizePageConfiguration.P_CONTEXT_MENU, 124 CONTEXT_MENU_CONTRIBUTION_GROUP_3, 125 new CVSActionDelegateWrapper(new SetKeywordSubstitutionAction(), configuration)); 126 } 127 appendToGroup( 128 ISynchronizePageConfiguration.P_CONTEXT_MENU, 129 CONTEXT_MENU_CONTRIBUTION_GROUP_4, 130 new RefreshDirtyStateAction(configuration)); 131 } 132 } 133 134 public class WorkspaceChangeSetCapability extends CVSChangeSetCapability { 135 138 public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, IDiff[] infos) { 139 ActiveChangeSet set = getActiveChangeSetManager().createSet(CVSUIMessages.WorkspaceChangeSetCapability_1, new IDiff[0]); 140 CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, getResources(infos), CommitSetDialog.NEW); 141 dialog.open(); 142 if (dialog.getReturnCode() != Window.OK) return null; 143 set.add(infos); 144 return set; 145 } 146 147 private IResource[] getResources(IDiff[] diffs) { 148 Set result = new HashSet (); 149 for (int i = 0; i < diffs.length; i++) { 150 IDiff diff = diffs[i]; 151 IResource resource = ResourceDiffTree.getResourceFor(diff); 152 if (resource != null) 153 result.add(resource); 154 } 155 return (IResource[]) result.toArray(new IResource[result.size()]); 156 } 157 158 161 public void editChangeSet(ISynchronizePageConfiguration configuration, ActiveChangeSet set) { 162 CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, set.getResources(), CommitSetDialog.EDIT); 163 dialog.open(); 164 if (dialog.getReturnCode() != Window.OK) return; 165 } 167 168 171 public ActiveChangeSetManager getActiveChangeSetManager() { 172 return CVSUIPlugin.getPlugin().getChangeSetManager(); 173 } 174 } 175 176 180 public WorkspaceSynchronizeParticipant() { 181 } 182 183 public WorkspaceSynchronizeParticipant(ISynchronizeScope scope) { 184 super(scope); 185 setSubscriber(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber()); 186 } 187 188 191 public void init(String secondaryId, IMemento memento) throws PartInitException { 192 super.init(secondaryId, memento); 193 setSubscriber(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber()); 194 } 195 196 199 protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { 200 super.initializeConfiguration(configuration); 201 ILabelDecorator labelDecorator = getLabelDecorator(configuration); 202 configuration.addLabelDecorator(labelDecorator); 203 configuration.addMenuGroup(ISynchronizePageConfiguration.P_TOOLBAR_MENU, TOOLBAR_CONTRIBUTION_GROUP); 204 configuration.addActionContribution(new WorkspaceActionContribution()); 205 configuration.setSupportedModes(ISynchronizePageConfiguration.ALL_MODES); 206 configuration.setMode(ISynchronizePageConfiguration.BOTH_MODE); 207 208 configuration.addMenuGroup( 211 ISynchronizePageConfiguration.P_CONTEXT_MENU, 212 CONTEXT_MENU_CONTRIBUTION_GROUP_1); 213 configuration.addMenuGroup( 214 ISynchronizePageConfiguration.P_CONTEXT_MENU, 215 CONTEXT_MENU_CONTRIBUTION_GROUP_2); 216 configuration.addMenuGroup( 217 ISynchronizePageConfiguration.P_CONTEXT_MENU, 218 CONTEXT_MENU_CONTRIBUTION_GROUP_3); 219 configuration.addMenuGroup( 220 ISynchronizePageConfiguration.P_CONTEXT_MENU, 221 CONTEXT_MENU_CONTRIBUTION_GROUP_4); 222 } 223 224 protected ILabelDecorator getLabelDecorator(ISynchronizePageConfiguration configuration) { 225 return new CVSParticipantLabelDecorator(configuration); 226 } 227 228 protected ISynchronizeParticipantDescriptor getDescriptor() { 229 return TeamUI.getSynchronizeManager().getParticipantDescriptor(ID); 230 } 231 232 235 public void prepareCompareInput(ISynchronizeModelElement element, CompareConfiguration config, IProgressMonitor monitor) throws TeamException { 236 monitor.beginTask(null, 100); 237 CVSParticipant.deriveBaseContentsFromLocal(element, Policy.subMonitorFor(monitor, 10)); 238 super.prepareCompareInput(element, config, Policy.subMonitorFor(monitor, 80)); 239 CVSParticipant.updateLabelsForCVS(element, config, Policy.subMonitorFor(monitor, 10)); 240 monitor.done(); 241 } 242 243 246 public PreferencePage[] getPreferencePages() { 247 return CVSParticipant.addCVSPreferencePages(super.getPreferencePages()); 248 } 249 250 253 public ChangeSetCapability getChangeSetCapability() { 254 if (capability == null) { 255 capability = new WorkspaceChangeSetCapability(); 256 } 257 return capability; 258 } 259 260 263 protected boolean isViewerContributionsSupported() { 264 return true; 265 } 266 267 public void refresh(IResource[] resources, IWorkbenchPartSite site) { 268 refresh(resources, getShortTaskName(), getLongTaskName(resources), site); 269 } 270 271 } 272 | Popular Tags |