1 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 r = new Runnable () { 33 public void run() { 34 showCompareInDialog(getShell(), file); 35 } 36 }; 37 TeamUIPlugin.getStandardDisplay().asyncExec(r); 38 } 39 40 private void showCompareInDialog(Shell shell, Object 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 getOKButtonLabel() { 51 return TeamUIMessages.ReplaceLocalHistory_0; 52 } 53 public boolean okPressed() { 54 try { 55 Object 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 getPromptTitle() { 71 return TeamUIMessages.ReplaceLocalHistory_1; 72 } 73 } 74 | Popular Tags |