Posts tagged "subscribing to display events"

Displaying Mosaic nodes and subscribing to display events

Adobe LiveCycle Mosaic ES2 9.5 introduces a new way of managing the visibility of nodes (views, panels, and tiles) in your application.  This is very useful when your application has multiple views.  The get/set activePanel()/activeView() APIs from Mosaic 9.0 have been removed because they no longer apply now that Mosaic supports nested panels and more than one panel or tile could be visible at the same time.  Replacing them are the “display” APIs.

The ActionScript IDisplayable class is a superclass for IView, IPanel, and ITile:

  • IDisplayable.display() [Sets a node to be visible]
  • IDisplayable.displayed [Gets the visibility of a node]

For JavaScript the display APIs are only available on nodes that are of types “view”, “panel”, or “tile”:

  • Node.display()         [Sets a node to be visible]
  • Node.getDisplayed()    [Gets the visibility of a node]

To display a node with ActionScript:

// nodeToDisplay is of type IMosaicNode
if (nodeToDisplay is IDisplayable)
{
    var nodeDisplayable:IDisplayable = nodeToDisplay as IDisplayable;
    nodeDisplayable.display(); // Display the node
}

To display a node with JavaScript:

// nodeToDisplay is of type Node
var strNodeType = nodeToDisplay.getNodeType();

if ((strNodeType == "view") ||
    (strNodeType == "panel")||
    (strNodeType == "tile"))
{
    nodeToDisplay.display(); // Display the node
}


To get the display state of a node with ActionScript:


var strNodeDisplayStatus:String = "hidden";

// nodeToTestForDisplay is of type IMosaicNode
if (nodeToTestForDisplay is IDisplayable)
{
    var nodeDisplayable:IDisplayable = nodeToTestForDisplay as IDisplayable;

    if (nodeDisplayable != null)
    {
        if (nodeDisplayable.displayed)
        {
            strNodeDisplayStatus = "displayed";
        }
    }
}

To get the display state of a node with JavaScript:


// nodeToTestForDisplay is of type Node
var strNodeType = nodeToTestForDisplay.getNodeType();

var strNodeDisplayStatus = "hidden";

if ((strNodeType == "view") ||
    (strNodeType == "panel")||
    (strNodeType == "tile"))
{
    if (nodeToTestForDisplay.getDisplayed())
    {
        strNodeDisplayStatus = "displayed";
    }
}


You can also subscribe to a new event that is dispatched whenever a Mosaic node becomes displayed.

The subscribe and respond to the “DisplayMessage” event with ActionScript:
 

// Add a message listener for the node-display event
mosaicApp.addMessageListener(DisplayMessage.NAMESPACE, DisplayMessage.DISPLAY_EVENT_CHANGE, onDisplayMessage);

// Handle the node-display event
private function onDisplayMessage(message:Message):void
{
    for each (var node:IMosaicNode in message.payload.revealedNodes)
    {
        Alert.show("Displayed node " + node.nodeLabel, "Display event", mx.controls.Alert.OK, this);
    }
}


The subscribe and respond to the “DisplayEvent” event with JavaScript:

 

mosaicApp.addMessageListener("com.adobe.mosaic.core", "DisplayEvent.CHANGE", onDisplayMessage);

function onDisplayMessage(message)
{
    for (var nNodeCounter = 0; nNodeCounter < message.payload.revealedNodes.length; nNodeCounter++)
    {
        var strNodeLabel = message.payload.revealedNodes[nNodeCounter].getNodeLabel();
        alert("Displayed node " + strNodeLabel);
    }
}


Sample Flex (DisplayReceiver.mxml) and HTML (DisplayHtmlReceiver.html) tiles are attached.