Class ContextMenuManager
- java.lang.Object
 - 
- com.microstrategy.web.app.gui.ContextMenuManager
 
 
- 
public class ContextMenuManager extends java.lang.ObjectThe
ContextMenuManagerrepresents a collection ofContextMenuobjects. AContextMenuis displayed when the end user makes click using the right mouse button on an element in the interface; the menu displays a list with different actions associated with that element.Context menus can and should be configured using external XML files. All MicroStrategy Web transforms that display context-menus have their
AbstractAppTransform.contextMenusformal parameter assigned in the style catalog. Even those transforms that display no context menus out of the box can be configured to display them simply by creating a new XML definition file and setting thecontextMenusformal parameter.To programatically create and manipulate context-menus, the following steps are required:
- Create a new 
ContextMenuManagerinstance that will be used as factory of allContextMenu. - From the 
ContextMenuManagercreate theContextMenuobjects. Typically there will be oneContextMenufor each different element, even if the options are the same. For example, in the folder page there is oneContextMenufor each object in the folder. - Next, populate the 
ContextMenuwith its correspondingContextMenuItemobjects. EachContextMenuItemrepresents a single option. - Once the 
ContextMenuhas been populated it needs to be associated with the corresponding HTML Tag (typically a<div>). For this purpose you can call theContextMenu.attachTo(com.microstrategy.web.tags.Tag)orContextMenu.getTriggerString(). - When all the ContextMenus have been created, the 
getScriptOutput()generates the JavaScript necessary to display the context-menus with-in MicroStrategy Web. 
Classes extending
The following sample illustrates these concepts. This transform creates three text elements, and associates to each aAbstractAppTransformneed not to worry about creating theContextMenuManagerinstance or invoking thegetScriptOutputmethod. These tasks are automatically taken care of by the abstract class.ContextMenuwith two items and a separator between them: the first one generates a JavaScript alert message in the browser, the second one redirects the user to www.microstrategy.com.import com.microstrategy.web.app.transforms.AbstractAppTransform; import com.microstrategy.web.beans.MarkupOutput; import com.microstrategy.web.tags.Tag; import com.microstrategy.web.app.gui.ContextMenu; public class ContextMenuSample extends AbstractAppTransform { public ContextMenuSample() { super(); } public void transformForRequestSuccessful(MarkupOutput out) { renderSample(out, "text A"); renderSample(out, "text B"); renderSample(out, "text C"); out.append(getContextMenuManager().getScriptOutput()); } public void renderSample(MarkupOutput out, String text) { //Create a div tag enclosing the given text: Tag div = getTagsFactory().newDivTag(); div.getContent().append(text); //Create and populate the corresponding context-menu: ContextMenu menu = getContextMenuManager().getMenu(); menu.addItem("Alert", "alert", "'" + text + "'"); menu.addSeparator(); menu.addItem("MicroStrategy web site", "http://www.microstrategy.com"); //Once populated, attach the context-menu to the div: menu.attachTo(div); //Generate the div's HTML: div.render(out); } public String getDescription() { return "Shows the programmatic usage of context-menus."; } }- Since:
 - MicroStrategy Web 7.3.1 or earlier
 
 - Create a new 
 
- 
- 
Constructor Summary
Constructors Constructor Description ContextMenuManager()Deprecated.This constructor is not supported anymore.ContextMenuManager(AppContext appContext)Deprecated.This constructor is not supported anymore.ContextMenuManager(java.lang.String name)Class constructor.ContextMenuManager(java.lang.String name, AppContext appContext)Class constructor.ContextMenuManager(java.lang.String name, ShortcutListSet definition, TransformContext context)Class constructor. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BlockListgetDrillDynamicMenus()On Demand Drill menus at top-levelBlockListgetDrillMenuItems()On Demand Drill menusContextMenugetDynamicMenu(java.lang.String name)Returns a dynamicContextMenuinstance identified by the given name.voidgetDynamicMenus(java.lang.StringBuilder builder)Puts the dynamic menus stored in this ContextMenuManager in JSON format.ContextMenugetMenu()Returns a new (empty)ContextMenuinstance.ContextMenugetMenu(ShortcutList shortcuts, WebComponent targetBean)Deprecated.Instead of passing theShortcutListas parameter, create a newContextMenuManagerwith aShortcutListSetdefinition and callgetMenu(String name, TransformContext context).ContextMenugetMenu(java.lang.String name)Deprecated.usegetDynamicMenu(String)instead.ContextMenugetMenu(java.lang.String name, TransformContext context)Creates a newContextMenuinstance, populated with the items as specified in theShortcutListSetdefinition.HashList<java.lang.String,ContextMenuItem>getMenuElements()Deprecated.This method should only be accessed internally and will be marked as private in future releases.voidgetMenuItems(java.lang.StringBuilder builder)Fills a StringBuilder with all the menu items of this ContextMenuManager represented by ContextMenuItems stored in thegetMenuElements()in the JSON format.MarkupOutputgetScriptOutput()Returns a newMarkupOutputobject populated with the JavaScript code required to display theContextMenuobjects associated with thisContextMenuManager.java.util.Map<java.lang.String,java.lang.String>getTriggerAttributes()Returns aMap(name/value pairs) with the attributes necessary to link an HTML tag with the context-menus associated with thisContextMenuManager.java.lang.StringgetTriggerString()Returns aStringwith the attributes necessary to link an HTML tag with the context-menus associated with thisContextMenuManager. 
 - 
 
- 
- 
Constructor Detail
- 
ContextMenuManager
public ContextMenuManager(java.lang.String name, AppContext appContext)Class constructor. Initializes a new instance of aContextMenuManagerclass. 
- 
ContextMenuManager
public ContextMenuManager(java.lang.String name, ShortcutListSet definition, TransformContext context)Class constructor. Initializes a new instance of theContextMenuManagerclass. This constructor receives theShortcutListSetstructure (typically initiated from an XML-definition) with the information that will be used to populate theContextMenuinstances.- Parameters:
 name- A unique identifier for thisContextMenuManager.definition- This is a non-nullShortcutListSetinstance to be used as the menu definition for the context-menus provided by this manager.context- A non-nullTransformContextinstance for this request. It provides information about where the context-menus will be used.- Since:
 - MicroStrategy Web 8.0.1
 
 
- 
ContextMenuManager
public ContextMenuManager(java.lang.String name)
Class constructor. Creates a new instance of the ContextMenuManager with the given name.- Parameters:
 name- A unique identifier for thisContextMenuManager.
 
- 
ContextMenuManager
public ContextMenuManager(AppContext appContext)
Deprecated.This constructor is not supported anymore. The proper usage requires to assign a unique name to everyContextMenuManager.Class constructor. Creates a new empty instance of aContextMenuManager. 
- 
ContextMenuManager
public ContextMenuManager()
Deprecated.This constructor is not supported anymore. The proper usage requires to assign a unique name to everyContextMenuManager.Class constructor. Creates an empty new instance of aContextMenuManager. 
 - 
 
- 
Method Detail
- 
getDynamicMenu
public ContextMenu getDynamicMenu(java.lang.String name)
Returns a dynamic
ContextMenuinstance identified by the given name.Dynamic ContextMenus are different from normal context-menus in a subtle way: there exists only one instance per
ContextMenuManager, therefore if you pass the same name you will receive the sameContextMenuinstance (as opposed to the othergetMenu()methods which always return a new instance). The reason is that these context-menus will be updated in the client using JavaScript so they really not depend on theTransformContext. Still, they are created on the server so the user can modify the context-menu definition using a configuration file.- Returns:
 - a dynamic 
ContextMenu. - Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getMenu
public ContextMenu getMenu(java.lang.String name)
Deprecated.usegetDynamicMenu(String)instead.Returns a dynamic
ContextMenuinstance identified by the given name.Dynamic ContextMenus are different from normal context-menus in a subtle way: there exists only one instance per
ContextMenuManager, therefore if you pass the same name you will receive the sameContextMenuinstance (as opposed to the othergetMenu()methods which always return a new instance). The reason is that these context-menus will be updated in the client using JavaScript so they really not depend on theTransformContext. Still, they are created on the server so the user can modify the context-menu definition using a configuration file.- Returns:
 - a dynamic 
ContextMenu. - Since:
 - MicroStrategy Web 8.0.1
 
 
- 
getMenu
public ContextMenu getMenu()
Returns a new (empty)ContextMenuinstance. 
- 
getMenu
public ContextMenu getMenu(java.lang.String name, TransformContext context)
Creates a new
ContextMenuinstance, populated with the items as specified in theShortcutListSetdefinition.When this
ContextMenuManageris created, the user may specify aShortcutListSetto be used as the menus definition, when this is the case, this method will search for aShortcutListwithin theShortcutListSetwith the corresponding name, if found it will use it to populate the newContextMenuinstance.- Parameters:
 name- The name of aShortcutListto use to populate theContextMenucontext- ATransformContextinstance, used to retrieve information about the context.- Returns:
 - a new (populated) 
ContextMenuinstance - Since:
 - MicroStrategy Web 8.0.1
 
 
- 
getMenu
public ContextMenu getMenu(ShortcutList shortcuts, WebComponent targetBean)
Deprecated.Instead of passing theShortcutListas parameter, create a newContextMenuManagerwith aShortcutListSetdefinition and callgetMenu(String name, TransformContext context).Creates a newContextMenuinstance populated with the given shortcuts.- Parameters:
 shortcuts- AShortcutList, the ContextMenu will have a ContextMenuItem for each element in the ShortcutList.targetBean- aWebComponent, used to retrieve context information, for example to validate features or create WebEvents.- Returns:
 - a new 
ContextMenuinstance. - Since:
 - MicroStrategy Web 8.0.0
 
 
- 
getMenuItems
public void getMenuItems(java.lang.StringBuilder builder)
Fills a StringBuilder with all the menu items of this ContextMenuManager represented by ContextMenuItems stored in thegetMenuElements()in the JSON format.- Parameters:
 builder-- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getDrillMenuItems
public BlockList getDrillMenuItems()
On Demand Drill menus 
- 
getDrillDynamicMenus
public BlockList getDrillDynamicMenus()
On Demand Drill menus at top-level 
- 
getDynamicMenus
public void getDynamicMenus(java.lang.StringBuilder builder)
Puts the dynamic menus stored in this ContextMenuManager in JSON format. on a StringBuilder representing the dynamic menus in JSON format- Parameters:
 builder-- Since:
 - MicroStrategy Web 9.0.0
 
 
- 
getTriggerString
public java.lang.String getTriggerString()
Returns aStringwith the attributes necessary to link an HTML tag with the context-menus associated with thisContextMenuManager. Typically is not necessary to call this method as theContextMenu.getTriggerString()already includes the necessary information.- Since:
 - MicroStrategy Web 8.0.0
 - See Also:
 ContextMenuManager
 
- 
getTriggerAttributes
public java.util.Map<java.lang.String,java.lang.String> getTriggerAttributes()
Returns aMap(name/value pairs) with the attributes necessary to link an HTML tag with the context-menus associated with thisContextMenuManager. Typically is not necessary to call this method as theContextMenu.getTagAttributes()orContextMenu.attachTo(com.microstrategy.web.tags.Tag)methods already includes the necessary information.- Since:
 - MicroStrategy Web 8.0.0
 - See Also:
 ContextMenuManager
 
- 
getScriptOutput
public MarkupOutput getScriptOutput()
Returns a newMarkupOutputobject populated with the JavaScript code required to display theContextMenuobjects associated with thisContextMenuManager. ThisMarkupOutputneeds to be included as part of the HTML output sent to the web-browser.- See Also:
 ContextMenuManager
 
- 
getMenuElements
public HashList<java.lang.String,ContextMenuItem> getMenuElements()
Deprecated.This method should only be accessed internally and will be marked as private in future releases.Returns the collection of all theContextMenuItemsdefined within anyContextMenuof thisContextMenuManager. 
 - 
 
 -