I have the following:
List<Cars>listview=new ArrayList<Cars>();
ObservableList<Cars>data=FXCollections.observableArrayList();
How I can set observable list with List<Car>?
Because I want to make class of List<Car>listview and get all items from it for use in Observable list (for show sql server information in table).
FXCollections.observableList(listview);
or
FXCollections.observableArrayList(listview);
In both cases, you should no longer modify the list using the original listview.
The difference of these two is that the first method creates an observable list that updates the original list, while the second method creates an observable list that starts with the elements in listview, but these two lists are unrelated after that.
Related
I'm new to RxJava, and trying to use the Realm Observable feature.
When doing this
realm.where(Intake.class)
.findAllSorted("time", Sort.DESCENDING)
.asObservable()
I get the full list of items, but when soemthing changes (ie item added), I get the full list again.
What is the RxJava-way to get only the new items?
Thanks in advance
You are currently observing the query results. Because your query can contain multiple items (findAllSorted()), you're always observing the RealmResults that will emit all sorted items when there's a change (see docs).
You can do something like this:
realm.where(Intake.class)
.findAllSorted("time", Sort.DESCENDING)
.asObservable()
.flatMapIterable(results -> results)
.distinct();
This does 2 more things:
convert your RealmResults to singular Intake instances
only let distinct items pass through (make sure your Intake implements equals() correctly)
This does however impose some extra CPU load, because each time the query passes on a new RealmResult, processing is done to filter out the distinct items.
In the above example, sorting will work on the initial set of emitted Intake objects. However, any subsequent emitted items could be observed out of order because they are new and emitted after the initial results.
I have a JavaFX TableView defined as :
TableView<MyMessage> messages;
It is supported by an ObservableList :
private ObservableList<MyMessage> messagesList;
// Allocate the message list
messagesList = FXCollections.observableArrayList();
// Set the list into place
messages.setItems( messagesList );
The MyMessage object has 10 fields all of type String. There is a background operation that inserts MyMessage objects into the ObservableList.
messages.add( new MyMessage( String ... colData ) );
Everything works as advertised. The table rows of the TableView are updated as objects are inserted into the ObservableList.
What doesn't seem to work as expected, is if I click on a column header to sort the table, the subsequent items inserted by the background thread are appended to the end of the table. Not to the proper sorted row position. If I click to resort the column, the table is resorted properly.
Do I need to some how force the re-sorting of the table each time I add something to the ObservableList? Or should the TableView take care of that for me.
Thanks.
Java FX 8 now has a .sort() method on tableView that can be called to re-trigger sorting. Some operations will trigger a re-sort automatically but external events adding/deleting entries in the observable collection do not.
should the TableView take care of that for me
No.
There was a request that TableView maintain sort order as the underlying list changes but it was closed as "not an issue". You can review the comments on the issue for more detailed information. In short, keeping the list sorted is the responsibility of the underlying ObservableList or the application maintaining the list.
Do I need to some how force the re-sorting of the table each time I add something to the ObservableList?
In essence, yes.
JavaFX was supposed to ship with a SortedObservableList implementation which effectively cooperated with the TableView to make all of the sorting handling pretty much automatic for the application. But, for JavaFX 2.2, the functionality did not make the cut for inclusion. Currently, this functionality is scheduled for delivery as part of JDK/JRE8 and can be tracked via this umbrella issue for improved sorting support in TableView.
I was wondering what the difference between data and listData in itemRenderers in flex. I have worked with data in all of my itemRenderers.
Basically I want to know when to use which, where each gets set and if I can use them together?
Note that I am asking from a Flex3 point of view.
data is the data that the renderer should display. Use it to work with the original data currently assigned to the renderer.
listData is an additional object to provide you with information about the role of the renderer in the list (rowIndex, columnIndex, list component, uid, ...). Use it to perform some UI related operations such as formatting the first row differently or rows alternating depending on their vertical index, calling the list view component, etc.
Each item of your dataProvider collection is passed to data variable. You entirely define, what is passed to data by defining dataProvider content.
Information about the cell of datagrid/list (such as row/column index, label) is passed to listData (see BaseListData). To use this variable your itemrenderer should implement IDropInListItemRenderer interface.
See details about listData here. The main point is:
The list classes will pass more information to the renderer so that it
can determine which field to use at run-time.
So listData is for advanced usage for more complicated item renderers.
See this:
http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_4.html
And this:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/listClasses/IDropInListItemRenderer.html
I have a Dev-Ex Tree List which has two columns, List contains elements inside it, Now My question is if i want to add any new item in the list then logic should search existing items in the tree, if no match found then it should allow to add that item in the list,otherwise not.
can i make a method which keep on checking recursively new item with the other item in the list.
Such tasks are usually solved by using TreeList Iterator. I think that the How to Implement an Iterator for the XtraTreeList (FindNode Example) knowledge base article contains the code you are looking for.
Is there any way to get the sum of items based on some filters from sharepoint list? I was trying to access the GetListItems method. But this returns all the items in the list. That makes the data heavy. My requirement is to get only the sum of items.
For example items created in a specific year. I am trying to populate a chart in flex from the sharepoint list. Accessing all the items and then calculating the sum in flex will not work always where the list contains more items.
Use the viewFields parameter of GetListItems to only return a single (small) field like ID. It is still data heavy but better than returning all the fields from the list.
There is a rowLimit parameter too that you can use to return all the list items instead of only a block at a time.
Info on the GetListItems method with code snippets at MS:
http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12).aspx