1 11 12 package org.eclipse.team.internal.ui.actions; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.dialogs.MessageDialog; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.team.core.history.IFileRevision; 22 import org.eclipse.team.internal.ui.TeamUIMessages; 23 import org.eclipse.team.internal.ui.Utils; 24 import org.eclipse.team.internal.ui.history.AbstractHistoryCategory; 25 import org.eclipse.team.ui.history.HistoryPage; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.actions.BaseSelectionListenerAction; 28 import org.eclipse.ui.progress.IProgressService; 29 30 public class OpenRevisionAction extends BaseSelectionListenerAction { 31 32 private IStructuredSelection selection; 33 private HistoryPage page; 34 35 public OpenRevisionAction(String text) { 36 super(text); 37 } 38 39 public void run() { 40 IStructuredSelection structSel = selection; 41 42 Object [] objArray = structSel.toArray(); 43 44 for (int i = 0; i < objArray.length; i++) { 45 Object tempRevision = objArray[i]; 46 if (tempRevision instanceof AbstractHistoryCategory) 48 continue; 49 50 final IFileRevision revision = (IFileRevision) tempRevision; 51 if (revision == null || !revision.exists()) { 52 MessageDialog.openError(page.getSite().getShell(), TeamUIMessages.OpenRevisionAction_DeletedRevTitle, TeamUIMessages.OpenRevisionAction_DeletedRevMessage); 53 } else { 54 IRunnableWithProgress runnable = new IRunnableWithProgress() { 55 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 56 try { 57 Utils.openEditor(page.getSite().getPage(), revision, monitor); 58 } catch (CoreException e) { 59 throw new InvocationTargetException (e); 60 } 61 62 } 63 }; 64 65 IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); 66 try { 67 progressService.run(false, false, runnable); 68 } catch (InvocationTargetException e) { 69 Utils.handleError(page.getSite().getShell(), e, TeamUIMessages.OpenRevisionAction_ErrorTitle, TeamUIMessages.OpenRevisionAction_ErrorMessage); 70 } catch (InterruptedException e) { 71 } 72 } 73 74 } 75 } 76 77 protected boolean updateSelection(IStructuredSelection selection) { 78 this.selection = selection; 79 return shouldShow(); 80 } 81 82 public void setPage(HistoryPage page) { 83 this.page = page; 84 } 85 86 private boolean shouldShow() { 87 IStructuredSelection structSel = selection; 88 Object [] objArray = structSel.toArray(); 89 90 if (objArray.length == 0) 91 return false; 92 93 for (int i = 0; i < objArray.length; i++) { 94 if (objArray[i] instanceof AbstractHistoryCategory) 96 return false; 97 98 IFileRevision revision = (IFileRevision) objArray[i]; 99 if (revision != null && !revision.exists()) 101 return false; 102 } 103 104 return true; 105 } 106 107 } 108 | Popular Tags |