| package org.eclipse.team.internal.ccvs.ui.actions; |
| |
| /* |
| * (c) Copyright IBM Corp. 2000, 2002. |
| * All Rights Reserved. |
| */ |
| |
| import java.lang.reflect.InvocationTargetException; |
| |
| import org.eclipse.compare.CompareUI; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IResource; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.dialogs.MessageDialog; |
| import org.eclipse.jface.operation.IRunnableWithProgress; |
| import org.eclipse.team.core.TeamException; |
| import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; |
| import org.eclipse.team.internal.ccvs.core.ICVSResource; |
| import org.eclipse.team.internal.ccvs.core.ILogEntry; |
| import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; |
| import org.eclipse.team.internal.ccvs.ui.CVSCompareRevisionsInput; |
| import org.eclipse.team.internal.ccvs.ui.Policy; |
| import org.eclipse.team.internal.ui.actions.TeamAction; |
| |
| public class CompareWithRevisionAction extends CVSAction { |
| /** |
| * Returns the selected remote file |
| */ |
| protected ICVSRemoteFile getSelectedRemoteFile() { |
| IResource[] resources = getSelectedResources(); |
| if (resources.length != 1) return null; |
| if (!(resources[0] instanceof IFile)) return null; |
| IFile file = (IFile)resources[0]; |
| try { |
| return (ICVSRemoteFile)CVSWorkspaceRoot.getRemoteResourceFor(file); |
| } catch (TeamException e) { |
| handle(e, null, null); |
| return null; |
| } |
| } |
| |
| public void execute(IAction action) { |
| |
| // Setup holders |
| final ICVSRemoteFile[] file = new ICVSRemoteFile[] { null }; |
| final ILogEntry[][] entries = new ILogEntry[][] { null }; |
| |
| // Get the selected file |
| run(new IRunnableWithProgress() { |
| public void run(IProgressMonitor monitor) throws InvocationTargetException { |
| file[0] = getSelectedRemoteFile(); |
| } |
| }, Policy.bind("CompareWithRevisionAction.compare"), this.PROGRESS_BUSYCURSOR); //$NON-NLS-1$ |
| |
| if (file[0] == null) { |
| // No revisions for selected file |
| MessageDialog.openWarning(getShell(), Policy.bind("CompareWithRevisionAction.noRevisions"), Policy.bind("CompareWithRevisionAction.noRevisionsLong")); //$NON-NLS-1$ //$NON-NLS-2$ |
| return; |
| } |
| |
| // Fetch the log entries |
| run(new IRunnableWithProgress() { |
| public void run(IProgressMonitor monitor) throws InvocationTargetException { |
| try { |
| monitor.beginTask(Policy.bind("CompareWithRevisionAction.fetching"), 100); //$NON-NLS-1$ |
| entries[0] = file[0].getLogEntries(Policy.subMonitorFor(monitor, 100)); |
| monitor.done(); |
| } catch (TeamException e) { |
| throw new InvocationTargetException(e); |
| } |
| } |
| }, Policy.bind("CompareWithRevisionAction.compare"), this.PROGRESS_DIALOG); //$NON-NLS-1$ |
| |
| if (entries[0] == null) return; |
| |
| // Show the compare viewer |
| run(new IRunnableWithProgress() { |
| public void run(IProgressMonitor monitor) throws InvocationTargetException { |
| CompareUI.openCompareEditor(new CVSCompareRevisionsInput((IFile)getSelectedResources()[0], entries[0])); |
| } |
| }, Policy.bind("CompareWithRevisionAction.compare"), this.PROGRESS_BUSYCURSOR); //$NON-NLS-1$ |
| } |
| /* |
| * @see TeamAction#isEnabled() |
| */ |
| protected boolean isEnabled() throws TeamException { |
| IResource[] resources = getSelectedResources(); |
| if (resources.length != 1) return false; |
| ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resources[0]); |
| return cvsResource.isManaged(); |
| } |
| |
| /* |
| * @see CVSAction#needsToSaveDirtyEditors() |
| */ |
| protected boolean needsToSaveDirtyEditors() { |
| return false; |
| } |
| } |