Can I define multiple itemRenderers in a Flex / Actionscript list - apache-flex

Basically I want to override some function in the flex/actionscript list class which creates a new ItemRenderer and passes it the required data ready to be displayed. I need to do this because I wish to show a different renderer based on the type of data being displayed. Is there such a function?
I don't really want to pass the list a single itemRenderer which calls its addChild function depending on the type of data it has - It just doesn't seem right...
Thanks.

You should override public method createItemRenderer(data:Object):IListItemRenderer of ListBase class (and List, which extends ListBase)

Related

Simple binding with JavaFX8

I have been exploring JavaFX8 for a few days and am trying to educate myself with the concept of binding. I've created an ObservableList like this
private static ObservableList<XYChart.Series<String, Number>> chartData = FXCollections.<XYChart.Series<String, Number>>observableArrayList();
I then go through a few steps to create an AreaChart and have had success calling the setAll() method below
areachart.getData().setAll(chartData);
It is my understanding though that bindings would allow me to remove this step by associating the data property with the list. If the list changes, the chart data property would automatically be "updated".
I've tried to bind the data property like this
areachart.dataProperty().bind(chartData);
However, its asking for a syntax that I'm not familiar with at all
(ObservableValue<? extends ObservableList<Series<String, Number>>> arg0)
Can someone please help me create the correct syntax to bind the list to the area chart? If I've gotten the concept of binding all mixed up please let me know.
JavaFX's ObservableList is special List which can be observed for its children manipulations by attaching an event handler to it. Please read related javadocs for more info.
In JavaFX, the ancestor of all charts, XYChart has a dataProperty() which is ObjectProperty<ObservableList<XYChart.Series<X,Y>>>. Namely this is a property field that holds an object whose type is ObservableList. And this is the field you need to set its holding observable list directly as
areachart.setData(chartData);
Now the data of areachart and chartData are referencing the same list, any removing/adding to chartData will be "reflected" to areachart's data and vice versa.
The
areachart.getData().setAll(chartData);
is also valid but it will copy list-to-list. I.e. it will internally loop the chartData and copy its children (XYChart.Series in this case) into the data observable list of areachart. Resulting to different lists, so no relation, no "reflection" between them.
The
areachart.dataProperty().bind(chartData);
is wrong. Because it is trying to bind, roughly saying, the property<list> to list.
Even though the dataProperty is ObjectProperty<ObservableList<XYChart.Series<X,Y>>>, binding to it through dataProperty().bind() will expect ObservableValue<? extends ObservableList<Series<String, Number>>>, where ObservableValue is a superclass of ObjectProperty. This is by design, there were discussions on this topic on SO, but cannot remember the actual Q&A entry. Try to search them.
Before going deeper in JavaFX refer to Using JavaFX Properties and Binding and other resources to understand it better. Generally speaking property is a wrapper to its holding object, by providing an observer like pattern to its state changes and also providing flexibility to plug up to other property objects through JavaFX APIs. See for example Bindings and its usage examples on the net.

Dart/Polymer binding object attributes of a list

I am trying to bind to the attributes of objects in a list. The list is made observable by using toObservable. Now I bind all the elements with polymer. Works fine. If a add an object to the list the update works also fine. But there is no update if the attributes of the objects in the list is changed. How can I achieve this?
I think you miss extends Object with Observable of the class declaration and/or the #observable annotation of the property declaration as shown below:
class YourListItem extends Object with Observable {
#observable aProperty;
}
If this doesn't help please provide the code of the objects you put into the list in your question.

How can i make an object unmodifiable in flex

I am having a configuration object in my flex3.5 application. I want that object to be unmodifiable so that no one can change any property in it once it is created.
If you're talking about a generic Object, it's impossible since it's dynamic. What you want to do is create a class that has only 'getter' functions and every property is specified in the constructor.
If you want to have it still bindable, look at my blog post about bindable read-only properties.
Use get/set methods. There is can be two strategies:
Private variables are initialized within class itself and every private variable has public get-method which makes public field read only.
If you need to set values from outside you should create set-methods and throw an error if value already set.

Flex AS3 - Inheritance and factory method

Before asking my question I would like to explain little about my architecture.My data is of mixed types like String , Array Collection , Boolean I have to populate the data into appropriate UI component - for example Boolean to check box , Array to List...... so We have created a factory class which will return 3 different type of component based on the input argument
CTextfield -> extends mx.controls.Text
CList -> extends mx.controls.List
CCheckBox -> extends custom.MultiLineCheckBox
.
MultiLineCheckBox which extends mx.controls.CheckBox and few methods are overridden to bring the multiple line label.
http://spy6.blogspot.com/2008/09/flex-multiline-checkbox.html
It works perfect.Am using the MultiLineCheckBox in the entire application wherever I want check Box.
Now I went into a scenario where I want check Box instead of MultiLineCheckBox. How to rewrite my CCheckBox to handle MultiLineCheckBox and also default CheckBox?
Note : Each of the CCheckBox class has lot of methods init.
You need an abstract factory that extends from your concrete factory (http://cnx.org/content/m17203/latest/AbstractFactory.jpg) then write the logic of handle the different scenarios in it, when to use checkbox vs multilinecheckbox

HowTo access correct data inside an AdvancedDataGridColumn-ItemRenderer?

How can I access the specific .data (based on its dataField) inside an AdvancedDatagridColumn-ItemRenderer instead retrieving the whole data for the parent AdvancedDataGrids dataprovider?
Any idea?
Many thanks...
In an itemRenderer, your dataProvider's object is passed in to the data property of the itemRenderer. Your itemRenderer will need to implement the IDataRenderer interface
http://livedocs.adobe.com/flex/3/langref/mx/core/IDataRenderer.html
Most Flex Framework Components already implement this interface.
The way that the DataGrid component works internally is to call an itemToLabel function ( http://livedocs.adobe.com/flex/3/langref/mx/controls/listClasses/AdvancedListBase.html#itemToLabel() ) to figure out the label to display. This function will look at the dataField and dateFunction and return a string representing your item.
The results of this function are passed into the itemRenderer as part of the AdvancedDataGridListData class. Take a look at the label property:
http://livedocs.adobe.com/livecycle/8.2/programLC/common/langref/mx/controls/advancedDataGridClasses/AdvancedDataGridListData.html
You can also use DataGridListData.owner to access the dataField directly, although that would be an unusual approach.

Resources