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.dialogs.MessageDialog; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; 24 import org.eclipse.team.internal.ccvs.core.ILogEntry; 25 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 26 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 27 28 public class OpenLogEntryAction extends CVSAction { 29 32 protected ILogEntry[] getSelectedLogEntries() { 33 ArrayList entries = null; 34 IStructuredSelection selection = getSelection(); 35 if (!selection.isEmpty()) { 36 entries = new ArrayList (); 37 Iterator elements = selection.iterator(); 38 while (elements.hasNext()) { 39 Object next = elements.next(); 40 if (next instanceof ILogEntry) { 41 entries.add(next); 42 continue; 43 } 44 if (next instanceof IAdaptable) { 45 IAdaptable a = (IAdaptable) next; 46 Object adapter = a.getAdapter(ILogEntry.class); 47 if (adapter instanceof ILogEntry) { 48 entries.add(adapter); 49 continue; 50 } 51 } 52 } 53 } 54 if (entries != null && !entries.isEmpty()) { 55 ILogEntry[] result = new ILogEntry[entries.size()]; 56 entries.toArray(result); 57 return result; 58 } 59 return new ILogEntry[0]; 60 } 61 64 public void execute(IAction action) throws InterruptedException , InvocationTargetException { 65 run(new IRunnableWithProgress() { 66 public void run(IProgressMonitor monitor) throws InvocationTargetException { 67 final ILogEntry[] entries = getSelectedLogEntries(); 68 for (int i = 0; i < entries.length; i++) { 69 if (entries[i].isDeletion()) { 70 MessageDialog.openError(getShell(), CVSUIMessages.OpenLogEntryAction_deletedTitle, CVSUIMessages.OpenLogEntryAction_deleted); } else { 72 ICVSRemoteFile file = entries[i].getRemoteFile(); 73 CVSUIPlugin.getPlugin().openEditor(file, monitor); 74 } 75 } 76 } 77 }, false, PROGRESS_BUSYCURSOR); 78 } 79 82 public boolean isEnabled() { 83 ILogEntry[] entries = getSelectedLogEntries(); 84 if (entries.length == 0) return false; 85 return true; 86 } 87 } 88 | Popular Tags |