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.CompareViewerPane; 17 import org.eclipse.compare.structuremergeviewer.ICompareInput; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jface.action.IToolBarManager; 21 import org.eclipse.jface.util.IPropertyChangeListener; 22 import org.eclipse.jface.util.PropertyChangeEvent; 23 import org.eclipse.jface.viewers.*; 24 import org.eclipse.swt.widgets.Display; 25 import org.eclipse.team.internal.ui.TeamUIMessages; 26 import org.eclipse.team.internal.ui.Utils; 27 import org.eclipse.team.internal.ui.history.DialogHistoryPageSite; 28 import org.eclipse.team.ui.PageCompareEditorInput; 29 import org.eclipse.ui.part.IPage; 30 import org.eclipse.ui.part.Page; 31 32 38 public class HistoryPageCompareEditorInput extends PageCompareEditorInput { 39 40 private IHistoryPage historyPage; 41 private DialogHistoryPageSite site; 42 private final Object object; 43 private final IHistoryPageSource pageSource; 44 private final IPropertyChangeListener changeListener = new IPropertyChangeListener() { 45 public void propertyChange(PropertyChangeEvent event) { 46 handlePropertyChange(event); 47 } 48 }; 49 private boolean isReplace; 50 51 57 public HistoryPageCompareEditorInput(CompareConfiguration configuration, IHistoryPageSource pageSource, Object object) { 58 super(configuration); 59 this.pageSource = pageSource; 60 this.object = object; 61 } 62 63 66 protected Object prepareInput(IProgressMonitor monitor) 67 throws InvocationTargetException , InterruptedException { 68 return object; 69 } 70 71 74 protected void handleDispose() { 75 super.handleDispose(); 76 if (historyPage != null) { 77 historyPage.removePropertyChangeListener(changeListener); 78 historyPage.dispose(); 79 } 80 } 81 82 85 protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) { 86 site = new DialogHistoryPageSite(parent.getShell()); 87 historyPage = (IHistoryPage)pageSource.createPage(object); 88 historyPage.setSite(site); 89 site.setToolBarManager(toolBarManager); 90 ((Page) historyPage).createControl(parent); 91 historyPage.setInput(object); 92 String description = historyPage.getDescription(); 93 if (description == null) 94 description = ""; setPageDescription(description); 96 if (getTitle() == null) 97 setTitle(historyPage.getName()); 98 historyPage.addPropertyChangeListener(changeListener); 99 return (IPage)historyPage; 100 } 101 102 105 protected ICompareInput asCompareInput(ISelection selection) { 106 ICompareInput compareInput = super.asCompareInput(selection); 107 if (compareInput != null) 108 return compareInput; 109 IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class); 110 if (compareAdapter != null){ 111 if (selection instanceof IStructuredSelection) { 112 IStructuredSelection ss= (IStructuredSelection) selection; 113 if (ss.size() == 1) { 114 Object o = ss.getFirstElement(); 115 return compareAdapter.getCompareInput(o); 116 } 117 } 118 } 119 return null; 120 } 121 122 125 protected ISelectionProvider getSelectionProvider() { 126 return site.getSelectionProvider(); 127 } 128 129 132 protected void prepareInput(ICompareInput input, 133 CompareConfiguration configuration, IProgressMonitor monitor) 134 throws InvocationTargetException { 135 IHistoryCompareAdapter compareAdapter = (IHistoryCompareAdapter) Utils.getAdapter(historyPage, IHistoryCompareAdapter.class); 136 if (compareAdapter != null){ 137 compareAdapter.prepareInput(input, configuration, monitor); 138 } 139 } 140 141 146 public final IHistoryPage getHistoryPage() { 147 return historyPage; 148 } 149 150 154 protected void handlePropertyChange(PropertyChangeEvent event) { 155 if (event.getSource() == historyPage) { 156 if (event.getProperty().equals(IHistoryPage.P_NAME)) { 157 Display.getDefault().asyncExec(new Runnable () { 158 public void run() { 159 setTitle(historyPage.getName()); 160 } 161 }); 162 } else if (event.getProperty().equals(IHistoryPage.P_DESCRIPTION)) { 163 Display.getDefault().asyncExec(new Runnable () { 164 public void run() { 165 setPageDescription(historyPage.getDescription()); 166 } 167 }); 168 } 169 } 170 } 171 172 175 public boolean isEditionSelectionDialog() { 176 return isReplaceDialog(); 177 } 178 179 185 protected boolean isReplaceDialog() { 186 return isReplace; 187 } 188 189 195 public void setReplace(boolean isReplace) { 196 this.isReplace = isReplace; 197 } 198 199 202 public String getOKButtonLabel() { 203 if (isReplaceDialog()) 204 return TeamUIMessages.HistoryPageCompareEditorInput_0; 205 return super.getOKButtonLabel(); 206 } 207 208 211 public boolean okPressed() { 212 if (!isReplaceDialog()) 213 return super.okPressed(); 214 try { 215 Object o = getSelectedEdition(); 216 performReplace(((ICompareInput)o).getRight()); 217 } catch (CoreException e) { 218 Utils.handle(e); 219 return false; 220 } 221 return true; 222 } 223 224 233 protected void performReplace(Object selectedObject) throws CoreException { 234 } 236 237 } 238 | Popular Tags |