1 11 package org.eclipse.team.ui.history; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.compare.CompareConfiguration; 16 import org.eclipse.compare.IContentChangeNotifier; 17 import org.eclipse.compare.structuremergeviewer.ICompareInput; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jface.action.ToolBarManager; 21 import org.eclipse.jface.viewers.*; 22 import org.eclipse.swt.graphics.Image; 23 import org.eclipse.swt.widgets.*; 24 import org.eclipse.team.internal.ui.Utils; 25 import org.eclipse.team.internal.ui.history.DialogHistoryPageSite; 26 import org.eclipse.team.ui.PageSaveablePart; 27 import org.eclipse.team.ui.SaveablePartDialog; 28 import org.eclipse.ui.part.Page; 29 30 37 public class HistoryPageSaveablePart extends PageSaveablePart { 38 39 private IHistoryPage historyPage; 40 private DialogHistoryPageSite site; 41 private final Object object; 42 private final IHistoryPageSource pageSource; 43 44 51 public static boolean showHistoryInDialog(Shell shell, Object object) { 52 IHistoryPageSource pageSource = HistoryPageSource.getHistoryPageSource(object); 53 if (pageSource != null && pageSource.canShowHistoryFor(object)) { 54 CompareConfiguration cc = new CompareConfiguration(); 55 cc.setLeftEditable(isFile(object)); 56 cc.setRightEditable(false); 57 HistoryPageSaveablePart input = new HistoryPageSaveablePart(shell, cc, pageSource, object); 58 try { 59 SaveablePartDialog cd = new SaveablePartDialog(shell, input); 60 cd.setBlockOnOpen(true); 61 cd.open(); 62 } finally { 63 input.dispose(); 64 } 65 return true; 66 } 67 return false; 68 } 69 70 private static boolean isFile(Object object) { 71 IResource resource = Utils.getResource(object); 72 return (resource != null && resource.getType() == IResource.FILE); 73 } 74 75 82 public HistoryPageSaveablePart(Shell shell, CompareConfiguration configuration, IHistoryPageSource pageSource, Object object) { 83 super(shell,configuration); 84 this.pageSource = pageSource; 85 this.object = object; 86 } 87 90 public String getTitle() { 91 return historyPage.getName(); 92 } 93 94 97 public Image getTitleImage() { 98 return null; 99 } 100 101 104 public void contentChanged(IContentChangeNotifier source) { 105 } 106 107 110 protected Control createPage(Composite parent, ToolBarManager toolBarManager) { 111 site = new DialogHistoryPageSite(getShell()); 112 historyPage = (IHistoryPage)pageSource.createPage(object); 113 historyPage.setSite(site); 114 site.setToolBarManager(toolBarManager); 115 ((Page) historyPage).createControl(parent); 116 historyPage.setInput(object); 117 String description = historyPage.getDescription(); 118 if (description == null) 119 description = ""; setPageDescription(description); 121 return ((Page) historyPage).getControl(); 122 } 123 124 127 protected final ISelectionProvider getSelectionProvider() { 128 return site.getSelectionProvider(); 129 } 130 131 134 protected ICompareInput getCompareInput(ISelection selection) { 135 ICompareInput compareInput = super.getCompareInput(selection); 136 if (compareInput != null) 137 return compareInput; 138 IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class); 139 if (compareAdapter != null){ 140 if (selection instanceof IStructuredSelection) { 141 IStructuredSelection ss= (IStructuredSelection) selection; 142 if (ss.size() == 1) { 143 Object o = ss.getFirstElement(); 144 return compareAdapter.getCompareInput(o); 145 } 146 } 147 } 148 return null; 149 } 150 151 154 protected void prepareInput(ICompareInput input, CompareConfiguration configuration, IProgressMonitor monitor) throws InvocationTargetException { 155 IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class); 156 if (compareAdapter != null){ 157 compareAdapter.prepareInput(input, configuration, monitor); 158 } 159 } 160 161 164 public void dispose() { 165 super.dispose(); 166 if (historyPage != null) 167 historyPage.dispose(); 168 } 169 } 170 | Popular Tags |