Class TypeHierarchyViewPart

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.ui.part.WorkbenchPart
org.eclipse.ui.part.ViewPart
org.eclipse.handly.ui.typehierarchy.TypeHierarchyViewPart
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IExecutableExtension, org.eclipse.ui.IPersistable, org.eclipse.ui.IViewPart, org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.IWorkbenchPart2, org.eclipse.ui.IWorkbenchPart3, org.eclipse.ui.part.IWorkbenchPartOrientation

public abstract class TypeHierarchyViewPart extends org.eclipse.ui.part.ViewPart
An abstract base implementation of a type hierarchy view.
Since:
1.6
  • Field Details

    • GROUP_FOCUS

      protected static final String GROUP_FOCUS
      Pop-up menu: name of group for focus actions (value "group.focus").
      See Also:
  • Constructor Details

    • TypeHierarchyViewPart

      public TypeHierarchyViewPart()
      Constructs a type hierarchy view that supports all of the type hierarchy kinds.
      See Also:
    • TypeHierarchyViewPart

      public TypeHierarchyViewPart(Set<TypeHierarchyKind> supportedHierarchyKinds)
      Constructs a type hierarchy view that supports the given type hierarchy kinds. Clients must not modify the given set afterwards.
      Parameters:
      supportedHierarchyKinds - not null and not empty
  • Method Details

    • arePossibleInputElements

      public boolean arePossibleInputElements(Object[] elements)
      Returns whether the given elements are possible input elements for this view.

      Default implementation invokes isPossibleInputElement(Object) for each of the given elements until false is returned for an element (in which case this method will return false) or all elements have been checked (in which case it will return true).

      Parameters:
      elements - may be null or may contain null elements, in which case false will be returned; may be empty, in which case true will be returned
      Returns:
      true if the given elements are possible input elements for this view, and false otherwise
    • setInputElements

      public void setInputElements(Object[] elements)
      Sets the current input elements for this view. Clients must not modify the given array afterwards.
      Parameters:
      elements - not null, must not contain null elements; may be empty
      Throws:
      IllegalArgumentException - if arePossibleInputElements(Object[]) returns false for the given elements
    • getInputElements

      public final Object[] getInputElements()
      Returns the current input elements for this view.
      Returns:
      the current input elements (never null, may be empty). Clients must not modify the returned array.
    • isEnabledHierarchyKind

      public final boolean isEnabledHierarchyKind(TypeHierarchyKind kind)
      Returns whether the given hierarchy kind is currently enabled for this view.
      Parameters:
      kind - may be null, in which case false will be returned
      Returns:
      true if the given kind is currently enabled, and false otherwise
    • setHierarchyKind

      public void setHierarchyKind(TypeHierarchyKind kind)
      Sets the current hierarchy kind for this view.
      Parameters:
      kind - not null
      Throws:
      IllegalArgumentException - if the given kind is not currently enabled for this view
    • getHierarchyKind

      public final TypeHierarchyKind getHierarchyKind()
      Returns the current hierarchy kind for this view.
      Returns:
      the current hierarchy kind (never null)
      See Also:
    • setLayoutMode

      public void setLayoutMode(int layoutMode)
      Sets layout mode for this view, which may be one of the constants SWT.HORIZONTAL or SWT.VERTICAL; this method may also be called with SWT.HORIZONTAL|SWT.VERTICAL for automatic layout or SWT.NONE for hierarchy-only layout.

      Note that only a subset of the allowed values for layout mode may be supported by the view.

      Parameters:
      layoutMode - the given layout mode
      Throws:
      IllegalArgumentException - if the given layout mode is not supported by the view
    • getLayoutMode

      public final int getLayoutMode()
      Returns the current layout mode for this view.
      Returns:
      the current layout mode
      See Also:
    • supportsLayoutMode

      public boolean supportsLayoutMode(int layoutMode)
      Returns true if the given value represents a supported layout mode for this view, and false otherwise. The set of the supported layout mode values does not change over the lifetime of the view and is never empty.

      Default implementation only supports SWT.NONE, which represents hierarchy-only layout.

      Parameters:
      layoutMode - the layout mode to check
      Returns:
      true if the given value represents a supported layout mode for this view, and false otherwise
    • refresh

      public final void refresh()
      Performs a full refresh of the content of this view.
    • init

      public void init(org.eclipse.ui.IViewSite site, org.eclipse.ui.IMemento memento) throws org.eclipse.ui.PartInitException
      Specified by:
      init in interface org.eclipse.ui.IViewPart
      Overrides:
      init in class org.eclipse.ui.part.ViewPart
      Throws:
      org.eclipse.ui.PartInitException
    • saveState

      public void saveState(org.eclipse.ui.IMemento memento)
      Specified by:
      saveState in interface org.eclipse.ui.IPersistable
      Specified by:
      saveState in interface org.eclipse.ui.IViewPart
      Overrides:
      saveState in class org.eclipse.ui.part.ViewPart
    • createPartControl

      public void createPartControl(org.eclipse.swt.widgets.Composite parent)
      Specified by:
      createPartControl in interface org.eclipse.ui.IWorkbenchPart
      Specified by:
      createPartControl in class org.eclipse.ui.part.WorkbenchPart
    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.eclipse.ui.IWorkbenchPart
      Overrides:
      dispose in class org.eclipse.ui.part.WorkbenchPart
    • setFocus

      public void setFocus()
      Specified by:
      setFocus in interface org.eclipse.ui.IWorkbenchPart
      Specified by:
      setFocus in class org.eclipse.ui.part.WorkbenchPart
    • isPossibleInputElement

      protected abstract boolean isPossibleInputElement(Object element)
      Returns whether the given element is a possible input element for this view.
      Parameters:
      element - may be null, in which case false will be returned
      Returns:
      true if the given element is a possible input element for this view, and false otherwise
      See Also:
    • createHistoryEntry

      protected abstract TypeHierarchyViewPart.HistoryEntry createHistoryEntry(Object[] inputElements)
      Creates and returns a history entry for the given input elements.
      Parameters:
      inputElements - never null; never empty
      Returns:
      the created history entry (not null)
    • computeContentDescription

      protected abstract String computeContentDescription()
      Computes the content description for this view.
      Returns:
      the computed content description (not null)
      See Also:
      • WorkbenchPart.getContentDescription()
    • isOpen

      protected final boolean isOpen()
      Returns whether the view has already been opened and has not yet been closed.
      Returns:
      true if the view is currently open, and false otherwise
    • refresh

      protected void refresh(IContext context)
      Performs a refresh of the content of this view according to options specified in the given context.
      Parameters:
      context - the operation context (never null)
    • updateHierarchyPage

      protected void updateHierarchyPage()
      Ensures that the appropriate hierarchy page is shown by this view.

      This method may only be called after the SWT controls for this view have been created and before they have been disposed.

    • onInputElementsChanged

      protected void onInputElementsChanged(Object[] oldInputElements, Object[] newInputElements)
      A callback that is invoked when the view input elements change.
      Parameters:
      oldInputElements - never null
      newInputElements - never null
    • onHierarchyKindChanged

      protected void onHierarchyKindChanged(TypeHierarchyKind oldKind, TypeHierarchyKind newKind)
      A callback that is invoked when the current hierarchy kind changes.
      Parameters:
      oldKind - never null
      newKind - never null
    • getSupportedHierarchyKinds

      protected final Set<TypeHierarchyKind> getSupportedHierarchyKinds()
      Returns a set of the supported hierarchy kinds for this view.
      Returns:
      the supported hierarchy kinds (never null, never empty)
    • setEnabledHierarchyKinds

      protected void setEnabledHierarchyKinds(Set<TypeHierarchyKind> kinds)
      Sets the enabled hierarchy kinds for this view. Note that at least one hierarchy kind must be enabled. Clients must not modify the given set afterwards.
      Parameters:
      kinds - not null and not empty
    • onEnabledHierarchyKindsChanged

      protected void onEnabledHierarchyKindsChanged(Set<TypeHierarchyKind> oldKinds, Set<TypeHierarchyKind> newKinds)
      A callback that is invoked when the set of enabled hierarchy kinds changes.
      Parameters:
      oldKinds - never null
      newKinds - never null
    • onLayoutModeChanged

      protected void onLayoutModeChanged(int oldLayoutMode, int newLayoutMode)
      A callback that is invoked when the view layout mode changes.
      Parameters:
      oldLayoutMode - the old layout mode
      newLayoutMode - the new layout mode
    • updateStatusLine

      protected void updateStatusLine(org.eclipse.jface.action.IStatusLineManager manager, org.eclipse.jface.viewers.IStructuredSelection selection)
      Updates the status line based on the given selection in this view.

      Default implementation clears the status line message if the selection is empty or if exactly one element is selected; sets a generic message of the form "(x) items selected" otherwise. It always clears the error message.

      Parameters:
      manager - the status line manager (never null)
      selection - the current selection (never null)
    • createNoHierarchyPage

      protected org.eclipse.swt.widgets.Control createNoHierarchyPage(org.eclipse.swt.widgets.Composite parent)
      Creates and returns a control for the 'no hierarchy' page. This method is called once, when the part's control is created.

      Default implementation returns a Label telling, in general terms, that there is no type hierarchy to display. Subclasses may override this method (e.g., to give details on what the user needs to do to display a type hierarchy).

      Parameters:
      parent - the parent composite (never null)
      Returns:
      the created control (not null)
    • getSashForm

      protected final org.eclipse.swt.custom.SashForm getSashForm()
      Returns the SashForm created for this view.
      Returns:
      the SashForm, or null if it has yet to be created
    • getHierarchyViewer

      protected final org.eclipse.jface.viewers.TreeViewer getHierarchyViewer(TypeHierarchyKind kind)
      Returns the hierarchy tree viewer for the given hierarchy kind.
      Parameters:
      kind - the type hierarchy kind (never null)
      Returns:
      the hierarchy tree viewer, or null if it has yet to be created
      See Also:
    • createHierarchyViewer

      protected org.eclipse.jface.viewers.TreeViewer createHierarchyViewer(org.eclipse.swt.widgets.Composite parent, TypeHierarchyKind kind)
      Creates and returns a tree viewer that will be used for displaying the type hierarchy of the given kind. This method only creates the viewer; it does not configure it. This method is called once, when the part's control is created.
      Parameters:
      parent - the parent composite (never null)
      kind - the type hierarchy kind (never null)
      Returns:
      the created viewer (not null)
      See Also:
    • configureHierarchyViewer

      protected abstract void configureHierarchyViewer(org.eclipse.jface.viewers.TreeViewer viewer, TypeHierarchyKind kind)
      Configures the newly created hierarchy viewer for the given hierarchy kind. This method has to set as least a content provider and a label provider. This method is called once, just after the viewer is created.
      Parameters:
      viewer - the viewer to configure (never null)
      kind - the type hierarchy kind (never null)
    • setHierarchyViewerInput

      protected void setHierarchyViewerInput(org.eclipse.jface.viewers.TreeViewer viewer, TypeHierarchyKind kind)
      Sets the input for the hierarchy viewer for the given hierarchy kind.
      Parameters:
      viewer - the viewer to set the input for (never null)
      kind - the type hierarchy kind (never null)
    • createHierarchyViewerMenuGroups

      protected void createHierarchyViewerMenuGroups(org.eclipse.jface.action.IMenuManager manager, TypeHierarchyKind kind)
      Creates the menu groups for the pop-up menu of the hierarchy viewer of the given hierarchy kind. This method is called each time the pop-up menu is about to show, just before fillHierarchyViewerMenu(org.eclipse.jface.action.IMenuManager, org.eclipse.handly.ui.typehierarchy.TypeHierarchyKind) is called.

      Default implementation adds groups named GROUP_FOCUS and IWorkbenchActionConstants.MB_ADDITIONS. Subclasses may extend or override this method, but should usually keep the default groups.

      Parameters:
      manager - the menu manager (never null)
      kind - the type hierarchy kind (never null)
    • fillHierarchyViewerMenu

      protected void fillHierarchyViewerMenu(org.eclipse.jface.action.IMenuManager manager, TypeHierarchyKind kind)
      Fills the pop-menu for the hierarchy viewer for the given hierarchy kind using the menu groups created by createHierarchyViewerMenuGroups(org.eclipse.jface.action.IMenuManager, org.eclipse.handly.ui.typehierarchy.TypeHierarchyKind). This method is called each time the pop-up menu is about to show.

      Default implementation adds generic actions such as 'focus on selection'. Subclasses may extend or override this method.

      Parameters:
      manager - the menu manager (never null)
      kind - the type hierarchy kind (never null)
    • onHierarchySelectionChanged

      protected void onHierarchySelectionChanged(org.eclipse.jface.viewers.ISelection selection, TypeHierarchyKind kind)
      A callback that is invoked when selection changes in the hierarchy viewer for the given hierarchy kind.

      Default implementation tries to reveal the selected hierarchy node in an open editor with revealInEditor.

      Parameters:
      selection - the new selection (never null)
      kind - the type hierarchy kind (never null)
    • revealInEditor

      protected void revealInEditor(Object element, boolean activate, boolean mayOpenNewEditor) throws org.eclipse.ui.PartInitException
      Reveals the given element in an appropriate editor on a best effort basis.

      Default implementation uses the editor opener.

      Parameters:
      element - not null
      activate - whether to activate the editor
      mayOpenNewEditor - whether a new editor may be opened when the element cannot be revealed in an existing editor
      Throws:
      org.eclipse.ui.PartInitException - if a new editor could not be created or initialized
    • getEditorOpener

      protected final EditorOpener getEditorOpener()
      Returns the editor opener used by this view.
      Returns:
      the editor opener, or null if it has yet to be created
      See Also:
    • createEditorOpener

      protected EditorOpener createEditorOpener()
      Creates and returns an editor opener for this view. This method is called once, when the part's control is created.

      Subclasses may override this method if they require a specific editor opener.

      Returns:
      the created editor opener (not null)
    • getFocusOnSelectionAction

      protected final org.eclipse.jface.action.IAction getFocusOnSelectionAction()
      Returns the 'focus on selection' action used by this view.
      Returns:
      the 'focus on selection' action
    • addRefreshAction

      protected void addRefreshAction(org.eclipse.jface.action.IAction action)
      Contributes the 'refresh' action to this view. This method is called once, when the part's control is created.

      Default implementation adds the given action to the view tool bar. Subclasses may extend or override this method.

      Parameters:
      action - the 'refresh' action (never null)
    • addSetHierarchyKindAction

      protected void addSetHierarchyKindAction(org.eclipse.jface.action.IAction action, TypeHierarchyKind kind)
      Contributes a 'set hierarchy kind' action to this view. This method is called once for each of the 'set hierarchy kind' actions, when the part's control is created. If this view supports only one hierarchy kind, no 'set hierarchy kind' action is created and this method is not called.

      Default implementation adds the given action to the view tool bar as well as to the view menu. Subclasses may extend or override this method.

      Parameters:
      action - a 'set hierarchy kind' action (never null)
      kind - the hierarchy kind set by the given action (never null)
      See Also:
    • addSetLayoutModeAction

      protected void addSetLayoutModeAction(org.eclipse.jface.action.IAction action, int layoutMode)
      Contributes a 'set layout mode' action to this view. This method is called once for each of the 'set layout mode' actions, when the part's control is created. If this view supports only one layout mode, no 'set layout mode' action is created and this method is not called.

      Default implementation adds the given action to the 'Layout' sub-menu of the view menu. The sub-menu is created if necessary. Subclasses may extend or override this method.

      Parameters:
      action - a 'set layout mode' action (never null)
      layoutMode - the layout mode set by the given action
      See Also:
    • createHistoryDropDownAction

      Creates and returns a 'show history list' action for this view. This method is called once, when the part's control is created.

      Subclasses need to override this method if they extend HistoryDropDownAction.

      Parameters:
      history - never null
      Returns:
      the created action (not null)
    • addHistoryDropDownAction

      protected void addHistoryDropDownAction(org.eclipse.jface.action.IAction action)
      Contributes the 'show history list' action to this view. This method is called once, when the part's control is created.

      Default implementation adds the given action to the view tool bar. Subclasses may extend or override this method.

      Parameters:
      action - the 'show history list' action (never null)
    • getHistory

      protected List<TypeHierarchyViewPart.HistoryEntry> getHistory()
      Returns the history used by this view; the history is represented by a "live" list of history entries.
      Returns:
      the view history (never null)
    • onHistoryChanged

      protected void onHistoryChanged()
      A callback that is invoked when the history has been updated.

      Default implementation sets the enabled state of the 'show history list' action according to whether the history is empty and, if the history is empty, clears the view input.

      See Also: