1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 24 import org.eclipse.team.ui.TeamUI; 25 26 public class ShowHistoryAction extends CVSAction { 27 30 protected ICVSRemoteFile[] getSelectedRemoteFiles() { 31 ArrayList resources = null; 32 IStructuredSelection selection = getSelection(); 33 if (!selection.isEmpty()) { 34 resources = new ArrayList (); 35 Iterator elements = selection.iterator(); 36 while (elements.hasNext()) { 37 Object next = elements.next(); 38 if (next instanceof ICVSRemoteFile) { 39 resources.add(next); 40 continue; 41 } 42 if (next instanceof IAdaptable) { 43 IAdaptable a = (IAdaptable)next; 44 Object adapter = a.getAdapter(ICVSRemoteFile.class); 45 if (adapter instanceof ICVSRemoteFile) { 46 resources.add(adapter); 47 continue; 48 } 49 } 50 } 51 } 52 if (resources != null && !resources.isEmpty()) { 53 ICVSRemoteFile[] result = new ICVSRemoteFile[resources.size()]; 54 resources.toArray(result); 55 return result; 56 } 57 return new ICVSRemoteFile[0]; 58 } 59 62 public void execute(IAction action) throws InterruptedException , InvocationTargetException { 63 run(new IRunnableWithProgress() { 64 public void run(IProgressMonitor monitor) throws InvocationTargetException { 65 ICVSRemoteFile[] files = getSelectedRemoteFiles(); 66 TeamUI.showHistoryFor(getTargetPage(), files[0], null); 67 } 68 }, false , PROGRESS_BUSYCURSOR); 69 } 70 73 public boolean isEnabled() { 74 ICVSRemoteFile[] resources = getSelectedRemoteFiles(); 75 return resources.length == 1; 76 } 77 80 protected String getErrorTitle() { 81 return CVSUIMessages.ShowHistoryAction_showHistory; 82 } 83 84 } 85 | Popular Tags |