1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import org.eclipse.compare.CompareConfiguration; 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.preference.PreferencePage; 17 import org.eclipse.jface.viewers.ILabelDecorator; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.synchronize.SyncInfo; 21 import org.eclipse.team.core.variants.IResourceVariant; 22 import org.eclipse.team.internal.ccvs.core.*; 23 import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; 24 import org.eclipse.team.internal.ccvs.ui.*; 25 import org.eclipse.team.internal.ccvs.ui.Policy; 26 import org.eclipse.team.internal.ui.IPreferenceIds; 27 import org.eclipse.team.internal.ui.TeamUIPlugin; 28 import org.eclipse.team.internal.ui.synchronize.ChangeSetCapability; 29 import org.eclipse.team.internal.ui.synchronize.IChangeSetProvider; 30 import org.eclipse.team.ui.synchronize.*; 31 32 35 public class CVSParticipant extends SubscriberParticipant implements IChangeSetProvider { 36 37 private CVSChangeSetCapability capability; 38 39 42 protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { 43 super.initializeConfiguration(configuration); 44 ILabelDecorator labelDecorator = new CVSParticipantLabelDecorator(configuration); 46 configuration.addLabelDecorator(labelDecorator); 47 } 48 49 52 public void prepareCompareInput(ISynchronizeModelElement element, CompareConfiguration config, IProgressMonitor monitor) throws TeamException { 53 monitor.beginTask(null, 100); 54 deriveBaseContentsFromLocal(element, Policy.subMonitorFor(monitor, 10)); 55 super.prepareCompareInput(element, config, Policy.subMonitorFor(monitor, 80)); 56 updateLabelsForCVS(element, config, Policy.subMonitorFor(monitor, 10)); 57 monitor.done(); 58 } 59 60 63 protected static void updateLabelsForCVS(ISynchronizeModelElement element, CompareConfiguration config, IProgressMonitor monitor) { 64 if (TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SHOW_AUTHOR_IN_COMPARE_EDITOR)) { 66 SyncInfo info = getSyncInfo(element); 67 if (info != null) { 68 final IResourceVariant remote = info.getRemote(); 69 final IResourceVariant base = info.getBase(); 70 String remoteAuthor = null; 71 if (remote != null && !remote.isContainer()) { 72 try { 73 ILogEntry entry = ((ICVSRemoteFile)remote).getLogEntry(monitor); 74 remoteAuthor = entry.getAuthor(); 75 config.setRightLabel(NLS.bind(CVSUIMessages.CVSParticipant_0, new String [] { remote.getContentIdentifier(), remoteAuthor })); 76 } catch (TeamException e) { 77 CVSUIPlugin.log(e); 78 } 79 } 80 if (base != null && !base.isContainer()) { 81 try { 82 String baseAuthor; 83 if (remoteAuthor != null && remote.getContentIdentifier().equals(base.getContentIdentifier())) { 84 baseAuthor = remoteAuthor; 85 } else { 86 ILogEntry entry = ((ICVSRemoteFile)base).getLogEntry(monitor); 87 baseAuthor = entry.getAuthor(); 88 } 89 config.setAncestorLabel(NLS.bind(CVSUIMessages.CVSParticipant_1, new String [] { base.getContentIdentifier(), baseAuthor })); 90 } catch (TeamException e) { 91 CVSUIPlugin.log(e); 92 } 93 } 94 } 95 } 96 } 97 98 protected static SyncInfo getSyncInfo(ISynchronizeModelElement element) { 99 if (element instanceof IAdaptable) { 100 return (SyncInfo)((IAdaptable)element).getAdapter(SyncInfo.class); 101 } 102 return null; 103 } 104 105 112 public static void deriveBaseContentsFromLocal(ISynchronizeModelElement element, IProgressMonitor monitor) throws TeamException { 113 SyncInfo info = getSyncInfo(element); 114 if (info == null) 115 return; 116 117 IResource local = info.getLocal(); 119 IResourceVariant base = info.getBase(); 120 if (base == null || base.isContainer() || local.getType() != IResource.FILE || !local.exists()) 121 return; 122 123 if ((info.getKind() & SyncInfo.DIRECTION_MASK) != SyncInfo.INCOMING) 126 return; 127 128 try { 129 RemoteFile remoteFile = (RemoteFile)base; 130 if (!remoteFile.isContentsCached()) 131 (remoteFile).setContents((IFile)local, monitor); 132 } catch (CoreException e) { 133 if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND) { 134 return; 136 } 137 throw CVSException.wrapException(e); 138 } 139 } 140 141 144 public PreferencePage[] getPreferencePages() { 145 return addCVSPreferencePages(super.getPreferencePages()); 146 } 147 148 public static PreferencePage[] addCVSPreferencePages(PreferencePage[] inheritedPages) { 149 PreferencePage[] pages = new PreferencePage[inheritedPages.length + 1]; 150 for (int i = 0; i < inheritedPages.length; i++) { 151 pages[i] = inheritedPages[i]; 152 } 153 pages[pages.length - 1] = new ComparePreferencePage(); 154 pages[pages.length - 1].setTitle(CVSUIMessages.CVSParticipant_2); 155 return pages; 156 } 157 158 161 public ChangeSetCapability getChangeSetCapability() { 162 if (capability == null) { 163 capability = createChangeSetCapability(); 164 } 165 return capability; 166 } 167 168 172 protected CVSChangeSetCapability createChangeSetCapability() { 173 return new CVSChangeSetCapability(); 174 } 175 176 179 protected boolean isViewerContributionsSupported() { 180 return true; 181 } 182 } 183 | Popular Tags |