Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Overview of function to implement

The IWidget interface requires you to implement a number methods, which will be called from the framework.  We will go over each method in detail below.

...

Next we will loop through the result set we get from the IWidgetContext object we saved in the onInit function and add the documents titles to our ArrayCollection.  At the same time we will loop through the document entities adding them to our entity ArrayCollection so we can show their names also:  Add this code below the code we just added in the previous step:

...

An alternative that just showed the aggregated entity information might look like:

Code Block
langjavascript
var queryResults:ArrayCollection =  _context.getQuery_AllResults().getEntities();
for each (var ent:Object in queryResults )
{
     entityArrayList.addItem(entity.disambiguous_name);
}

And so on.

TODO See here for more details about the different views of the data provided by the WidgetContext IWidgetContext class.

You can download the full code example here or see the widget code below.

...

Filtering the data visible by widgets

TODO

Saving the widget state across sessions

TODO

Adding a query term to the builder

TODO

...

Suppose you want to see quickly only those documents containing a specific set of entities, but don't want to make a whole new query. For example, you have a "Document Browser" widget open (like the first example above), and also an "aggregated event" widget (like the second example above) eg a "Significance" widget, and you want to see all documents in the "document browser" containing the first entity listed.

In the "aggregated event" widget in some callback (eg click on canvas), you would simply write some code like this:

Code Block
languagejavascript
var entitiesToFilter:Set = new HashSet();
entitiesToFilter.add(_context.getQuery_AllResults().getEntities().getItemAt(0));
_context.filterByEntities(FilterDataSetEnum.FILTER_GLOBAL_DATA, entitiesToFilter, EntityMatchTypeEnum.ANY, IncludeEntitiesEnum.INCLUDE_ALL_ENTITIES);
// (Enums mean: (1) filter starting with all data, (2) apply OR to multiple entities in set, and (3) leave all entities in the resulting document set, not just those in the filter set)

After the final "filterByEntities" call, all active widgets have their "onReceiveNewFilter" callback invoked. This can be used analogously to the "onReceiveNewQuery" example shown above:

Code Block
langjavascript
public function onReceiveNewFilter():void {
   var queryResults:ArrayCollection =  _context.getQuery_FilteredResults().getTopDocuments();
   for each (var doc:Object in queryResults)
   {
        titleArrayList.addItem(doc.title);
        for each ( var entity:Object in doc.entities )
        {
             entityArrayList.addItem(entity.disambiguous_name);
        }
   }
}

Note the filtering applies to all widgets, including the one making the call.

A visual example of widget filtering is available here.

Saving the widget state across sessions

By default, when a widget is closed it loses all of its state (for example, in a "document search results" type widget, you might have a drop-down list specifying the number of documents to show per page). The exception to this is the location and size of the widget in the framework canvas.

The "onSaveWidgetOptions" and "onLoadWidgetOptions" provide an easy-to-use capability to store any desired state across sessions (ie closing and then re-opening a widget).

For example, assume a flex "ComboBox" object defined in the MXML, with id="documentsPerPage" (with options "5", "10", "20" and "50", from a bound array "_documentsPerPage"). Then the following code fragment would save this option for the logged-in user:

Code Block
languagejavascript
public function onSaveWidgetOptions():Object {
	var json:Object = { documentsPerPage: documentsPerPage.selectedItem.label };
	return json;
}
public function onLoadWidgetOptions(json:Object):void {
	if (null != json) {
		var option:String = json.documentsPerPage;
		if (null != option) {
			for (var i:int = 0; i < _documentsPerPage.length; ++i) {
				if (option == _documentsPerPage[i]) {
					documentsPerPage.selectedIndex = i;
					break;
				}
			}
		}
	}
}

Notes:

  • "onSaveWidgetOptions" is called periodically by the framework (so shouldn't block)
  • "onLoadWidgetOptions" is called after the widget's intialization is complete.
  • As can be seen by the code fragments above, the "Object" passed to from the callbacks represents a JSON object.

Adding a query term to the builder

This is a somewhat more advanced use of the IWidgetContext API, and requires some familiarity with the JSON query API.

TODO

Performing a local query

This is also a somewhat more advanced use of the IWidgetContext API requiring some familiarity with the JSON query API.

TODO

Anchor
CodeAnnex
CodeAnnex

...