public void run(IAction action) { ElementSelectionDialog dialog = new ElementSelectionDialog(getShell()); configureDialog(dialog); int result = dialog.open(); if (result != IDialogConstants.OK_ID) return; ITypeInfo info = (ITypeInfo) dialog.getFirstResult(); if (info == null) return; ICElement[] elements = null; ITypeReference location = info.getResolvedReference(); if (location != null) { elements = location.getCElements(); } if (elements == null || elements.length == 0) { String title = Messages.OpenTypeInHierarchyAction_errorTitle; String message = NLS.bind( Messages.OpenTypeInHierarchyAction_errorNoDefinition, info.getQualifiedTypeName().toString()); MessageDialog.openError(getShell(), title, message); } else { IProject project = elements[0].getCProject().getProject(); IServiceModelManager smm = ServiceModelManager.getInstance(); IServiceConfiguration serviceConfig = smm.getActiveConfiguration(project); IService indexingService = smm.getService(IRDTServiceConstants.SERVICE_C_INDEX); IServiceProvider serviceProvider = serviceConfig.getServiceProvider(indexingService); if (serviceProvider instanceof IIndexServiceProvider) { ITypeHierarchyService service = ((IIndexServiceProvider) serviceProvider).getTypeHierarchyService(); TypeHierarchyUtil.open(service, elements[0], fWorkbenchWindow); } } }
private void configureDialog(ElementSelectionDialog dialog) { dialog.setDialogSettings(getClass().getName()); dialog.setVisibleTypes(VISIBLE_TYPES); dialog.setTitle(Messages.OpenTypeInHierarchyAction_title); dialog.setUpperListLabel(Messages.OpenTypeInHierarchyAction_upperListLabel); dialog.setMessage(Messages.OpenTypeInHierarchyAction_message); if (fWorkbenchWindow != null) { IWorkbenchPage page = fWorkbenchWindow.getActivePage(); if (page != null) { IWorkbenchPart part = page.getActivePart(); if (part instanceof ITextEditor) { ISelection sel = ((ITextEditor) part).getSelectionProvider().getSelection(); if (sel instanceof ITextSelection) { String txt = ((ITextSelection) sel).getText(); if (txt.length() > 0 && txt.length() < 80) { dialog.setFilter(txt, true); } } } } } }