1 11 package org.eclipse.jdt.internal.ui.typehierarchy; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.jface.viewers.ISelectionProvider; 16 17 import org.eclipse.ui.PlatformUI; 18 19 import org.eclipse.jdt.core.IType; 20 21 import org.eclipse.jdt.internal.corext.util.Messages; 22 23 import org.eclipse.jdt.ui.ITypeHierarchyViewPart; 24 import org.eclipse.jdt.ui.JavaElementLabels; 25 26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 27 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 28 29 32 public class FocusOnSelectionAction extends Action { 33 34 private ITypeHierarchyViewPart fViewPart; 35 36 public FocusOnSelectionAction(ITypeHierarchyViewPart part) { 37 super(TypeHierarchyMessages.FocusOnSelectionAction_label); 38 setDescription(TypeHierarchyMessages.FocusOnSelectionAction_description); 39 setToolTipText(TypeHierarchyMessages.FocusOnSelectionAction_tooltip); 40 fViewPart= part; 41 42 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FOCUS_ON_SELECTION_ACTION); 43 } 44 45 private ISelection getSelection() { 46 ISelectionProvider provider= fViewPart.getSite().getSelectionProvider(); 47 if (provider != null) { 48 return provider.getSelection(); 49 } 50 return null; 51 } 52 53 54 57 public void run() { 58 Object element= SelectionUtil.getSingleElement(getSelection()); 59 if (element instanceof IType) { 60 fViewPart.setInputElement((IType)element); 61 } 62 } 63 64 public boolean canActionBeAdded() { 65 Object element= SelectionUtil.getSingleElement(getSelection()); 66 if (element instanceof IType) { 67 IType type= (IType)element; 68 setText(Messages.format( 69 TypeHierarchyMessages.FocusOnSelectionAction_label, 70 JavaElementLabels.getTextLabel(type, 0))); 71 return true; 72 } 73 return false; 74 } 75 } 76 | Popular Tags |