KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > history > ReplaceLocalHistory


1 /*******************************************************************************
2  * Copyright (c) 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.ui.history;
12
13 import org.eclipse.compare.CompareConfiguration;
14 import org.eclipse.compare.CompareUI;
15 import org.eclipse.compare.structuremergeviewer.ICompareInput;
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IFileState;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.team.internal.ui.*;
22 import org.eclipse.team.ui.history.HistoryPageCompareEditorInput;
23 import org.eclipse.team.ui.history.IHistoryPageSource;
24
25 public class ReplaceLocalHistory extends ShowLocalHistory {
26     
27     public void run(IAction action) {
28         final IFile file = (IFile) getSelection().getFirstElement();
29         IFileState states[]= getLocalHistory();
30         if (states == null || states.length == 0)
31             return;
32         Runnable JavaDoc r = new Runnable JavaDoc() {
33             public void run() {
34                 showCompareInDialog(getShell(), file);
35             }
36         };
37         TeamUIPlugin.getStandardDisplay().asyncExec(r);
38     }
39     
40     private void showCompareInDialog(Shell shell, Object JavaDoc object){
41         IHistoryPageSource pageSource = LocalHistoryPageSource.getInstance();
42         if (pageSource != null && pageSource.canShowHistoryFor(object)) {
43             CompareConfiguration cc = new CompareConfiguration();
44             cc.setLeftEditable(false);
45             cc.setRightEditable(false);
46             HistoryPageCompareEditorInput input = new HistoryPageCompareEditorInput(cc, pageSource, object) {
47                 public boolean isEditionSelectionDialog() {
48                     return true;
49                 }
50                 public String JavaDoc getOKButtonLabel() {
51                     return TeamUIMessages.ReplaceLocalHistory_0;
52                 }
53                 public boolean okPressed() {
54                     try {
55                         Object JavaDoc o = getSelectedEdition();
56                         FileRevisionTypedElement right = (FileRevisionTypedElement) ((ICompareInput)o).getRight();
57                         IFile file = (IFile)getCompareResult();
58                         file.setContents(right.getContents(), false, true, null);
59                     } catch (CoreException e) {
60                         Utils.handle(e);
61                         return false;
62                     }
63                     return true;
64                 }
65             };
66             CompareUI.openCompareDialog(input);
67         }
68     }
69     
70     protected String JavaDoc getPromptTitle() {
71         return TeamUIMessages.ReplaceLocalHistory_1;
72     }
73 }
74
Popular Tags