1 11 package org.eclipse.jdt.internal.ui.browsing; 12 13 import org.eclipse.core.resources.IWorkspace; 14 import org.eclipse.core.runtime.IAdaptable; 15 16 import org.eclipse.jface.viewers.ISelection; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.actions.OpenInNewWindowAction; 21 22 import org.eclipse.jdt.core.IJavaElement; 23 import org.eclipse.jdt.core.JavaCore; 24 25 31 public class PatchedOpenInNewWindowAction extends OpenInNewWindowAction { 32 33 private IWorkbenchWindow fWorkbenchWindow; 34 35 public PatchedOpenInNewWindowAction(IWorkbenchWindow window, IAdaptable input) { 36 super(window, input); 37 fWorkbenchWindow= window; 38 } 39 40 public void run() { 41 JavaBrowsingPerspectiveFactory.setInputFromAction(getSelectedJavaElement()); 42 try { 43 super.run(); 44 } finally { 45 JavaBrowsingPerspectiveFactory.setInputFromAction(null); 46 } 47 } 48 49 private IJavaElement getSelectedJavaElement() { 50 if (fWorkbenchWindow.getActivePage() != null) { 51 ISelection selection= fWorkbenchWindow.getActivePage().getSelection(); 52 if (selection instanceof IStructuredSelection && !selection.isEmpty()) { 53 Object selectedElement= ((IStructuredSelection)selection).getFirstElement(); 54 if (selectedElement instanceof IJavaElement) 55 return (IJavaElement)selectedElement; 56 if (!(selectedElement instanceof IJavaElement) && selectedElement instanceof IAdaptable) 57 return (IJavaElement)((IAdaptable)selectedElement).getAdapter(IJavaElement.class); 58 else if (selectedElement instanceof IWorkspace) 59 return JavaCore.create(((IWorkspace)selectedElement).getRoot()); 60 } 61 } 62 return null; 63 } 64 } 65 | Popular Tags |