1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.TeamException; 22 import org.eclipse.team.core.subscribers.Subscriber; 23 import org.eclipse.team.internal.ccvs.core.*; 24 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 25 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 26 import org.eclipse.team.internal.ccvs.ui.actions.ShowAnnotationAction; 27 import org.eclipse.team.internal.ccvs.ui.actions.ShowResourceInHistoryAction; 28 import org.eclipse.team.internal.ui.Utils; 29 import org.eclipse.team.ui.TeamUI; 30 import org.eclipse.team.ui.synchronize.*; 31 import org.eclipse.ui.IMemento; 32 import org.eclipse.ui.PartInitException; 33 34 public class MergeSynchronizeParticipant extends CVSParticipant { 35 36 40 public static final String TOOLBAR_CONTRIBUTION_GROUP = "toolbar_group"; 42 public static final String CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_1"; public static final String NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_2"; 45 private final static String CTX_ROOT = "root"; private final static String CTX_ROOT_PATH = "root_resource"; private final static String CTX_START_TAG = "start_tag"; private final static String CTX_START_TAG_TYPE = "start_tag_type"; private final static String CTX_END_TAG = "end_tag"; private final static String CTX_END_TAG_TYPE = "end_tag_type"; 52 55 public class MergeParticipantActionContribution extends SynchronizePageActionGroup { 56 private MergeUpdateAction updateAction; 57 public void initialize(ISynchronizePageConfiguration configuration) { 58 super.initialize(configuration); 59 60 updateAction = new MergeUpdateAction( 61 configuration, 62 getVisibleRootsSelectionProvider(), 63 "WorkspaceToolbarUpdateAction."); updateAction.setPromptBeforeUpdate(true); 65 appendToGroup( 66 ISynchronizePageConfiguration.P_TOOLBAR_MENU, 67 TOOLBAR_CONTRIBUTION_GROUP, 68 updateAction); 69 70 appendToGroup( 71 ISynchronizePageConfiguration.P_CONTEXT_MENU, 72 CONTEXT_MENU_CONTRIBUTION_GROUP, 73 new MergeUpdateAction(configuration)); 74 appendToGroup( 75 ISynchronizePageConfiguration.P_CONTEXT_MENU, 76 CONTEXT_MENU_CONTRIBUTION_GROUP, 77 new ConfirmMergedAction(configuration)); 78 79 if (!configuration.getSite().isModal()) { 80 appendToGroup( 81 ISynchronizePageConfiguration.P_CONTEXT_MENU, 82 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP, 83 new CVSActionDelegateWrapper(new ShowAnnotationAction(), configuration)); 84 appendToGroup( 85 ISynchronizePageConfiguration.P_CONTEXT_MENU, 86 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP, 87 new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration)); 88 } 89 90 } 91 } 92 93 public MergeSynchronizeParticipant() { 94 super(); 95 } 96 97 public MergeSynchronizeParticipant(CVSMergeSubscriber subscriber) { 98 setSubscriber(subscriber); 99 } 100 101 104 public void setSubscriber(Subscriber subscriber) { 105 super.setSubscriber(subscriber); 106 try { 107 ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(CVSMergeSubscriber.ID); 108 setInitializationData(descriptor); 109 CVSMergeSubscriber s = (CVSMergeSubscriber)getSubscriber(); 110 setSecondaryId(s.getId().getLocalName()); 111 } catch (CoreException e) { 112 CVSUIPlugin.log(e); 113 } 114 } 115 116 119 public void init(String secondayId, IMemento memento) throws PartInitException { 120 super.init(secondayId, memento); 121 if(memento != null) { 122 ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(CVSMergeSubscriber.ID); 123 String qualifier = descriptor.getId(); 124 String localname = secondayId; 125 if(qualifier == null || localname == null) { 126 throw new PartInitException(CVSUIMessages.MergeSynchronizeParticipant_8); 127 } 128 try { 129 setSubscriber(read(new QualifiedName(qualifier, localname), memento)); 130 } catch (CVSException e) { 131 throw new PartInitException(CVSUIMessages.MergeSynchronizeParticipant_9, e); 132 } 133 } 134 } 135 136 139 public void saveState(IMemento memento) { 140 super.saveState(memento); 141 CVSMergeSubscriber s = (CVSMergeSubscriber)getSubscriber(); 142 write(s, memento); 143 } 144 145 148 public void dispose() { 149 super.dispose(); 150 if(TeamUI.getSynchronizeManager().get(getId(), getSecondaryId()) == null) { 151 flushStateCache(); 154 } 155 } 156 157 160 public String getName() { 161 return NLS.bind(CVSUIMessages.CompareParticipant_0, new String [] { ((CVSMergeSubscriber)getSubscriber()).getName(), Utils.convertSelection(getSubscriber().roots()) }); 162 } 163 164 167 protected CVSTag getStartTag() { 168 return ((CVSMergeSubscriber)getSubscriber()).getStartTag(); 169 } 170 171 174 protected CVSTag getEndTag() { 175 return ((CVSMergeSubscriber)getSubscriber()).getEndTag(); 176 } 177 178 181 public static MergeSynchronizeParticipant getMatchingParticipant(IResource[] resources, CVSTag startTag, CVSTag endTag) { 182 ISynchronizeParticipantReference[] refs = TeamUI.getSynchronizeManager().getSynchronizeParticipants(); 183 for (int i = 0; i < refs.length; i++) { 184 ISynchronizeParticipantReference reference = refs[i]; 185 if (reference.getId().equals(CVSMergeSubscriber.ID)) { 186 MergeSynchronizeParticipant p; 187 try { 188 p = (MergeSynchronizeParticipant) reference.getParticipant(); 189 } catch (TeamException e) { 190 continue; 191 } 192 IResource[] roots = p.getResources(); 193 Arrays.sort(resources, Utils.resourceComparator); 194 Arrays.sort(roots, Utils.resourceComparator); 195 if (Arrays.equals(resources, roots) && p.getStartTag().equals(startTag) && p.getEndTag().equals(endTag)) { 196 return p; 197 } 198 } 199 } 200 return null; 201 } 202 203 private void write(CVSMergeSubscriber s, IMemento memento) { 204 CVSTag start = s.getStartTag(); 206 CVSTag end = s.getEndTag(); 207 memento.putString(CTX_START_TAG, start.getName()); 208 memento.putInteger(CTX_START_TAG_TYPE, start.getType()); 209 memento.putString(CTX_END_TAG, end.getName()); 210 memento.putInteger(CTX_END_TAG_TYPE, end.getType()); 211 212 IResource[] roots = s.roots(); 214 for (int i = 0; i < roots.length; i++) { 215 IResource resource = roots[i]; 216 IMemento rootNode = memento.createChild(CTX_ROOT); 217 rootNode.putString(CTX_ROOT_PATH, resource.getFullPath().toString()); 218 } 219 } 220 221 private CVSMergeSubscriber read(QualifiedName id, IMemento memento) throws CVSException { 222 CVSTag start = new CVSTag(memento.getString(CTX_START_TAG), memento.getInteger(CTX_START_TAG_TYPE).intValue()); CVSTag end = new CVSTag(memento.getString(CTX_END_TAG), memento.getInteger(CTX_END_TAG_TYPE).intValue()); 225 IMemento[] rootNodes = memento.getChildren(CTX_ROOT); 226 if(rootNodes == null || rootNodes.length == 0) { 227 throw new CVSException(NLS.bind(CVSUIMessages.MergeSynchronizeParticipant_10, new String [] { id.toString() })); 228 } 229 230 List resources = new ArrayList (); 231 for (int i = 0; i < rootNodes.length; i++) { 232 IMemento rootNode = rootNodes[i]; 233 IPath path = new Path(rootNode.getString(CTX_ROOT_PATH)); 234 IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path, true ); 235 if(resource != null) { 236 resources.add(resource); 237 } else { 238 CVSProviderPlugin.log(IStatus.INFO, NLS.bind(CVSUIMessages.MergeSynchronizeParticipant_11, new String [] { path.toString() }), null); 240 } 241 } 242 if(resources.isEmpty()) { 243 throw new CVSException(NLS.bind(CVSUIMessages.MergeSynchronizeParticipant_12, new String [] { id.toString() })); 244 } 245 IResource[] roots = (IResource[]) resources.toArray(new IResource[resources.size()]); 246 return new CVSMergeSubscriber(id, roots, start, end); 247 } 248 249 private void flushStateCache() { 250 ((CVSMergeSubscriber)getSubscriber()).cancel(); 251 } 252 253 256 protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { 257 super.initializeConfiguration(configuration); 258 configuration.addMenuGroup(ISynchronizePageConfiguration.P_TOOLBAR_MENU, TOOLBAR_CONTRIBUTION_GROUP); 259 configuration.addMenuGroup( 260 ISynchronizePageConfiguration.P_CONTEXT_MENU, 261 CONTEXT_MENU_CONTRIBUTION_GROUP); 262 configuration.addMenuGroup( 263 ISynchronizePageConfiguration.P_CONTEXT_MENU, 264 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP); 265 configuration.setSupportedModes(ISynchronizePageConfiguration.INCOMING_MODE | ISynchronizePageConfiguration.CONFLICTING_MODE); 266 configuration.setMode(ISynchronizePageConfiguration.INCOMING_MODE); 267 configuration.addActionContribution(new MergeParticipantActionContribution()); 268 } 269 270 273 protected String getLongTaskName() { 274 return getName(); 275 } 276 277 280 protected String getShortTaskName() { 281 return CVSUIMessages.Participant_merging; 282 } 283 284 protected CVSChangeSetCapability createChangeSetCapability() { 285 return null; 287 } 288 } 289 | Popular Tags |