java.lang.Object | |
↳ | com.microstrategy.web.app.gui.ContextMenuManager |
The ContextMenuManager
represents a collection of ContextMenu
objects.
A ContextMenu
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
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 the contextMenus
formal parameter.
To programatically create and manipulate context-menus, the following steps are required:
ContextMenuManager
instance that will be used as factory of
all ContextMenu
.
ContextMenuManager
create the ContextMenu
objects. Typically
there will be one ContextMenu
for each different element, even if the options
are the same. For example, in the folder page there is one ContextMenu
for
each object in the folder.
ContextMenu
with its corresponding ContextMenuItem
objects. Each ContextMenuItem
represents a single option.
ContextMenu
has been populated it needs to be associated
with the corresponding HTML Tag (typically a <div>
). For this purpose
you can call the attachTo(Tag)
or getTriggerString()
.
getScriptOutput()
generates
the JavaScript necessary to display the context-menus with-in MicroStrategy Web.
Classes extending AbstractAppTransform
need not to worry about creating the
ContextMenuManager
instance or invoking the getScriptOutput
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."; } }
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ContextMenuManager(String name, AppContext appContext)
Class constructor.
| |||||||||||
ContextMenuManager(String name, ShortcutListSet definition, TransformContext context)
Class constructor.
| |||||||||||
ContextMenuManager(String name)
Class constructor.
| |||||||||||
ContextMenuManager(AppContext appContext)
This constructor is deprecated.
This constructor is not supported anymore. The proper usage requires to assign
a unique name to every
ContextMenuManager .
| |||||||||||
ContextMenuManager()
This constructor is deprecated.
This constructor is not supported anymore. The proper usage requires to assign
a unique name to every
ContextMenuManager .
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BlockList |
getDrillDynamicMenus()
On Demand Drill menus at top-level
| ||||||||||
BlockList |
getDrillMenuItems()
On Demand Drill menus
| ||||||||||
ContextMenu |
getDynamicMenu(String name)
Returns a dynamic | ||||||||||
void |
getDynamicMenus(StringBuilder builder)
Puts the dynamic menus stored in this ContextMenuManager in JSON format.
| ||||||||||
ContextMenu |
getMenu(ShortcutList shortcuts, WebComponent targetBean)
This method is deprecated.
Instead of passing the
ShortcutList as parameter, create a new
ContextMenuManager with a ShortcutListSet definition and call
getMenu(String, TransformContext) . | ||||||||||
ContextMenu |
getMenu(String name, TransformContext context)
Creates a new | ||||||||||
ContextMenu |
getMenu(String name)
This method is deprecated.
use
getDynamicMenu(String) instead. | ||||||||||
ContextMenu |
getMenu()
Returns a new (empty)
ContextMenu instance. | ||||||||||
HashList<String, ContextMenuItem> |
getMenuElements()
This method is deprecated.
This method should only be accessed internally and will be marked as
private in future releases.
| ||||||||||
void |
getMenuItems(StringBuilder builder)
Fills a StringBuilder with all the menu items of this ContextMenuManager represented by ContextMenuItems stored in the
getMenuElements() in the
JSON format. | ||||||||||
MarkupOutput |
getScriptOutput()
Returns a new
MarkupOutput object populated with the JavaScript code
required to display the ContextMenu objects associated with
this ContextMenuManager . | ||||||||||
Map<String, String> |
getTriggerAttributes()
Returns a
Map (name/value pairs) with the attributes necessary to link an HTML tag
with the context-menus associated with this ContextMenuManager . | ||||||||||
String |
getTriggerString()
Returns a
String with the attributes necessary to link an HTML tag
with the context-menus associated with this ContextMenuManager . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Class constructor. Initializes a new instance of a ContextMenuManager
class.
Class constructor. Initializes a new instance of the ContextMenuManager
class. This constructor receives the ShortcutListSet
structure (typically initiated from an XML-definition) with the information that will
be used to populate the ContextMenu
instances.
name | A unique identifier for this ContextMenuManager . |
---|---|
definition | This is a non-null ShortcutListSet instance to be used
as the menu definition for the context-menus provided by this manager. |
context | A non-null TransformContext instance for this request. It provides information about
where the context-menus will be used. |
Class constructor. Creates a new instance of the ContextMenuManager with the given name.
name | A unique identifier for this ContextMenuManager .
|
---|
This constructor is deprecated.
This constructor is not supported anymore. The proper usage requires to assign
a unique name to every ContextMenuManager
.
Class constructor. Creates a new empty instance of a ContextMenuManager
.
This constructor is deprecated.
This constructor is not supported anymore. The proper usage requires to assign
a unique name to every ContextMenuManager
.
Class constructor. Creates an empty new instance of a ContextMenuManager
.
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 same ContextMenu
instance (as opposed to the
other getMenu()
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 the TransformContext
. Still, they are created on the server
so the user can modify the context-menu definition using a configuration file.
ContextMenu
.Puts the dynamic menus stored in this ContextMenuManager in JSON format. on a StringBuilder representing the dynamic menus in JSON format
This method is deprecated.
Instead of passing the ShortcutList
as parameter, create a new
ContextMenuManager
with a ShortcutListSet
definition and call
getMenu(String, TransformContext)
.
Creates a new ContextMenu
instance populated with the given shortcuts.
shortcuts | A ShortcutList , the ContextMenu will have a ContextMenuItem
for each element in the ShortcutList. |
---|---|
targetBean | a WebComponent , used to retrieve context information, for example
to validate features or create WebEvents. |
ContextMenu
instance.Creates a new ContextMenu
instance, populated with the items as specified
in the ShortcutListSet
definition.
When this ContextMenuManager
is created, the user may specify a
ShortcutListSet
to be used as the menus definition, when this is the case,
this method will search
for a ShortcutList
within the ShortcutListSet
with
the corresponding name,
if found it will use it to populate the new ContextMenu
instance.
name | The name of a ShortcutList to use to populate the ContextMenu |
---|---|
context | A TransformContext instance, used to retrieve information about
the context. |
ContextMenu
instance
This method is deprecated.
use getDynamicMenu(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 same ContextMenu
instance (as opposed to the
other getMenu()
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 the TransformContext
. Still, they are created on the server
so the user can modify the context-menu definition using a configuration file.
ContextMenu
.
This method is deprecated.
This method should only be accessed internally and will be marked as
private in future releases.
Returns the collection of all the ContextMenuItems
defined within
any ContextMenu
of this ContextMenuManager
.
Fills a StringBuilder with all the menu items of this ContextMenuManager represented by ContextMenuItems stored in the getMenuElements()
in the
JSON format.
Returns a new MarkupOutput
object populated with the JavaScript code
required to display the ContextMenu
objects associated with
this ContextMenuManager
. This MarkupOutput
needs
to be included as part of the HTML output sent to the web-browser.
Returns a Map
(name/value pairs) with the attributes necessary to link an HTML tag
with the context-menus associated with this ContextMenuManager
.
Typically is not necessary to call this method as the getTagAttributes()
or
attachTo(Tag)
methods
already includes the necessary information.
Returns a String
with the attributes necessary to link an HTML tag
with the context-menus associated with this ContextMenuManager
.
Typically is not necessary to call this method as the getTriggerString()
already includes the necessary information.