All the menu bars, tool bars, pop-up menus in Lucy are populated thanks to the concept of a configured or configurable action bar.

  • The term action bars refers to the collection of menu bars, tool bars and pop-up menus.

  • The term configurable indicates that you can customize the contents of those action bars through configuration files, without writing extra code.

Configured action bars allow:

  • Add-ons to populate an action bar, without knowing where it is displayed in the UI

  • You to add an action bar to the UI without knowing which add-ons add content to it

  • You to customize the availability and location of the default Lucy actions by adjusting configuration files

  • You to insert actions in multiple locations in the UI.

To illustrate how Lucy action bar configuration works, this article shows you how to insert a new action in an existing action bar.

An in-depth explanation of the concept of configured action bars and their possibilities is available in the reference guides. The aim of this introduction is to give a high-level overview of how this works, and provide some code pointers to the most relevant classes.

High-level overview of inserting an action

TLcyActionBarManager

To insert an action in a configured action bar:

  1. Create the action and assign a unique identifier to it.

    ILcdAction openAction = ...; //create the action
    openAction.putValue( TLcyActionBarUtil.ID_KEY, "OpenAction");//specify the ID of the action
  2. Configure the action in your configuration file using the ID you just assigned.

    # The keys start with the ID of the action, followed by the name of the action bar in which to insert the action
    OpenAction.menuBar.item = File, Open
    OpenAction.menuBar.groups = FileGroup, OpenSaveGroup

    See How to find the IDs of the available actions, tool bars, menu bars and pop-up menus for more information about retrieving IDs in Lucy. You can also create your own configured action bar in the UI (see step 4) and use the name of your own action bar.

  3. Register the action with the TLcyActionBarManager. You use the TLcyActionBarManager as a central repository of actions. The manager keeps track of which actions are registered for which action bars.

    //The parsed version of the configuration file
    //When working with an ALcyPreferencesAddOn, you can use ALcyPreferencesAddOn#getPreferences
    //Otherwise, you can use:
    // new TLcyStringPropertiesCodec().decode(pathToFile);
    ALcyProperties config = ...;
    
    ILcyLucyEnv lucy = ...;
    TLcyActionBarManager actionBarManager = lucy.getUserInterfaceManager().getActionBarManager();
    
    //Register the openAction with the action bar manager
    TLcyActionBarUtil.insertInConfiguredActionBars(openAction, mapComponent, config, actionBarManager);
  4. The action gets inserted into the UI automatically. The TLcyActionBarManager automatically inserts the action into the menu bar on the UI, as it does for all the standard Lucy action bars. If you want this to work for your own action bars, the action bar in the UI must indicate to the TLcyActionBarManager that it wants to be kept in-sync. You set this up with the TLcyActionBarUtil.setupAsConfiguredActionBar method. Consult the API reference documentation for all parameter details.

    TLcyMenuBar myBar = ...; // the bar that is inserted to the UI
    //Ask the TLcyActionBarManager to keep the UI bar in sync with the TLcyActionBarManager
    String menuBarID = "myBar";
    TLcyActionBarUtil.setupAsConfiguredBar(myBar, myBarID, mapComponent, properties, prefix, mapComponent.getComponent(), actionBarManager)