Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Scout/HowTo/4.0/Hide or disable menu items dynamically"

< Scout‎ | HowTo‎ | 4.0
m (Hiding and disabling menu items)
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
Line 1: Line 1:
{{ScoutPage|cat=HowTo 4.0}}
+
The Scout documentation has been moved to https://eclipsescout.github.io/.
 
+
This how-to describes how to dynamically hide or disable menu entries.
+
 
+
= Hiding and disabling menu 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:  
+
 
+
[[Image: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:
+
 
+
[[Image:MenuPrepareAction.png]]<br>
+
 
+
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 execOwnerValueChanged(Object newValue) throws ProcessingException {
+
        super.execOwnerValueChanged(newValue);
+
        boolean visible = complexCalculation();
+
        boolean enabled = anotherComplexCalculation();
+
       
+
        setVisible(visible);
+
        setEnabled(visible && enabled);
+
      }
+
 
+
<br> The following screenshot illustrates the effects of the various combinations on AnotherMenuItem:
+
 
+
[[Image:MenuResults.png]]<br>
+
 
+
<br>
+
 
+
= 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:
+
 
+
[[Image:MenuSeparator.png]]<br>
+
 
+
    @Order(30.0)
+
public class SeparatorMenu extends AbstractMenu {
+
 
+
  @Override
+
  protected boolean getConfiguredSeparator() {
+
    return true;
+
  }
+
}
+
 
+
<br>
+

Latest revision as of 07:35, 18 March 2024

The Scout documentation has been moved to https://eclipsescout.github.io/.

Back to the top