close

Filter

loading table of contents...

Site Manager Developer Manual / Version 2204

Table Of Contents

4.8.5 Add Command to Context Menu

You can find context menus in each view of the Site Manager. In this chapter, you will learn how to add a command to a context menu which belongs to a property editor. The steps shown in the next table will add the command to a menu belonging to a link list editor. The name of the menu is "linklist-menu" and your command will be added at the end of the menu.

Step Description
1 Extend the property editor for which you want to add your command
 public class MyLinkListEditor extends GenericLinkListEditor {
2 Overwrite the getComponent method
 public JComponent getComponent() {
3 Call the getComponent method of the parent class to create the default behavior
 super.getComponent();
4 Get the references to the manager components and register your command as described in Section 4.8.1, “Register Commands”.
 

CommandManager commandMgr = Services.getCommandManager(context);

PopupMenuManager popupMenuMgr = Services.getPopupMenuManager(context);

ListenerManager listenerMgr = Services.getListenerManager(context);

commandMgr.registerCommand("My-Command", new MyCommand());

5 Add a separator and your command to the end of the pop-up menu
 

popupMenuMgr.addItemAfter("linklist-menu", moveBottomCommand, listenerMgr.createMenuSeparator("Custom"));

popupMenuMgr.addItemAfter("linklist-menu", "Custom", listenerMgr.createPopupMenuItem("My-Command"));

6 Return the JComponent to the Site Manager
 

return this;

}

Table 4.10. Add command to context menu


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.