1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; 19 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; 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.core.synchronize.*; 24 import org.eclipse.team.internal.ccvs.core.CVSCompareSubscriber; 25 import org.eclipse.team.internal.ccvs.core.CVSTag; 26 import org.eclipse.team.internal.ccvs.ui.*; 27 import org.eclipse.team.internal.ccvs.ui.actions.ShowAnnotationAction; 28 import org.eclipse.team.internal.ccvs.ui.actions.ShowResourceInHistoryAction; 29 import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager; 30 import org.eclipse.team.internal.ui.Utils; 31 import org.eclipse.team.ui.TeamUI; 32 import org.eclipse.team.ui.synchronize.*; 33 34 public class CompareParticipant extends CVSParticipant implements IPropertyChangeListener { 35 36 public static final String CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_1"; public static final String NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_2"; 39 42 public class CompareParticipantActionContribution extends SynchronizePageActionGroup { 43 public void initialize(ISynchronizePageConfiguration configuration) { 44 super.initialize(configuration); 45 46 appendToGroup( 47 ISynchronizePageConfiguration.P_CONTEXT_MENU, 48 CONTEXT_MENU_CONTRIBUTION_GROUP, 49 new CompareRevertAction(configuration)); 50 51 if (!configuration.getSite().isModal()) { 52 ShowAnnotationAction showAnnotationAction = new ShowAnnotationAction(); 53 appendToGroup( 54 ISynchronizePageConfiguration.P_CONTEXT_MENU, 55 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP, 56 new CVSActionDelegateWrapper(showAnnotationAction, configuration)); 57 appendToGroup( 58 ISynchronizePageConfiguration.P_CONTEXT_MENU, 59 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP, 60 new CVSActionDelegateWrapper(new ShowResourceInHistoryAction(), configuration)); 61 } 62 } 63 } 64 65 private SyncInfoFilter contentComparison = new SyncInfoFilter() { 66 private SyncInfoFilter contentCompare = new SyncInfoFilter.ContentComparisonSyncInfoFilter(); 67 public boolean select(SyncInfo info, IProgressMonitor monitor) { 68 return !contentCompare.select(info, monitor); 70 } 71 }; 72 73 public CompareParticipant(CVSCompareSubscriber subscriber) { 74 setSubscriber(subscriber); 75 } 76 77 80 protected void setSubscriber(Subscriber subscriber) { 81 super.setSubscriber(subscriber); 82 if (CVSUIPlugin.getPlugin().getPluginPreferences().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) { 83 setSyncInfoFilter(contentComparison); 84 } 85 try { 86 ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(CVSCompareSubscriber.ID); 87 setInitializationData(descriptor); 88 CVSCompareSubscriber s = getCVSCompareSubscriber(); 89 setSecondaryId(s.getId().getLocalName()); 90 } catch (CoreException e) { 91 CVSUIPlugin.log(e); 92 } 93 CVSUIPlugin.getPlugin().getPluginPreferences().addPropertyChangeListener(this); 94 } 95 96 99 public String getName() { 100 return NLS.bind(CVSUIMessages.CompareParticipant_0, new String [] { getSubscriber().getName(), Utils.convertSelection(getSubscriber().roots()) }); 101 } 102 103 106 public static CompareParticipant getMatchingParticipant(IResource[] resources, CVSTag tag) { 107 ISynchronizeParticipantReference[] refs = TeamUI.getSynchronizeManager().getSynchronizeParticipants(); 108 for (int i = 0; i < refs.length; i++) { 109 ISynchronizeParticipantReference reference = refs[i]; 110 if (reference.getId().equals(CVSCompareSubscriber.ID)) { 111 try { 112 CompareParticipant p = (CompareParticipant) reference.getParticipant(); 113 if (p.matches(resources, tag)) { 114 return p; 115 } 116 } catch (TeamException e) { 117 continue; 118 } 119 } 120 } 121 return null; 122 } 123 124 132 protected boolean matches(IResource[] resources, CVSTag tag) { 133 CVSTag existingTag = getCVSCompareSubscriber().getTag(); 134 if (existingTag != null) { 136 IResource[] roots = getResources(); 137 Arrays.sort(resources, Utils.resourceComparator); 138 Arrays.sort(roots, Utils.resourceComparator); 139 if (Arrays.equals(resources, roots) && existingTag.equals(tag)) { 140 return true; 141 } 142 } 143 return false; 144 } 145 146 150 public CVSCompareSubscriber getCVSCompareSubscriber() { 151 return (CVSCompareSubscriber)getSubscriber(); 152 } 153 154 157 protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { 158 super.initializeConfiguration(configuration); 159 configuration.addMenuGroup( 160 ISynchronizePageConfiguration.P_CONTEXT_MENU, 161 CONTEXT_MENU_CONTRIBUTION_GROUP); 162 configuration.addMenuGroup( 163 ISynchronizePageConfiguration.P_CONTEXT_MENU, 164 NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP); 165 configuration.addActionContribution(new CompareParticipantActionContribution()); 166 } 167 168 171 public void dispose() { 172 super.dispose(); 173 CVSUIPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this); 174 getCVSCompareSubscriber().dispose(); 175 } 176 177 180 public void propertyChange(PropertyChangeEvent event) { 181 if (event.getProperty().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) { 182 if (CVSUIPlugin.getPlugin().getPluginPreferences().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) { 183 setSyncInfoFilter(contentComparison); 184 } else { 185 setSyncInfoFilter(new FastSyncInfoFilter()); 186 } 187 } 188 } 189 190 193 protected String getLongTaskName() { 194 return getName(); 195 } 196 197 200 protected String getShortTaskName() { 201 return CVSUIMessages.Participant_comparing; 202 } 203 204 207 protected CVSChangeSetCapability createChangeSetCapability() { 208 return new CVSChangeSetCapability() { 209 public ActiveChangeSetManager getActiveChangeSetManager() { 210 return CVSUIPlugin.getPlugin().getChangeSetManager(); 211 } 212 215 public boolean enableActiveChangeSetsFor(ISynchronizePageConfiguration configuration) { 216 return super.enableActiveChangeSetsFor(configuration) || 217 configuration.getComparisonType() == ISynchronizePageConfiguration.TWO_WAY; 218 } 219 }; 220 } 221 } 222 | Popular Tags |