KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 org.eclipse.compare.*;
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jface.action.IToolBarManager;
18 import org.eclipse.osgi.util.NLS;
19 import org.eclipse.swt.widgets.Shell;
20 import org.eclipse.team.internal.ccvs.ui.CVSHistoryPage;
21 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
22 import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;
23 import org.eclipse.team.ui.history.*;
24 import org.eclipse.ui.part.IPage;
25
26 /**
27  * Displays a compare dialog and allows the same behavior as the compare. In addition
28  * a replace button is added to the dialog that will replace the local with the currently
29  * selected revision.
30  *
31  * @since 3.0
32  */

33 public class ReplaceWithRevisionAction extends CompareWithRevisionAction {
34     
35     protected void showCompareInDialog(Shell shell, Object JavaDoc object){
36         IHistoryPageSource pageSource = HistoryPageSource.getHistoryPageSource(object);
37         if (pageSource != null && pageSource.canShowHistoryFor(object)) {
38             CompareConfiguration cc = new CompareConfiguration();
39             cc.setLeftEditable(false);
40             cc.setRightEditable(false);
41             HistoryPageCompareEditorInput input = new HistoryPageCompareEditorInput(cc, pageSource, object) {
42                 public void saveChanges(IProgressMonitor monitor) throws CoreException {
43                     super.saveChanges(monitor);
44                     ((CVSHistoryPage)getHistoryPage()).saveChanges(monitor);
45                     setDirty(false);
46                 }
47                 protected void performReplace(Object JavaDoc o) throws CoreException {
48                     FileRevisionTypedElement right = (FileRevisionTypedElement)o;
49                     IFile file = (IFile)getCompareResult();
50                     file.setContents(right.getContents(), false, true, null);
51                 }
52                 protected IPage createPage(CompareViewerPane parent,
53                         IToolBarManager toolBarManager) {
54                     IPage page = super.createPage(parent, toolBarManager);
55                     setTitle(NLS.bind(CVSUIMessages.ReplaceWithRevisionAction_0, ((IHistoryPage)page).getName()));
56                     setPageDescription(((IHistoryPage)page).getName());
57                     return page;
58                 }
59             };
60             input.setReplace(true);
61             CompareUI.openCompareDialog(input);
62         }
63     }
64     /* (non-Javadoc)
65      * @see org.eclipse.team.internal.ccvs.ui.actions.CompareWithRevisionAction#getActionTitle()
66      */

67     protected String JavaDoc getActionTitle() {
68         return CVSUIMessages.ReplaceWithRevisionAction_1;
69     }
70     
71     protected boolean isShowInDialog() {
72         // Always show a replace in a dialog
73
return true;
74     }
75 }
76
Popular Tags