Class ContextMenuManager
- java.lang.Object
-
- com.microstrategy.web.app.gui.ContextMenuManager
-
public class ContextMenuManager extends java.lang.Object
The
ContextMenuManager
represents a collection ofContextMenu
objects. AContextMenu
is 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.contextMenus
formal 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 thecontextMenus
formal parameter.To programatically create and manipulate context-menus, the following steps are required:
- Create a new
ContextMenuManager
instance that will be used as factory of allContextMenu
. - From the
ContextMenuManager
create theContextMenu
objects. Typically there will be oneContextMenu
for each different element, even if the options are the same. For example, in the folder page there is oneContextMenu
for each object in the folder. - Next, populate the
ContextMenu
with its correspondingContextMenuItem
objects. EachContextMenuItem
represents a single option. - Once the
ContextMenu
has 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 aAbstractAppTransform
need not to worry about creating theContextMenuManager
instance or invoking thegetScriptOutput
method. These tasks are automatically taken care of by the abstract class.ContextMenu
with 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 BlockList
getDrillDynamicMenus()
On Demand Drill menus at top-levelBlockList
getDrillMenuItems()
On Demand Drill menusContextMenu
getDynamicMenu(java.lang.String name)
Returns a dynamicContextMenu
instance identified by the given name.void
getDynamicMenus(java.lang.StringBuilder builder)
Puts the dynamic menus stored in this ContextMenuManager in JSON format.ContextMenu
getMenu()
Returns a new (empty)ContextMenu
instance.ContextMenu
getMenu(ShortcutList shortcuts, WebComponent targetBean)
Deprecated.Instead of passing theShortcutList
as parameter, create a newContextMenuManager
with aShortcutListSet
definition and callgetMenu(String name, TransformContext context)
.ContextMenu
getMenu(java.lang.String name)
Deprecated.usegetDynamicMenu(String)
instead.ContextMenu
getMenu(java.lang.String name, TransformContext context)
Creates a newContextMenu
instance, populated with the items as specified in theShortcutListSet
definition.HashList<java.lang.String,ContextMenuItem>
getMenuElements()
Deprecated.This method should only be accessed internally and will be marked as private in future releases.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.MarkupOutput
getScriptOutput()
Returns a newMarkupOutput
object populated with the JavaScript code required to display theContextMenu
objects 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.String
getTriggerString()
Returns aString
with 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 aContextMenuManager
class.
-
ContextMenuManager
public ContextMenuManager(java.lang.String name, ShortcutListSet definition, TransformContext context)
Class constructor. Initializes a new instance of theContextMenuManager
class. This constructor receives theShortcutListSet
structure (typically initiated from an XML-definition) with the information that will be used to populate theContextMenu
instances.- Parameters:
name
- A unique identifier for thisContextMenuManager
.definition
- This is a non-nullShortcutListSet
instance to be used as the menu definition for the context-menus provided by this manager.context
- A non-nullTransformContext
instance 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
@Deprecated 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
@Deprecated 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
ContextMenu
instance 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 sameContextMenu
instance (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
@Deprecated public ContextMenu getMenu(java.lang.String name)
Deprecated.usegetDynamicMenu(String)
instead.Returns a dynamic
ContextMenu
instance 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 sameContextMenu
instance (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)ContextMenu
instance.
-
getMenu
public ContextMenu getMenu(java.lang.String name, TransformContext context)
Creates a new
ContextMenu
instance, populated with the items as specified in theShortcutListSet
definition.When this
ContextMenuManager
is created, the user may specify aShortcutListSet
to be used as the menus definition, when this is the case, this method will search for aShortcutList
within theShortcutListSet
with the corresponding name, if found it will use it to populate the newContextMenu
instance.- Parameters:
name
- The name of aShortcutList
to use to populate theContextMenu
context
- ATransformContext
instance, used to retrieve information about the context.- Returns:
- a new (populated)
ContextMenu
instance - Since:
- MicroStrategy Web 8.0.1
-
getMenu
@Deprecated public ContextMenu getMenu(ShortcutList shortcuts, WebComponent targetBean)
Deprecated.Instead of passing theShortcutList
as parameter, create a newContextMenuManager
with aShortcutListSet
definition and callgetMenu(String name, TransformContext context)
.Creates a newContextMenu
instance 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
ContextMenu
instance. - 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 aString
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.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 newMarkupOutput
object populated with the JavaScript code required to display theContextMenu
objects associated with thisContextMenuManager
. ThisMarkupOutput
needs to be included as part of the HTML output sent to the web-browser.- See Also:
ContextMenuManager
-
getMenuElements
@Deprecated 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 theContextMenuItems
defined within anyContextMenu
of thisContextMenuManager
.
-
-