Jump to: navigation, search

Scout/HowTo/3.8/Hide or disable menu items dynamically

< Scout‎ | HowTo‎ | 3.8
Revision as of 10:53, 5 March 2013 by Urs.beeli.sbb.ch (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Scout
Wiki Home
Website
DownloadGit
Community
ForumsBlogTwitter
Bugzilla
Bugzilla


This how-to describes how to dynamically hide or disable menu entries.

Hiding and disabling menut items

Context menus added to tables or form fields already support showing and hiding of menu entries depending on the number of selected elements (mostly relevant for tables) using the "Single Selection", "Multi Selection" and "Empty Space" actions:

MenuSelection.png

In addition, it is also possible to use additional criteria to either show/hide or enable/disable (shown but greyed out) a menu item by overwriting its exePrepareAction() method:

MenuPrepareAction.png

In this method, any criteria can be evaluated and depending on the result of the evaluation the user can then decide to hide/show/disable/enable the menu item:

     @Override
  protected void execPrepareAction() throws ProcessingException {
    boolean visible = complexCalculation();
    boolean enabled = anotherComplexCalculation();
    
    setVisible(visible);
    setEnabled(visible && enabled);
  }


The following screenshot illustrates the effects of the various combinations on AnotherMenuItem:

MenuResults.png


Adding separators to menus

In order to add a separator to a menu, a new menu item with its Separator property set to true must be added to a menu:

MenuSeparator.png

   @Order(30.0)
public class SeparatorMenu extends AbstractMenu {
  
  @Override
  protected boolean getConfiguredSeparator() {
    return true;
  }
}