KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > CompareWithRevisionAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.compare.CompareConfiguration;
16 import org.eclipse.compare.CompareUI;
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.team.internal.ccvs.core.CVSException;
24 import org.eclipse.team.internal.ccvs.core.ICVSResource;
25 import org.eclipse.team.internal.ccvs.ui.*;
26 import org.eclipse.team.internal.ui.TeamUIPlugin;
27 import org.eclipse.team.ui.TeamUI;
28 import org.eclipse.team.ui.history.*;
29
30 /**
31  * Compare with revision will allow a user to browse the history of a file, compare with the
32  * other revisions and merge changes from other revisions into the workspace copy.
33  */

34 public class CompareWithRevisionAction extends WorkspaceAction {
35
36     
37     /*
38      * @see CVSAction#execute(IAction)
39      */

40     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
41                     
42         // Show the compare viewer
43
run(new IRunnableWithProgress() {
44             public void run(IProgressMonitor monitor) throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
45                 if (isShowInDialog()) {
46                     IFile file = (IFile) getSelectedResources()[0];
47                     showCompareInDialog(getShell(), file);
48                 } else {
49                     IHistoryView view = TeamUI.showHistoryFor(TeamUIPlugin.getActivePage(), (IFile)getSelectedResources()[0], null);
50                     IHistoryPage page = view.getHistoryPage();
51                     if (page instanceof CVSHistoryPage){
52                         CVSHistoryPage cvsHistoryPage = (CVSHistoryPage) page;
53                         cvsHistoryPage.setClickAction(true);
54                     }
55                 }
56             }
57         }, false /* cancelable */, PROGRESS_BUSYCURSOR);
58     }
59     
60     protected void showCompareInDialog(Shell shell, Object JavaDoc object){
61         IHistoryPageSource pageSource = HistoryPageSource.getHistoryPageSource(object);
62         if (pageSource != null && pageSource.canShowHistoryFor(object)) {
63             CompareConfiguration cc = new CompareConfiguration();
64             cc.setLeftEditable(true);
65             cc.setRightEditable(false);
66             HistoryPageCompareEditorInput input = new HistoryPageCompareEditorInput(cc, pageSource, object) {
67                 public void saveChanges(IProgressMonitor monitor) throws CoreException {
68                     super.saveChanges(monitor);
69                     ((CVSHistoryPage)getHistoryPage()).saveChanges(monitor);
70                     setDirty(false);
71                 }
72             };
73             CompareUI.openCompareDialog(input);
74         }
75     }
76     
77     /**
78      * Return the text describing this action
79      */

80     protected String JavaDoc getActionTitle() {
81         return CVSUIMessages.CompareWithRevisionAction_4;
82     }
83     
84     /* (non-Javadoc)
85      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
86      */

87     protected String JavaDoc getErrorTitle() {
88         return CVSUIMessages.CompareWithRevisionAction_compare;
89     }
90
91     /* (non-Javadoc)
92      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForCVSResource(org.eclipse.team.internal.ccvs.core.ICVSResource)
93      */

94     protected boolean isEnabledForCVSResource(ICVSResource cvsResource) throws CVSException {
95         return (!cvsResource.isFolder() && super.isEnabledForCVSResource(cvsResource));
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForMultipleResources()
100      */

101     protected boolean isEnabledForMultipleResources() {
102         return false;
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForAddedResources()
107      */

108     protected boolean isEnabledForAddedResources() {
109         return true;
110     }
111     
112     protected boolean isEnabledForUnmanagedResources() {
113         return true;
114     }
115     
116     protected boolean isEnabledForIgnoredResources() {
117         return true;
118     }
119
120     protected boolean isShowInDialog() {
121         return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_SHOW_COMPARE_REVISION_IN_DIALOG);
122     }
123 }
124
Popular Tags