Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2010 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 Eugene Kuleshov <eu@md.pp.ru> - Bug 173959 add mechanism for navigating from team annotation to corresponding task /
 
 package org.eclipse.team.internal.ccvs.ui.operations;
 
 import java.util.*;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.custom.StyleRange;
 import  org.eclipse.swt.graphics.RGB;
 import  org.eclipse.swt.widgets.Display;
 import  org.eclipse.swt.widgets.Shell;
 
An operation to fetch the annotations for a file from the repository and display them in the annotations view.
 
 public class ShowAnnotationOperation extends CVSOperation {
     
     private final ICVSResource fCVSResource;
     private final String fRevision;
     private final boolean fBinary;
 
     public ShowAnnotationOperation(IWorkbenchPart partICVSResource cvsResourceString revisionboolean binary) {
         super(part);
         cvsResource;
         revision;
          = binary;
     }
 
     /* (non-Javadoc)
      * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
      */
     protected void execute(IProgressMonitor monitorthrows CVSExceptionInterruptedException {
     	
 		monitor.beginTask(null, 100);
 
 		// Get the annotations from the repository.
 		final AnnotateListener listenernew AnnotateListener();
 		fetchAnnotation(listener, Policy.subMonitorFor(monitor, 80));
 
 		// this is not needed if there is no live annotate
 		final RevisionInformation information = createRevisionInformation(listener, Policy.subMonitorFor(monitor, 20));
 
 		// Open the view and display it from the UI thread.
 		final Display displaygetPart().getSite().getShell().getDisplay();
 		display.asyncExec(new Runnable() {
 			public void run() {
 				try {
 					//is there an open editor for the given input? If yes, use live annotate
 					final AbstractDecoratedTextEditor editorgetEditor(listener);
 					if (editor != null) {
 						editor.showRevisionInformation(information"org.eclipse.quickdiff.providers.CVSReferenceProvider"); //$NON-NLS-1$
 						final IWorkbenchPage pagegetPart().getSite().getPage();
 						showHistoryView(pageeditor);
 						page.activate(editor);
 					}
 				} catch (PartInitException e) {
 					CVSException.wrapException(e);
 				}
 			}
		});
		monitor.done();
	}
    
    
Shows the history view, creating it if necessary, but does not give it focus.

Parameters:
page the workbench page to operate in
editor the editor that is showing the file
Returns:
the history view
Throws:
PartInitException
    	Object object = .getIResource();
    	if (object == null)
    		object = editor.getEditorInput();
		IHistoryView historyView= TeamUI.showHistoryFor(pageobjectnull);
    	IHistoryPage historyPage = historyView.getHistoryPage();
    	if (historyPage instanceof CVSHistoryPage){
    		CVSHistoryPage cvsHistoryPage = (CVSHistoryPagehistoryPage;
    		cvsHistoryPage.setMode(.);
    		// We need to call link to ensure that the history page gets linked
			// even if the page input did not change
    		cvsHistoryPage.linkWithEditor();
    	}
    	return historyView;
    }
    /* (non-Javadoc)
     * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getTaskName()
     */
    protected String getTaskName() {
    }
	protected boolean hasCharset(ICVSResource cvsResourceInputStream contents) {
		try {
			return TeamPlugin.getCharset(cvsResource.getName(), contents) != null;
catch (IOException e) {
			// Assume that the contents do have a charset
			return true;
		}
	}
		if (resource instanceof IFile){
			return RevisionAnnotationController.openEditor(getPart().getSite().getPage(), (IFile)resource);
		}
		if ( instanceof ICVSRemoteResource) {
			return RevisionAnnotationController.openEditor(getPart().getSite().getPage(), new RemoteAnnotationStorage((ICVSRemoteFile)listener.getContents()));
		}
        return null;
	}
	private void fetchAnnotation(AnnotateListener listenerICVSResource cvsResourceString revisionIProgressMonitor monitorthrows CVSException {
    
        monitor = Policy.monitorFor(monitor);
        monitor.beginTask(null, 100);
        
        final ICVSFolder folder = cvsResource.getParent();
        final FolderSyncInfo info = folder.getFolderSyncInfo();
        final ICVSRepositoryLocation location = KnownRepositories.getInstance().getRepository(info.getRoot());
        
        final Session session = new Session(locationfoldertrue /*output to console*/);
        session.open(Policy.subMonitorFor(monitor, 10), false /* read-only */);
        try {
            final Command.QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
            try {
                CVSProviderPlugin.getPlugin().setQuietness(.);
                List localOptions = new ArrayList();
                if (revision != null) {
                    localOptions.add(Annotate.makeRevisionOption(revision));
                }
                if () {
                    localOptions.add(.);
                }
                final IStatus status = ..execute(session., (LocalOption[]) localOptions.toArray(new LocalOption[localOptions.size()]), new ICVSResource[]{cvsResource}, listener, Policy.subMonitorFor(monitor, 90));
                if (status.getCode() == .) {
                    throw new CVSServerException(status);
                }
            } finally {
                CVSProviderPlugin.getPlugin().setQuietness(quietness);
                monitor.done();
            }
        } finally {
            session.close();
        }
    }
    private RevisionInformation createRevisionInformation(final AnnotateListener listenerIProgressMonitor monitorthrows CVSException {
	    Map logEntriesByRevisionnew HashMap();
		if ( instanceof ICVSFile) {
			try {
				ILogEntry[] logEntries= ((ICVSFile).getLogEntries(monitor);
				for (int i= 0; i < logEntries.lengthi++) {
					ILogEntry entrylogEntries[i];
					logEntriesByRevision.put(entry.getRevision(), entry);
				}
catch (CVSException e) {
				throw e;
catch (TeamException e) {
				// XXX why does getLogEntries throw TeamException?
				throw CVSException.wrapException(e);
			}
		}
		final CommitterColors colors= CommitterColors.getDefault();
			private final boolean isResizable;
			public AnnotationControlCreator(boolean isResizable) {
				this.isResizable;
			}
					public String updatePresentation(Display displayString hoverInfoTextPresentation presentationint maxWidthint maxHeight) {
						// decorate header
						StyleRange styleRange = new StyleRange();
						styleRange.start = 0;
						styleRange.length = hoverInfo.indexOf('\n');
						styleRange.fontStyle = SWT.BOLD;
						presentation.addStyleRange(styleRange);
						return hoverInfo;
					}
				};
					return new DefaultInformationControl(parent, (ToolBarManagernullpresenter);
				else
					return new DefaultInformationControl(parent, EditorsUI.getTooltipAffordanceString(), presenter);
			}
		}
		HashMap setsnew HashMap();
		List annotateBlockslistener.getCvsAnnotateBlocks();
		for (Iterator blocksannotateBlocks.iterator(); blocks.hasNext();) {
			final CVSAnnotateBlock block= (CVSAnnotateBlockblocks.next();
			final String revisionStringblock.getRevision();
			Revision revision= (Revisionsets.get(revisionString);
			if (revision == null) {
				final ILogEntry entry= (ILogEntrylogEntriesByRevision.get(revisionString);
				if (entry == null)
					continue;
				revisionnew Revision() {
					private String fCommitternull;
					public Object getHoverInfo() {
						return entry.getAuthor()
" " + entry.getRevision() + " " + DateFormat.getDateTimeInstance(..).format(entry.getDate()) //$NON-NLS-1$ //$NON-NLS-2$
"\n\n" + entry.getComment(); //$NON-NLS-1$
					}
					private String getCommitterId() {
						if ( == null)
							block.toString().substring(0, block.toString().indexOf(' '));
						return ;
					}
					public String getId() {
						return revisionString;
					}
					public Date getDate() {
						return entry.getDate();
					}
					public RGB getColor() {
					}
					public String getAuthor() {
						return getCommitterId();
					}
				};
				sets.put(revisionStringrevision);
				info.addRevision(revision);
			}
			revision.addRange(new LineRange(block.getStartLine(), block.getEndLine() - block.getStartLine() + 1));
		}
		return info;
	}
New to GrepCode? Check out our FAQ X