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.core.ILogEntry; 24 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 25 26 public class OpenRemoteFileAction 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 ILogEntry) { 43 resources.add(((ILogEntry)next).getRemoteFile()); 44 continue; 45 } 46 if (next instanceof IAdaptable) { 47 IAdaptable a = (IAdaptable) next; 48 Object adapter = a.getAdapter(ICVSRemoteFile.class); 49 if (adapter instanceof ICVSRemoteFile) { 50 resources.add(adapter); 51 continue; 52 } 53 } 54 } 55 } 56 if (resources != null && !resources.isEmpty()) { 57 ICVSRemoteFile[] result = new ICVSRemoteFile[resources.size()]; 58 resources.toArray(result); 59 return result; 60 } 61 return new ICVSRemoteFile[0]; 62 } 63 66 public void execute(IAction action) throws InterruptedException , InvocationTargetException { 67 run(new IRunnableWithProgress() { 68 public void run(IProgressMonitor monitor) throws InvocationTargetException { 69 ICVSRemoteFile[] files = getSelectedRemoteFiles(); 70 for (int i = 0; i < files.length; i++) { 71 ICVSRemoteFile file = files[i]; 72 CVSUIPlugin.getPlugin().openEditor(file, monitor); 73 } 74 } 75 }, false, PROGRESS_BUSYCURSOR); 76 } 77 80 public boolean isEnabled() { 81 ICVSRemoteFile[] resources = getSelectedRemoteFiles(); 82 if (resources.length == 0) return false; 83 return true; 84 } 85 } 86 | Popular Tags |