1 8 package de.loskutov.bco.ui.actions; 9 10 import org.eclipse.core.resources.IContainer; 11 import org.eclipse.core.resources.IFile; 12 import org.eclipse.core.resources.IResource; 13 import org.eclipse.core.resources.ResourcesPlugin; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.JavaCore; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.IObjectActionDelegate; 20 import org.eclipse.ui.dialogs.ResourceListSelectionDialog; 21 22 import de.loskutov.bco.BytecodeOutlinePlugin; 23 24 27 public class OpenAction extends BytecodeAction implements IObjectActionDelegate { 28 29 32 public void run(IAction action) { 33 IJavaElement[] resources = getSelectedResources(); 35 36 IJavaElement element2 = selectJavaElement(); 38 if (element2 == null) { 39 return; 40 } 41 try { 42 exec(resources[0], element2); 43 } catch (Exception e) { 44 BytecodeOutlinePlugin.error("Failed to run Compare: " 45 + e.getMessage(), e); 46 } 47 } 48 49 private IJavaElement selectJavaElement() { 50 IContainer input = ResourcesPlugin.getWorkspace().getRoot(); 51 52 OpenClassFileDialog dialog = new OpenClassFileDialog( 53 shell, input, IResource.FILE); 54 55 int resultCode = dialog.open(); 56 if (resultCode != IDialogConstants.OK_ID) { 57 return null; 58 } 59 60 Object [] result = dialog.getResult(); 61 if (result == null || result.length == 0 62 || !(result[0] instanceof IFile)) { 63 return null; 64 } 65 return JavaCore.create((IFile) result[0]); 66 } 67 68 71 private static final class OpenClassFileDialog extends ResourceListSelectionDialog { 72 73 78 public OpenClassFileDialog(Shell parentShell, IContainer container, 79 int typesMask) { 80 super(parentShell, container, typesMask); 81 setTitle("Bytecode compare"); 82 setMessage("Please select class file to compare"); 83 } 84 85 89 protected boolean select(IResource resource) { 90 if (resource == null) { 91 return false; 92 } 93 String fileExtension = resource.getFileExtension(); 94 return super.select(resource) 95 && ("java".equals(fileExtension) || "class" 96 .equals(fileExtension)); 97 } 98 } 99 100 } 101 | Popular Tags |