Index: src/org/eclipse/dltk/ui/actions/OpenViewActionGroup.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/OpenViewActionGroup.java,v retrieving revision 1.6 diff -u -r1.6 OpenViewActionGroup.java --- src/org/eclipse/dltk/ui/actions/OpenViewActionGroup.java 25 May 2007 08:21:06 -0000 1.6 +++ src/org/eclipse/dltk/ui/actions/OpenViewActionGroup.java 11 Apr 2008 13:24:47 -0000 @@ -34,14 +34,14 @@ public class OpenViewActionGroup extends ActionGroup { private boolean fEditorIsOwner; -// private boolean fIsTypeHiararchyViewerOwner; + private boolean fIsTypeHiararchyViewerOwner; private boolean fIsCallHiararchyViewerOwner; private ISelectionProvider fSelectionProvider; //private OpenSuperImplementationAction fOpenSuperImplementation; //private OpenExternalJavadocAction fOpenExternalJavadoc; -// private OpenTypeHierarchyAction fOpenTypeHierarchy; + private OpenTypeHierarchyAction fOpenTypeHierarchy; private OpenCallHierarchyAction fOpenCallHierarchy; private PropertyDialogAction fOpenPropertiesDialog; @@ -99,7 +99,7 @@ createSiteActions(part.getSite(), selectionProvider); // we do a name check here to avoid class loading. String partName= part.getClass().getName(); -// fIsTypeHiararchyViewerOwner= "org.eclipse.dltk.internal.ui.typehierarchy.TypeHierarchyViewPart".equals(partName); //$NON-NLS-1$ + fIsTypeHiararchyViewerOwner= "org.eclipse.dltk.internal.ui.typehierarchy.TypeHierarchyViewPart".equals(partName); //$NON-NLS-1$ fIsCallHiararchyViewerOwner= "org.eclipse.dltk.internal.ui.callhierarchy.CallHierarchyViewPart".equals(partName); //$NON-NLS-1$ } @@ -137,9 +137,9 @@ //fOpenExternalJavadoc.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); //part.setAction("OpenExternalJavadoc", fOpenExternalJavadoc); //$NON-NLS-1$ -// fOpenTypeHierarchy= new OpenTypeHierarchyAction(part); -// fOpenTypeHierarchy.setActionDefinitionId(IDLTKEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); -// part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$ + fOpenTypeHierarchy= new OpenTypeHierarchyAction(part); + fOpenTypeHierarchy.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); + part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$ if( !disableCallHierarcy ) { fOpenCallHierarchy= new OpenCallHierarchyAction(part); fOpenCallHierarchy.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_CALL_HIERARCHY); @@ -158,9 +158,9 @@ // fOpenExternalJavadoc.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_EXTERNAL_JAVADOC); // fOpenExternalJavadoc.setSpecialSelectionProvider(specialProvider); // -// fOpenTypeHierarchy= new OpenTypeHierarchyAction(site); -// fOpenTypeHierarchy.setActionDefinitionId(IDLTKEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); -// fOpenTypeHierarchy.setSpecialSelectionProvider(specialProvider); + fOpenTypeHierarchy= new OpenTypeHierarchyAction(site); + fOpenTypeHierarchy.setActionDefinitionId(IScriptEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY); + fOpenTypeHierarchy.setSpecialSelectionProvider(specialProvider); if( !disableCallHierarcy ) { fOpenCallHierarchy= new OpenCallHierarchyAction(site); @@ -183,7 +183,7 @@ ISelection selection= provider.getSelection(); // fOpenSuperImplementation.update(selection); // fOpenExternalJavadoc.update(selection); -// fOpenTypeHierarchy.update(selection); + fOpenTypeHierarchy.update(selection); if( !disableCallHierarcy ) { fOpenCallHierarchy.update(selection); } @@ -198,7 +198,7 @@ } // provider.addSelectionChangedListener(fOpenSuperImplementation); // provider.addSelectionChangedListener(fOpenExternalJavadoc); -// provider.addSelectionChangedListener(fOpenTypeHierarchy); + provider.addSelectionChangedListener(fOpenTypeHierarchy); if( !disableCallHierarcy ) { provider.addSelectionChangedListener(fOpenCallHierarchy); } @@ -219,8 +219,8 @@ */ public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu); -// if (!fIsTypeHiararchyViewerOwner) -// appendToGroup(menu, fOpenTypeHierarchy); + if (!fIsTypeHiararchyViewerOwner) + appendToGroup(menu, fOpenTypeHierarchy); if (!fIsCallHiararchyViewerOwner) { if( !disableCallHierarcy ) { appendToGroup(menu, fOpenCallHierarchy); @@ -237,7 +237,7 @@ public void dispose() { // fSelectionProvider.removeSelectionChangedListener(fOpenSuperImplementation); // fSelectionProvider.removeSelectionChangedListener(fOpenExternalJavadoc); -// fSelectionProvider.removeSelectionChangedListener(fOpenTypeHierarchy); + fSelectionProvider.removeSelectionChangedListener(fOpenTypeHierarchy); if( !disableCallHierarcy ) { fSelectionProvider.removeSelectionChangedListener(fOpenCallHierarchy); } @@ -247,7 +247,7 @@ private void setGlobalActionHandlers(IActionBars actionBars) { // actionBars.setGlobalActionHandler(DLTKActionConstants.OPEN_SUPER_IMPLEMENTATION, fOpenSuperImplementation); // actionBars.setGlobalActionHandler(DLTKActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc); -// actionBars.setGlobalActionHandler(DLTKActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy); + actionBars.setGlobalActionHandler(DLTKActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy); if( !disableCallHierarcy ) { actionBars.setGlobalActionHandler(DLTKActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy); } Index: src/org/eclipse/dltk/ui/actions/DLTKActionConstants.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/DLTKActionConstants.java,v retrieving revision 1.2 diff -u -r1.2 DLTKActionConstants.java --- src/org/eclipse/dltk/ui/actions/DLTKActionConstants.java 2 May 2007 15:07:29 -0000 1.2 +++ src/org/eclipse/dltk/ui/actions/DLTKActionConstants.java 11 Apr 2008 13:24:47 -0000 @@ -530,4 +530,11 @@ public static final String FIND_IMPLEMENT_OCCURRENCES= "org.eclipse.dltk.ui.actions.ImplementOccurrences"; //$NON-NLS-1$ + /** + * Navigate menu: name of standard Open Type Hierarchy global action + * (value "org.eclipse.dltk.ui.actions.OpenTypeHierarchy"). + */ + public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.dltk.ui.actions.OpenTypeHierarchy"; //$NON-NLS-1$ + + } Index: src/org/eclipse/dltk/internal/ui/actions/ActionMessages.properties =================================================================== RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/ActionMessages.properties,v retrieving revision 1.5 diff -u -r1.5 ActionMessages.properties --- src/org/eclipse/dltk/internal/ui/actions/ActionMessages.properties 12 Mar 2008 11:06:03 -0000 1.5 +++ src/org/eclipse/dltk/internal/ui/actions/ActionMessages.properties 11 Apr 2008 13:24:46 -0000 @@ -80,3 +80,13 @@ ToggleLinkingAction_tooltip=Link with Editor ToggleLinkingAction_description=Link with active editor RefactorActionGroup_noRefactoringAvailable= + +OpenTypeHierarchyAction_label=Ope&n Type Hierarchy +OpenTypeHierarchyAction_tooltip=Open a Type Hierarchy on the Selected Element +OpenTypeHierarchyAction_description=Open a type hierarchy on the selected element +OpenTypeHierarchyAction_dialog_title=Open Type Hierarchy +OpenTypeHierarchyAction_messages_title=Cannot create type hierarchy +OpenTypeHierarchyAction_messages_no_java_element=A Java element must be selected. +OpenTypeHierarchyAction_messages_no_java_resources=The selected package does not contain any Java resource. +OpenTypeHierarchyAction_messages_no_types=The selected compilation unit does not contain a type. +OpenTypeHierarchyAction_messages_no_valid_java_element=A valid Java element must be selected. Index: src/org/eclipse/dltk/internal/ui/actions/ActionMessages.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/internal/ui/actions/ActionMessages.java,v retrieving revision 1.5 diff -u -r1.5 ActionMessages.java --- src/org/eclipse/dltk/internal/ui/actions/ActionMessages.java 12 Mar 2008 11:06:03 -0000 1.5 +++ src/org/eclipse/dltk/internal/ui/actions/ActionMessages.java 11 Apr 2008 13:24:46 -0000 @@ -71,4 +71,14 @@ public static String OpenNewSourceFolderWizardAction_text2; public static String OpenNewSourceFolderWizardAction_description; public static String OpenNewSourceFolderWizardAction_tooltip; + + public static String OpenTypeHierarchyAction_label; + public static String OpenTypeHierarchyAction_tooltip; + public static String OpenTypeHierarchyAction_description; + public static String OpenTypeHierarchyAction_messages_no_script_element; + public static String OpenTypeHierarchyAction_messages_title; + public static String OpenTypeHierarchyAction_dialog_title; + public static String OpenTypeHierarchyAction_messages_no_script_resources; + public static String OpenTypeHierarchyAction_messages_no_types; + public static String OpenTypeHierarchyAction_messages_no_valid_script_element; } Index: plugin.xml =================================================================== RCS file: /cvsroot/technology/org.eclipse.dltk/core/plugins/org.eclipse.dltk.ui/plugin.xml,v retrieving revision 1.41 diff -u -r1.41 plugin.xml --- plugin.xml 10 Apr 2008 13:21:28 -0000 1.41 +++ plugin.xml 11 Apr 2008 13:24:46 -0000 @@ -764,13 +764,13 @@ menubarPath="navigate/open.ext" id="org.eclipse.dltk.ui.actions.OpenCallHierarchy"> - + + * The action is applicable to selections containing elements of type + * IType. + * + *

+ * This class may be instantiated; it is not intended to be subclassed. + *

+ * + * @since 2.0 + */ +public class OpenTypeHierarchyAction extends SelectionDispatchAction { + + private ScriptEditor fEditor; + + /** + * Creates a new OpenTypeHierarchyAction. The action requires + * that the selection provided by the site's selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param site the site providing context information for this action + */ + public OpenTypeHierarchyAction(IWorkbenchSite site) { + super(site); + setText(ActionMessages.OpenTypeHierarchyAction_label); + setToolTipText(ActionMessages.OpenTypeHierarchyAction_tooltip); + setDescription(ActionMessages.OpenTypeHierarchyAction_description); +// PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_TYPE_HIERARCHY_ACTION); + } + + /** + * Creates a new OpenTypeHierarchyAction. The action requires + * that the selection provided by the given selection provider is of type + * org.eclipse.jface.viewers.IStructuredSelection. + * + * @param site the site providing context information for this action + * @param provider a special selection provider which is used instead + * of the site's selection provider or null to use the site's + * selection provider + * + * @since 3.2 + * @deprecated Use {@link #setSpecialSelectionProvider(ISelectionProvider)} instead. This API will be + * removed after 3.2 M5. + */ + public OpenTypeHierarchyAction(IWorkbenchSite site, ISelectionProvider provider) { + this(site); + setSpecialSelectionProvider(provider); + } + + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + * @param editor the Script editor + */ + public OpenTypeHierarchyAction(ScriptEditor editor) { + this(editor.getEditorSite()); + fEditor= editor; + setEnabled(SelectionConverter.canOperateOn(fEditor)); + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(ITextSelection selection) { + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void selectionChanged(IStructuredSelection selection) { + setEnabled(isEnabled(selection)); + } + + private boolean isEnabled(IStructuredSelection selection) { + if (selection.size() != 1) + return false; + Object input= selection.getFirstElement(); + + + if (input instanceof LogicalPackage) + return true; + + if (!(input instanceof IModelElement)) + return false; + switch (((IModelElement)input).getElementType()) { +// case IModelElement.INITIALIZER: + case IModelElement.METHOD: + case IModelElement.FIELD: + case IModelElement.TYPE: + return true; + case IModelElement.PROJECT_FRAGMENT: + case IModelElement.SCRIPT_PROJECT: + case IModelElement.SCRIPT_FOLDER: + case IModelElement.PACKAGE_DECLARATION: +// case IModelElement.IMPORT_DECLARATION: +// case IModelElement.CLASS_FILE: + case IModelElement.SOURCE_MODULE: + return true; +// case IModelElement.LOCAL_VARIABLE: + default: + return false; + } + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(ITextSelection selection) { + IModelElement input= SelectionConverter.getInput(fEditor); + if (!ActionUtil.isProcessable(getShell(), input)) + return; + + try { + IModelElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); + if (elements == null) + return; + List candidates= new ArrayList(elements.length); + for (int i= 0; i < elements.length; i++) { + IModelElement[] resolvedElements= OpenTypeHierarchyUtil.getCandidates(elements[i]); + if (resolvedElements != null) + candidates.addAll(Arrays.asList(resolvedElements)); + } + run((IModelElement[])candidates.toArray(new IModelElement[candidates.size()])); + } catch (InvocationTargetException e) { + ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.SelectionConverter_codeResolve_failed); + } catch (InterruptedException e) { + // cancelled + } + } + + /* (non-Javadoc) + * Method declared on SelectionDispatchAction. + */ + public void run(IStructuredSelection selection) { + if (selection.size() != 1) + return; + Object input= selection.getFirstElement(); + + if (input instanceof LogicalPackage) { + IScriptFolder[] fragments= ((LogicalPackage)input).getFragments(); + if (fragments.length == 0) + return; + input= fragments[0]; + } + + if (!(input instanceof IModelElement)) { + IStatus status= createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_script_element); + ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenTypeHierarchyAction_messages_title, status); + return; + } + IModelElement element= (IModelElement) input; + if (!ActionUtil.isProcessable(getShell(), element)) + return; + + List result= new ArrayList(1); + IStatus status= compileCandidates(result, element); + if (status.isOK()) { + run((IModelElement[]) result.toArray(new IModelElement[result.size()])); + } else { + ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenTypeHierarchyAction_messages_title, status); + } + } + + /* + * No Javadoc since the method isn't meant to be public but is + * since the beginning + */ + public void run(IModelElement[] elements) { + if (elements.length == 0) { + getShell().getDisplay().beep(); + return; + } + OpenTypeHierarchyUtil.open(elements, getSite().getWorkbenchWindow()); + } + + private static String getDialogTitle() { + return ActionMessages.OpenTypeHierarchyAction_dialog_title; + } + + private static IStatus compileCandidates(List result, IModelElement elem) { + IStatus ok= new Status(IStatus.OK, DLTKUIPlugin.getPluginId(), 0, "", null); //$NON-NLS-1$ + try { + switch (elem.getElementType()) { +// case IModelElement.INITIALIZER: + case IModelElement.METHOD: + case IModelElement.FIELD: + case IModelElement.TYPE: + case IModelElement.PROJECT_FRAGMENT: + case IModelElement.SCRIPT_PROJECT: + result.add(elem); + return ok; + case IModelElement.SCRIPT_FOLDER: + if (((IScriptFolder)elem).containsScriptResources()) { + result.add(elem); + return ok; + } + return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_script_resources); + case IModelElement.PACKAGE_DECLARATION: + result.add(elem.getAncestor(IModelElement.SCRIPT_FOLDER)); + return ok; +// case IModelElement.IMPORT_DECLARATION: +// IImportDeclaration decl= (IImportDeclaration) elem; +// if (decl.isOnDemand()) { +// elem= JavaModelUtil.findTypeContainer(elem.getJavaProject(), Signature.getQualifier(elem.getElementName())); +// } else { +// elem= elem.getJavaProject().findType(elem.getElementName()); +// } +// if (elem != null) { +// result.add(elem); +// return ok; +// } +// return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_unknown_import_decl); +// case IJavaElement.CLASS_FILE: +// result.add(((IClassFile)elem).getType()); +// return ok; + case IModelElement.SOURCE_MODULE: + AbstractSourceModule cu= (AbstractSourceModule)elem; + IType[] types= cu.getTypes(); + if (types.length > 0) { + result.addAll(Arrays.asList(types)); + return ok; + } + return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_types); + } + } catch (ModelException e) { + return e.getStatus(); + } + return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_valid_script_element); + } + + private static IStatus createStatus(String message) { + return new Status(IStatus.INFO, DLTKUIPlugin.getPluginId(), IDLTKStatusConstants.INTERNAL_ERROR, message, null); + } +} +