Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.team.internal.ccvs.ui.subscriber;
 
Superclass for all CVS particpants (workspace, merge and compare)
 
 public class CVSParticipant extends SubscriberParticipant implements IChangeSetProvider {
 	
 
     /* (non-Javadoc)
 	 * @see org.eclipse.team.ui.synchronize.subscribers.SubscriberParticipant#initializeConfiguration(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration)
 	 */
 	protected void initializeConfiguration(ISynchronizePageConfiguration configuration) {
 		super.initializeConfiguration(configuration);
 		// The decorator adds itself to the configuration
 		ILabelDecorator labelDecorator = new CVSParticipantLabelDecorator(configuration);
 		configuration.addLabelDecorator(labelDecorator);
 	}
 	
 	/* (non-Javadoc)
      * @see org.eclipse.team.ui.synchronize.SubscriberParticipant#updateLabels(org.eclipse.team.ui.synchronize.ISynchronizeModelElement, org.eclipse.compare.CompareConfiguration, org.eclipse.core.runtime.IProgressMonitor)
      */
     public void prepareCompareInput(ISynchronizeModelElement elementCompareConfiguration configIProgressMonitor monitorthrows TeamException {
         monitor.beginTask(null, 100);
         deriveBaseContentsFromLocal(element, Policy.subMonitorFor(monitor, 10));
         super.prepareCompareInput(elementconfig, Policy.subMonitorFor(monitor, 80));
         updateLabelsForCVS(elementconfig, Policy.subMonitorFor(monitor, 10));
         monitor.done();
     }

    
Helper method for updating compare editor labels
 
     protected static void updateLabelsForCVS(ISynchronizeModelElement elementCompareConfiguration configIProgressMonitor monitor) {
         // Add the author to the remote or base
 	        SyncInfo info = getSyncInfo(element);
 	        if (info != null) {
 	    		final IResourceVariant remote = info.getRemote();
 	    		final IResourceVariant base = info.getBase();
 	    		String remoteAuthor = null;
 	    		if (remote != null && !remote.isContainer()) {
 	    		    try {
 	                    ILogEntry entry = ((ICVSRemoteFile)remote).getLogEntry(monitor);
 	                    remoteAuthor = entry.getAuthor();
 	                    config.setRightLabel(NLS.bind(.new String[] { remote.getContentIdentifier(), remoteAuthor })); 
 	                } catch (TeamException e) {
 	                    CVSUIPlugin.log(e);
 	                }
 	    		}
 	    		if (base != null && !base.isContainer()) {
 	    		    try {
                         String baseAuthor;
                         if (remoteAuthor != null && remote.getContentIdentifier().equals(base.getContentIdentifier())) {
                             baseAuthor = remoteAuthor;
                         } else {
                             ILogEntry entry = ((ICVSRemoteFile)base).getLogEntry(monitor);
                             baseAuthor = entry.getAuthor();
                         }
                         config.setAncestorLabel(NLS.bind(.new String[] { base.getContentIdentifier(), baseAuthor })); 
                     } catch (TeamException e) {
                         CVSUIPlugin.log(e);
                     }
 	    		}
 	        }
         }
     }
     
 	protected static SyncInfo getSyncInfo(ISynchronizeModelElement element) {
 	    if (element instanceof IAdaptable) {
		    return (SyncInfo)((IAdaptable)element).getAdapter(SyncInfo.class);
	    }
	    return null;
	}

    
If the local is not modified and the base matches the local then cache the local contents as the contents of the base.

    public static void deriveBaseContentsFromLocal(ISynchronizeModelElement elementIProgressMonitor monitorthrows TeamException {
        SyncInfo info = getSyncInfo(element);
        if (info == null
            return;
        
        // We need a base that is a file and a local that is a file
        IResource local = info.getLocal();
        IResourceVariant base = info.getBase();
        if (base == null || base.isContainer() || local.getType() != . || !local.exists())
            return;
        
        // We can only use the local contents for incoming changes.
        // Outgoing or conflicting changes imply that the local has changed
        if ((info.getKind() & .) != .)
            return;
        
        try {
            RemoteFile remoteFile = (RemoteFile)base;
            if (!remoteFile.isContentsCached())
                (remoteFile).setContents((IFile)localmonitor);
        } catch (CoreException e) {
            if (e.getStatus().getCode() == .) {
                // The file must have just been deleted
                return;
            }
            throw CVSException.wrapException(e);
        }
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#getPreferencePages()
     */
    public PreferencePage[] getPreferencePages() {
        return addCVSPreferencePages(super.getPreferencePages());
    }
    public static PreferencePage[] addCVSPreferencePages(PreferencePage[] inheritedPages) {
        PreferencePage[] pages = new PreferencePage[inheritedPages.length + 1];
        for (int i = 0; i < inheritedPages.lengthi++) {
            pages[i] = inheritedPages[i];
        }
        pages[pages.length - 1] = new ComparePreferencePage();
        pages[pages.length - 1].setTitle(.); 
        return pages;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#getChangeSetCapability()
     */
        if ( == null) {
             = createChangeSetCapability();
        }
        return ;
    }

    
Create the change set capability for this particpant.

Returns:
the created capability
        return new CVSChangeSetCapability();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#isViewerContributionsSupported()
     */
    protected boolean isViewerContributionsSupported() {
        return true;
    }
New to GrepCode? Check out our FAQ X