Accessing context information

Application Mashup (WireCloud) course @ http://edu.fiware.org

Presenter Notes

Accessing context information

Introduction

Presenter Notes

Introduction

WireCloud provides context at three levels: platform, mashup and widget/operator levels. Those context are accesible through the following objects:

MashupPlatform.widget.context   // Widget context   (Only available to widgets)
MashupPlatform.operator.context // Operator context (Only available to operators)
MashupPlatform.mashup.context   // Mashup context
MashupPlatform.context          // Platform context

Presenter Notes

Introduction

Each of these context managers supports three methods:

  • getAvailableContext: That provides information about what concepts are available for the given level
  • get: Retrieves the current value for a concept
  • registerCallback: Allows to register a callback that will be called when any of the concepts are modified

Basically you'll make use of the get method. For example:

MashupPlatform.widget.context.get('heightInPixels');
MashupPlatform.mashup.context.get('name');
MashupPlatform.context.get('username');

Presenter Notes

Accessing context information

Discovering the available context information of a WireCloud instance

Presenter Notes

Discovering the available context information of a WireCloud instance

The available context information depends on the version and the list of addons installed in the concrete instance of WireCloud. Here you have to options:

  • Discovering available context information using the getAvailableContext method
  • Or discovering it using the Context Inspector widget

Presenter Notes

Accessing context information

Using widget context for resizing widget's content

Presenter Notes

Using widget context for resizing widget's content

One of the main uses that developers can give to the context support is using it for receiving notification about changes in the size of a widget. This is due to the fact that CSS is better prepared for managing horizontal dimensions than vertical ones. In addition to this, the resize event is not fired inside widgets as they are wrapped in iframe elements, so if the developer need to resize the content programmatically, this becomes the best choice. This code snippet shows how to use the context support for resizing the widget's content:

MashupPlatform.widget.context.registerCallback(function (new_values) {
    ...

    if ('heightInPixels' in new_values) {
        repaint();
    }

    ...
});

Presenter Notes

Thanks!

Presenter Notes