...
1. First will will create 2 lists in our widget, the left list will show the documents titles, and the right list will show all the entities in the resulting dataset.
Lets first create a group to hold our 2 lists so they will align appropriately:
Code Block | ||
---|---|---|
| ||
<s:HGroup width="100%" height="100%"> <s:List id="titleList" width="50%" height="100%" dataProvider="{titleArrayList}" /> <s:List id="entityList" width="50%" height="100%" dataProvider="{entityArrayList}" /> </s:HGroup> |
...
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:
Code Block | ||
---|---|---|
| ||
var queryResults:ArrayCollection = _context.getQueryResults().getResults(); for each (var doc:Object in queryResults ) { titleArrayList.addItem(doc.title); for each ( var entity:Object in doc.entities ) { entityArrayList.addItem(entity.disambiguous_name); } } |
...
You can download the IWD:full code example here or see the widget code below.
Code Block | ||
---|---|---|
| ||
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <!-- The MIT License Copyright (c) 2011 IKANOW llc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> <mx:Module xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" implements="com.ikanow.infinit.e.widget.library.widget.IWidget" creationComplete="init(event)"> <s:HGroup width="100%" height="100%"> <s:List id="titleList" width="50%" height="100%" dataProvider="{titleArrayList}" /> <s:List id="entityList" width="50%" height="100%" dataProvider="{entityArrayList}" /> </s:HGroup> <fx:Style source="../com/ikanow/infinit/e/assets/styles/infiniteDefaultStyle.css" /> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; /* If you need to override a style in our stylesheet, or add another style that we did not support you can do so here, an example has been commented out Please see documentation about over-riding MX component styles to display fonts */ /* mx|Text { font-family: infiniteNonCFFFont; } */ </fx:Style> <fx:Script> <![CDATA[ import com.ikanow.infinit.e.widget.library.data.IWidgetContext; import com.ikanow.infinit.e.widget.library.widget.IWidget; import mx.collections.ArrayCollection; private var _context:IWidgetContext; [Bindable] private var titleArrayList:ArrayCollection = new ArrayCollection(); [Bindable] private var entityArrayList:ArrayCollection = new ArrayCollection(); /** * Method fired when module is done loading. Sends * message to parent letting it know that module is * ready to receive data. */ private function init(event:Event):void { var events:Event = new Event("Done Loading"); dispatchEvent(events); } /** * IWidget interface to receive data object (IWidgetContext). * Store the iwidgetcontext so we can receieve data later. */ public function onInit(context:IWidgetContext):void { _context = context; } /** * IWidget interface that fires when a new query is done. * We can access the data from the query by using our * iwidgetcontext object _context.getQueryResults(). */ public function onReceiveNewQuery():void { titleArrayList.removeAll(); entityArrayList.removeAll(); var queryResults:ArrayCollection = _context.getQueryResults().getResults(); for each (var doc:Object in queryResults ) { titleArrayList.addItem(doc.title); for each ( var entity:Object in doc.entities ) { entityArrayList.addItem(entity.disambiguous_name); } } } /** * IWidget interface that fires when a new filter is done (including from ourself) * We can access the data fromt he filter by using our * iwidgetcontext object _context.getFilterResults(). */ public function onReceiveNewFilter():void { var filterResults:ArrayCollection = _context.getFilterResults().getResults(); } /** * function to rescale the module when the parent container is being resized * * @param newHeight The new height the component needs to be set to * @param newWidth The new width the component needs to be set to */ public function reScale(newHeight:Number,newWidth:Number):void { this.height = newHeight; this.width = newWidth; } ]]> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> </mx:Module> |