Class PopupMenuBuilder

java.lang.Object
org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder

public class PopupMenuBuilder extends Object
This class is used to create a context menu.
  • Field Details

    • HIDE_COLUMN_MENU_ITEM_ID

      public static final String HIDE_COLUMN_MENU_ITEM_ID
      See Also:
    • SHOW_ALL_COLUMNS_MENU_ITEM_ID

      public static final String SHOW_ALL_COLUMNS_MENU_ITEM_ID
      See Also:
    • HIDE_ROW_MENU_ITEM_ID

      public static final String HIDE_ROW_MENU_ITEM_ID
      See Also:
    • SHOW_ALL_ROWS_MENU_ITEM_ID

      public static final String SHOW_ALL_ROWS_MENU_ITEM_ID
      See Also:
    • AUTO_RESIZE_COLUMN_MENU_ITEM_ID

      public static final String AUTO_RESIZE_COLUMN_MENU_ITEM_ID
      See Also:
    • AUTO_RESIZE_ROW_MENU_ITEM_ID

      public static final String AUTO_RESIZE_ROW_MENU_ITEM_ID
      See Also:
    • AUTO_RESIZE_ALL_SELECTED_COLUMN_MENU_ITEM_ID

      public static final String AUTO_RESIZE_ALL_SELECTED_COLUMN_MENU_ITEM_ID
      See Also:
    • COLUMN_CHOOSER_MENU_ITEM_ID

      public static final String COLUMN_CHOOSER_MENU_ITEM_ID
      See Also:
    • COLUMN_STYLE_EDITOR_MENU_ITEM_ID

      public static final String COLUMN_STYLE_EDITOR_MENU_ITEM_ID
      See Also:
    • COLUMN_RENAME_MENU_ITEM_ID

      public static final String COLUMN_RENAME_MENU_ITEM_ID
      See Also:
    • CREATE_COLUMN_GROUP_MENU_ITEM_ID

      public static final String CREATE_COLUMN_GROUP_MENU_ITEM_ID
      See Also:
    • RENAME_COLUMN_GROUP_MENU_ITEM_ID

      public static final String RENAME_COLUMN_GROUP_MENU_ITEM_ID
      See Also:
    • REMOVE_COLUMN_GROUP_MENU_ITEM_ID

      public static final String REMOVE_COLUMN_GROUP_MENU_ITEM_ID
      See Also:
    • UNGROUP_COLUMNS_MENU_ITEM_ID

      public static final String UNGROUP_COLUMNS_MENU_ITEM_ID
      See Also:
    • INSPECT_LABEL_MENU_ITEM_ID

      public static final String INSPECT_LABEL_MENU_ITEM_ID
      See Also:
    • CATEGORIES_BASED_COLUMN_CHOOSER_MENU_ITEM_ID

      public static final String CATEGORIES_BASED_COLUMN_CHOOSER_MENU_ITEM_ID
      See Also:
    • CLEAR_ALL_FILTERS_MENU_ITEM_ID

      public static final String CLEAR_ALL_FILTERS_MENU_ITEM_ID
      See Also:
    • TOGGLE_FILTER_ROW_MENU_ITEM_ID

      public static final String TOGGLE_FILTER_ROW_MENU_ITEM_ID
      See Also:
    • STATE_MANAGER_MENU_ITEM_ID

      public static final String STATE_MANAGER_MENU_ITEM_ID
      See Also:
    • SEPARATOR_MENU_ITEM_ID

      public static final String SEPARATOR_MENU_ITEM_ID
      See Also:
    • EXPORT_IMAGE_MENU_ITEM_ID

      public static final String EXPORT_IMAGE_MENU_ITEM_ID
      Since:
      1.5
      See Also:
    • CREATE_ROW_GROUP_MENU_ITEM_ID

      public static final String CREATE_ROW_GROUP_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • RENAME_ROW_GROUP_MENU_ITEM_ID

      public static final String RENAME_ROW_GROUP_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • REMOVE_ROW_GROUP_MENU_ITEM_ID

      public static final String REMOVE_ROW_GROUP_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • UNGROUP_ROWS_MENU_ITEM_ID

      public static final String UNGROUP_ROWS_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • FREEZE_COLUMN_MENU_ITEM_ID

      public static final String FREEZE_COLUMN_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • FREEZE_ROW_MENU_ITEM_ID

      public static final String FREEZE_ROW_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • FREEZE_POSITION_MENU_ITEM_ID

      public static final String FREEZE_POSITION_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • UNFREEZE_MENU_ITEM_ID

      public static final String UNFREEZE_MENU_ITEM_ID
      Since:
      1.6
      See Also:
    • natTable

      protected NatTable natTable
      The active NatTable instance the context menu should be added to. Needed in advance to be able to add custom menu items that need the NatTable instance.
    • popupMenu

      protected org.eclipse.swt.widgets.Menu popupMenu
      The Menu that is created with this popup menu builder.
    • visibility

      protected final MenuItemStateMap visibility
      Collection of all registered visibility state checkers for configured id's.
    • enablement

      protected final MenuItemStateMap enablement
      Collection of all registered enablement state checkers for configured id's.
    • parentBuilder

      protected PopupMenuBuilder parentBuilder
      The parent PopupMenuBuilder in case this instance is for building a submenu.
      Since:
      2.3
  • Constructor Details

    • PopupMenuBuilder

      public PopupMenuBuilder(NatTable parent)
      Creates PopupMenuBuilder that builds up a new Menu that is only configurable with this instance of PopupMenuBuilder. Uses a MenuManager internally to be able to configure visibility and enabled states.
      Parameters:
      parent - The active NatTable instance the context menu should be added to.
    • PopupMenuBuilder

      public PopupMenuBuilder(org.eclipse.jface.action.MenuManager manager)
      Creates a PopupMenuBuilder that builds up a new Menu using the given MenuManager.

      Note: If this constructor is used a Menu can only be created by using build(NatTable), otherwise it will fail with an exception.

      Parameters:
      manager - The MenuManager that should be used to create the Menu.
      Since:
      1.6
    • PopupMenuBuilder

      public PopupMenuBuilder(NatTable parent, org.eclipse.jface.action.MenuManager manager)
      Creates a PopupMenuBuilder that builds up a new Menu using the given MenuManager.
      Parameters:
      parent - The active NatTable instance the context menu should be added to.
      manager - The MenuManager that should be used to create the Menu.
    • PopupMenuBuilder

      public PopupMenuBuilder(NatTable natTable, org.eclipse.swt.widgets.Menu menu)
      Creates a popup menu builder based on the given menu. Using this enables the possibility to use configured context menus from plugin.xml and adding NatTable commands programmatically.

      As an example you might want to create a PopupMenuBuilder by using a configured menu with the id org.eclipse.nebula.widgets.nattable.example.contextmenu

       ISelectionProvider isp =
               new RowSelectionProvider<?>(selectionLayer, bodyDataProvider, false);
       MenuManager menuManager = new MenuManager();
       menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
       getSite().registerContextMenu(
               "org.eclipse.nebula.widgets.nattable.example.contextmenu", menuManager, isp);
       PopupMenuBuilder popupMenu =
               new PopupMenuBuilder(menuManager.createContextMenu(natTable));
       

      For usage with Eclipse 4 you can use the EMenuService to register the menu to a NatTable instance. Afterwards get the menu and remove it from the NatTable to avoid the SWT control menu. The generated menu carries a MenuManager in the Widget.getData() which will be used within this PopupMenuBuilder.

       menuService.registerContextMenu(natTable, menuId);
       Menu swtMenu = natTable.getMenu();
       natTable.setMenu(null);
       
      Parameters:
      natTable - The active NatTable instance which might be needed for creation of menu items that need the NatTable instance to work.
      menu - The registered context menu.
    • PopupMenuBuilder

      public PopupMenuBuilder(NatTable natTable, PopupMenuBuilder parent, org.eclipse.swt.widgets.Menu menu)
      Constructor to create a submenu. Intended to be used internally via withSubMenu(String, String, ImageDescriptor).
      Parameters:
      natTable - The active NatTable instance which might be needed for creation of menu items that need the NatTable instance to work.
      parent - The parent PopupMenuBuilder to which this instance should be added to create a submenu.
      menu - The Menu instance that represents the submenu.
      Since:
      2.3
      See Also:
    • PopupMenuBuilder

      public PopupMenuBuilder(NatTable natTable, PopupMenuBuilder parent, org.eclipse.jface.action.MenuManager menuManager)
      Constructor to create a submenu. Intended to be used internally via withSubMenu(String, String, ImageDescriptor).
      Parameters:
      natTable - The active NatTable instance which might be needed for creation of menu items that need the NatTable instance to work.
      parent - The parent PopupMenuBuilder to which this instance should be added to create a submenu.
      menuManager - The MenuManager that should be used to create the submenu.
      Since:
      2.3
      See Also:
  • Method Details

    • withMenuItemProvider

      public PopupMenuBuilder withMenuItemProvider(IMenuItemProvider menuItemProvider)
      Adds the menu item provided by the given IMenuItemProvider to the popup menu. You can use this to add your own item to the popup menu.

      Items added by this method can not be identified by id, so adding visible or enabled state checkers is not possible for these providers.

      Parameters:
      menuItemProvider - The IMenuItemProvider that provides the menu item that should be added to the popup menu.
      Returns:
      The current PopupMenuBuilder with the added item.
    • withMenuItemProvider

      public PopupMenuBuilder withMenuItemProvider(String id, IMenuItemProvider menuItemProvider)
      Adds the menu item provided by the given IMenuItemProvider to the popup menu. You can use this to add your own item to the popup menu.

      As items added by this method can be identified via the given id it is possible to register visible or enabled state checkers for these providers.

      Parameters:
      id - The id under which the given IMenuItemProvider should be identifiable.
      menuItemProvider - The IMenuItemProvider that provides the menu item that should be added to the popup menu.
      Returns:
      The current PopupMenuBuilder with the added item.
    • withContributionItem

      public PopupMenuBuilder withContributionItem(org.eclipse.jface.action.ContributionItem contributionItem)
      Adds the menu item(s) provided by the given ContributionItem to the popup menu. You can use this to add your own item to the popup menu.

      This method is only working if the PopupMenuBuilder is using a MenuManager.

      Using this adds support for visibility and enabled states of menu items.

      Parameters:
      contributionItem - The ContributionItem that is used to add a menu item to the menu.
      Returns:
      The current PopupMenuBuilder with the added item.
      Throws:
      IllegalStateException - if this PopupMenuBuilder does not use a MenuManager
    • withHideColumnMenuItem

      public PopupMenuBuilder withHideColumnMenuItem()
      Adds the menu item for hiding a column to the popup menu. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the hide column menu item added.
      See Also:
    • withHideColumnMenuItem

      public PopupMenuBuilder withHideColumnMenuItem(String menuLabel)
      Adds the menu item for hiding a column to the popup menu. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the hide column menu item added.
      See Also:
    • withShowAllColumnsMenuItem

      public PopupMenuBuilder withShowAllColumnsMenuItem()
      Adds the menu item for showing all columns to the popup menu. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the show all columns menu item added.
      See Also:
    • withShowAllColumnsMenuItem

      public PopupMenuBuilder withShowAllColumnsMenuItem(String menuLabel)
      Adds the menu item for showing all columns to the popup menu. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the show all columns menu item added.
      See Also:
    • withExportToImageMenuItem

      public PopupMenuBuilder withExportToImageMenuItem()
      Add the menu item for exporting to image to the popup menu. Use the default text localized in NatTable core resource bundles.

      IMPORTANT: the ImageExporter needs to be configured for the configuration attribute ExportConfigAttributes.TABLE_EXPORTER to really export to an image. Also the ExportTableCommandHandler needs to be registered on an ILayer in the layer stack, e.g. the GridLayer.

      Returns:
      The PopupMenuBuilder with the export to image menu item added.
      Since:
      1.5
      See Also:
    • withExportToImageMenuItem

      public PopupMenuBuilder withExportToImageMenuItem(String menuLabel)
      Add the menu item for exporting to image to the popup menu. Use the given String as label for the menu item.

      IMPORTANT: the ImageExporter needs to be configured for the configuration attribute ExportConfigAttributes.TABLE_EXPORTER to really export to an image. Also the ExportTableCommandHandler needs to be registered on an ILayer in the layer stack, e.g. the GridLayer.

      Parameters:
      menuLabel - The label to use for exporting to image in the popup menu.
      Returns:
      The PopupMenuBuilder with the exporting to image menu item added.
      Since:
      1.5
      See Also:
    • withHideRowMenuItem

      public PopupMenuBuilder withHideRowMenuItem()
      Adds the menu item for hiding a row to the popup menu by using the RowHideCommand. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the hide row menu item added.
      See Also:
    • withHideRowMenuItem

      public PopupMenuBuilder withHideRowMenuItem(String menuLabel)
      Adds the menu item for hiding a row to the popup menu by using the RowHideCommand. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the hide row menu item added.
      See Also:
    • withHideRowPositionMenuItem

      public PopupMenuBuilder withHideRowPositionMenuItem()
      Adds the menu item for hiding a row to the popup menu by using the RowPositionHideCommand. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the hide row menu item added.
      Since:
      1.6
      See Also:
    • withHideRowPositionMenuItem

      public PopupMenuBuilder withHideRowPositionMenuItem(String menuLabel)
      Adds the menu item for hiding a row to the popup menu by using the RowPositionHideCommand. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the hide row menu item added.
      Since:
      1.6
      See Also:
    • withShowAllRowsMenuItem

      public PopupMenuBuilder withShowAllRowsMenuItem()
      Adds the menu item for showing all rows to the popup menu. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the show all rows menu item added.
      See Also:
    • withShowAllRowsMenuItem

      public PopupMenuBuilder withShowAllRowsMenuItem(String menuLabel)
      Adds the menu item for showing all rows to the popup menu. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the show all rows menu item added.
      See Also:
    • withAutoResizeSelectedColumnsMenuItem

      public PopupMenuBuilder withAutoResizeSelectedColumnsMenuItem()
      Adds the menu item for auto resizing selected columns to the popup menu. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the resize selected columns menu item added.
      See Also:
    • withAutoResizeSelectedColumnsMenuItem

      public PopupMenuBuilder withAutoResizeSelectedColumnsMenuItem(String menuLabel)
      Adds the menu item for auto resizing selected columns to the popup menu. Uses the given String as label for the menu item.
      Returns:
      The PopupMenuBuilder with the resize selected columns menu item added.
      See Also:
    • withAutoResizeSelectedRowsMenuItem

      public PopupMenuBuilder withAutoResizeSelectedRowsMenuItem()
    • withAutoResizeSelectedRowsMenuItem

      public PopupMenuBuilder withAutoResizeSelectedRowsMenuItem(String menuLabel)
    • withColumnChooserMenuItem

      public PopupMenuBuilder withColumnChooserMenuItem()
    • withColumnChooserMenuItem

      public PopupMenuBuilder withColumnChooserMenuItem(String menuLabel)
    • withColumnStyleEditor

      public PopupMenuBuilder withColumnStyleEditor()
    • withColumnStyleEditor

      public PopupMenuBuilder withColumnStyleEditor(String menuLabel)
    • withColumnRenameDialog

      public PopupMenuBuilder withColumnRenameDialog()
    • withColumnRenameDialog

      public PopupMenuBuilder withColumnRenameDialog(String menuLabel)
    • withCreateColumnGroupsMenuItem

      public PopupMenuBuilder withCreateColumnGroupsMenuItem()
    • withCreateColumnGroupsMenuItem

      public PopupMenuBuilder withCreateColumnGroupsMenuItem(String menuLabel)
    • withCreateColumnGroupMenuItem

      public PopupMenuBuilder withCreateColumnGroupMenuItem()
      Adds the menu item for creating a column group with the new performance ColumnGroupHeaderLayer.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withCreateColumnGroupMenuItem

      public PopupMenuBuilder withCreateColumnGroupMenuItem(String menuLabel)
      Adds the menu item for creating a column group with the new performance ColumnGroupHeaderLayer.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withUngroupColumnsMenuItem

      public PopupMenuBuilder withUngroupColumnsMenuItem()
    • withUngroupColumnsMenuItem

      public PopupMenuBuilder withUngroupColumnsMenuItem(String menuLabel)
    • withRenameColumnGroupMenuItem

      public PopupMenuBuilder withRenameColumnGroupMenuItem()
    • withRenameColumnGroupMenuItem

      public PopupMenuBuilder withRenameColumnGroupMenuItem(String menuLabel)
    • withRemoveColumnGroupMenuItem

      public PopupMenuBuilder withRemoveColumnGroupMenuItem()
    • withRemoveColumnGroupMenuItem

      public PopupMenuBuilder withRemoveColumnGroupMenuItem(String menuLabel)
    • withCreateRowGroupMenuItem

      public PopupMenuBuilder withCreateRowGroupMenuItem()
      Adds the menu item for creating a row group with the new performance RowGroupHeaderLayer.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withCreateRowGroupMenuItem

      public PopupMenuBuilder withCreateRowGroupMenuItem(String menuLabel)
      Adds the menu item for creating a row group with the new performance RowGroupHeaderLayer.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withUngroupRowsMenuItem

      public PopupMenuBuilder withUngroupRowsMenuItem()
      Adds the menu item for ungrouping selected rows from an existing row group.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withUngroupRowsMenuItem

      public PopupMenuBuilder withUngroupRowsMenuItem(String menuLabel)
      Adds the menu item for ungrouping selected rows from an existing row group.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withRenameRowGroupMenuItem

      public PopupMenuBuilder withRenameRowGroupMenuItem()
      Adds the menu item for renaming a row group.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withRenameRowGroupMenuItem

      public PopupMenuBuilder withRenameRowGroupMenuItem(String menuLabel)
      Adds the menu item for renaming a row group.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withRemoveRowGroupMenuItem

      public PopupMenuBuilder withRemoveRowGroupMenuItem()
      Adds the menu item for removing a row group.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withRemoveRowGroupMenuItem

      public PopupMenuBuilder withRemoveRowGroupMenuItem(String menuLabel)
      Adds the menu item for removing a row group.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezeColumnMenuItem

      public PopupMenuBuilder withFreezeColumnMenuItem()
      Adds the menu item for for freezing a grid at a given column position.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezeColumnMenuItem

      public PopupMenuBuilder withFreezeColumnMenuItem(String menuLabel)
      Adds the menu item for for freezing a grid at a given column position.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezeRowMenuItem

      public PopupMenuBuilder withFreezeRowMenuItem()
      Adds the menu item for for freezing a grid at a given row position.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezeRowMenuItem

      public PopupMenuBuilder withFreezeRowMenuItem(String menuLabel)
      Adds the menu item for for freezing a grid at a given row position.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezePositionMenuItem

      public PopupMenuBuilder withFreezePositionMenuItem(boolean include)
      Adds the menu item for freezing a grid at a given cell position. This menu item is intended to be used in a body menu.
      Parameters:
      include - whether the selected cell should be included in the freeze region or not. Include means the freeze borders will be to the right and bottom, while exclude means the freeze borders are to the left and top.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withFreezePositionMenuItem

      public PopupMenuBuilder withFreezePositionMenuItem(String menuLabel, boolean include)
      Adds the menu item for freezing a grid at a given cell position. This menu item is intended to be used in a body menu.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      include - whether the selected cell should be included in the freeze region or not. Include means the freeze borders will be to the right and bottom, while exclude means the freeze borders are to the left and top.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withUnfreezeMenuItem

      public PopupMenuBuilder withUnfreezeMenuItem()
      Adds the menu item for removing a frozen state.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withUnfreezeMenuItem

      public PopupMenuBuilder withUnfreezeMenuItem(String menuLabel)
      Adds the menu item for removing a frozen state.
      Parameters:
      menuLabel - The label to be used for showing the menu item.
      Returns:
      This PopupMenuBuilder.
      Since:
      1.6
    • withInspectLabelsMenuItem

      public PopupMenuBuilder withInspectLabelsMenuItem()
    • withCategoriesBasedColumnChooser

      public PopupMenuBuilder withCategoriesBasedColumnChooser()
    • withCategoriesBasedColumnChooser

      public PopupMenuBuilder withCategoriesBasedColumnChooser(String menuLabel)
    • withClearAllFilters

      public PopupMenuBuilder withClearAllFilters()
    • withClearAllFilters

      public PopupMenuBuilder withClearAllFilters(String menuLabel)
    • withToggleFilterRow

      public PopupMenuBuilder withToggleFilterRow()
      Adds a menu item for toggling the visibility of the filter row. Uses the default text localized in NatTable core resource bundles.
      Returns:
      The PopupMenuBuilder with the toggle filter row menu item added.
      See Also:
    • withToggleFilterRow

      public PopupMenuBuilder withToggleFilterRow(String menuLabel)
      Adds a menu item for toggling the visibility of the filter row. Uses the given String as label for the menu item.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the toggle filter row menu item added.
      See Also:
    • withStateManagerMenuItemProvider

      public PopupMenuBuilder withStateManagerMenuItemProvider()
      Adds the menu item for opening the view management dialog to the popup menu. Uses the default text localized in NatTable core resource bundles. Uses the given String as label for the menu item.
      Returns:
      The PopupMenuBuilder with the menu item added for showing the view management dialog for managing NatTable states.
      See Also:
    • withStateManagerMenuItemProvider

      public PopupMenuBuilder withStateManagerMenuItemProvider(String menuLabel)
      Adds the menu item for opening the view management dialog to the popup menu.
      Parameters:
      menuLabel - The label to use for showing the item in the popup menu.
      Returns:
      The PopupMenuBuilder with the menu item added for showing the view management dialog for managing NatTable states.
      See Also:
    • withSeparator

      public PopupMenuBuilder withSeparator()
      Adds a separator to the popup menu.
      Returns:
      The PopupMenuBuilder with an added separator.
      See Also:
    • withSeparator

      public PopupMenuBuilder withSeparator(String id)
      Adds a separator to the popup menu with the given id.
      Parameters:
      id - The id to identify the separator. Necessary if there should be visibility constraints for specific separators.
      Returns:
      The PopupMenuBuilder with an added separator.
      See Also:
    • withSubMenu

      public PopupMenuBuilder withSubMenu(String label)
      Adds a submenu to the popup menu with the given label.
      Parameters:
      label - The label to be used for the submenu.
      Returns:
      the PopupMenuBuilder of the submenu.
      Since:
      2.3
      See Also:
    • withSubMenu

      public PopupMenuBuilder withSubMenu(String id, String label)
      Adds a submenu to the popup menu with the given id and label.
      Parameters:
      id - The id to identify the submenu. Necessary if there should be visibility constraints for specific submenus.
      label - The label to be used for the submenu.
      Returns:
      the PopupMenuBuilder of the submenu.
      Since:
      2.3
      See Also:
    • withSubMenu

      public PopupMenuBuilder withSubMenu(String id, String label, org.eclipse.jface.resource.ImageDescriptor image)
      Adds a submenu to the popup menu with the given id, label and image.
      Parameters:
      id - The id to identify the submenu. Necessary if there should be visibility constraints for specific submenus.
      label - The label to be used for the submenu.
      image - The image to be used for the submenu.
      Returns:
      the PopupMenuBuilder of the submenu.
      Since:
      2.3
      See Also:
      • MenuManager(String, ImageDescriptor, String)
    • buildSubMenu

      public PopupMenuBuilder buildSubMenu()
      Build the submenu and return the parent PopupMenuBuilder to implement the builder pattern.
      Returns:
      The parent PopupMenuBuilder.
      Since:
      2.3
    • build

      public org.eclipse.jface.action.MenuManager build(NatTable natTable)
      Sets the given NatTable to this builder and returns the MenuManager that is used to create the context menu.

      Note: Calling this method only brings the builder to a working state. The creation of the Menu needs to be done using the MenuManager. In this case the caller is also responsible for the Menu disposal.

      Parameters:
      natTable - The NatTable instance for which the Menu should be created by using the returned MenuManager. Needed to make the IMenuItemProvider work.
      Returns:
      The MenuManager that is used by this builder.
      Since:
      1.6
    • build

      public org.eclipse.swt.widgets.Menu build()
      Builds and returns the created Menu.

      Note: Calling this method will also add a DisposeListener to the NatTable instance to ensure the created Menu is disposed when the NatTable itself gets disposed.

      Returns:
      The Menu that is created by this builder.
    • build

      public org.eclipse.swt.widgets.Menu build(boolean diposeMenuManager)
      Builds and returns the created Menu.

      Note: Calling this method will also add a DisposeListener to the NatTable instance to ensure the created Menu is disposed when the NatTable itself gets disposed. Via the diposeMenuManager parameter it is possible to configure if also the internally used MenuManager should be disposed or not.

      Note: Generally it is recommended to trigger the disposal of the MenuManager. Especially if submenus are created, as otherwise the MenuItem of the submenu will not be disposed and causes resource leaks.

      Parameters:
      diposeMenuManager - true if the internally used MenuManager should be disposed, false if not. Default is false to avoid unintentionally disposing it.
      Returns:
      The Menu that is created by this builder.
      Since:
      2.3
    • withVisibleState

      public PopupMenuBuilder withVisibleState(String id, IMenuItemState state)
      Associate a visibility IMenuItemState with the menu item identified by the given id.

      The visibility state is handled by the internal MenuManager. If no MenuManager is used, this method will have not effect.

      For the item to be visible, all associated IMenuItemState must be active OR no IMenuItemState must be associated with the item.

      Parameters:
      id - the registered IMenuItemState will affect the menu item identified by the given id.
      state - the IMenuItemState to queried for the visibility state of the menu item with the given id.
      Returns:
      This PopupMenuBuilder with the visible state checker for the given id.
    • withEnabledState

      public PopupMenuBuilder withEnabledState(String id, IMenuItemState state)
      Associate a enabled IMenuItemState with the menu item identified by the given id.

      The enabled state is handled by the internal MenuManager. If no MenuManager is used, this method will have not effect.

      For the item to be enabled, all associated IMenuItemState must be active OR no IMenuItemState must be associated with the item.

      Parameters:
      id - the registered IMenuItemState will affect the menu item identified by the given id.
      state - the IMenuItemState to queried for the enabled state of the menu item with the given id.
      Returns:
      This PopupMenuBuilder with the enabled state checker for the given id.
    • isEnabled

      protected boolean isEnabled(String contributionItemId)
      Parameters:
      contributionItemId - The id of the menu item to check.
      Returns:
      true if the menu item is enabled, false if not.
      Since:
      2.3
      See Also:
    • isVisible

      protected boolean isVisible(String contributionItemId)
      Parameters:
      contributionItemId - The id of the menu item to check.
      Returns:
      true if the menu item is visible, false if not.
      Since:
      2.3
      See Also:
    • getNatEventData

      protected NatEventData getNatEventData()
      Return the NatEventData that is set to the Menu created by this PopupMenuBuilder. For a sub menu the NatEventData of the root parent menu is returned.
      Returns:
      The NatEventData set to the created Menu.
      Since:
      2.3