JGoodies list binding - java

Does the JGoodies list binding support binding list contents to a list object in the model? I know I can add listeners to the list model and domain model and coordinate changes between the two fairly easily, but I wasn't sure if JGoodies would do that. I could only find list binding that dealt with list selection events.

I'd suggest you use GlazedLists. It's really easy to use and works great.
One issue is you have to use one of their classes that implements EventList; you can't just bind a list model to a pre-existing List.

It looks like the LinkedListModel and ArrayListModel do this. I overlooked those before.

Related

assign data from dto to group of text fields in javafx

I'm new to JavaFX and what I'm trying to do is I have a DTO object with 15 fields that I fetch from backend which I need to show all the fields in screen
for now what I did for each filed will create textfield in fxml file and inject it in the controller using textfield id then set the text for that from the dto for example
#FXML
TextField firstName;
........
firstName.setText(dto.getFirstName)
so is there is any other way than going through each textfield and using setText to set their value
As you state that you are new to JavaFX, I do not recommend that you try to implement the potential approaches in this answer.
Investigate the controlsfx BeanPropertyUtils, PropertySheet and PropertyEditor.
Different potential implementation strategies:
You could use a collection of TextFields, e.g. a list and assign values sequentially based on, for example, position in an sql row set.
Or perform a lookup on a map of strings to TextFields based on a column name key.
Or use reflection on Java Beans (this is how controlsfx works).
But none of them would be worth implementing unless you have a great many fields and need some generic system to handle values. Otherwise I wouldn’t recommend implementing such abstract functionality.
An example of a generic use case would be if you were introspecting on an unknown large database schema.
If you do need to do this, probably your best place to start would be the controlsfx library.
SceneBuilderKit, which was used to build SceneBuilder, has similar functionality but it is not as easily accesible as ControlsFX.
I advise you review the above comments then decide if you really want to do this.
If you do, then choose one potential strategy and implement it (this won’t be done in a StackOverflow answer).
If stuck, provide a complete minimal reproducible example for a concrete example and implementation attempt in code, only for the art of the problem you are stuck on. This allows you to create a more concrete question that is greatly reduced in scope.

Xpages "Views" with beans: Categorize, Sort, Search

I'm trying to do the OOP approach in all my xPages. As expected I'm facing several issues, but also have tons of advantages doing so.
My question is related to Views (Repeat controls). I am loading a List<myCustomBean> for my repeat controls that contains all available objects of type myCustomBean and display each myCustomBean the way I want in a Bootstrap table row. That works all fine.
I'm able to sort my List with URL parameter sortedBy=MySortColumn with my own method. - Problem 1 solved.
How would I approach a Categorization in my Repeat Control? So I could easily sort the beans by the Cotegory, but how would I display it, incl. expandable and collapsible twisties? Maybe there is a Custom control that I can use? Or a Control of the Extension Library?
Or do I have to build everything from scratch myself?
Any advice is much appreciated.
The Data View control is probably the best. Like the View Panel or Data View, it's a extension of the Repeat Control. But it has much more flexibility that the View Panel and allows much more configurable layout than the Data View. It has a categoryColumn property, but that's designed for binding to a dominoView datasource. But there is also the categoryRow facet which can be used.
Essentially, using a dominoView component is already using OOP programming. Your repeat is using List<myCustomBean>, dominoView returns List<DominoViewEntry>. Properties on the dominoView are used to interrogate the underlying View object within the database and return only those ViewEntry objects from the ViewNavigator or ViewEntryCollection that are required. It wraps the ViewEntry as a DominoViewEntry object for just a selection of those, based on the rows property of whatever uses the DominoView.
As someone who built a subset of that functionality for use from Vaadin (see my XPages to Web App blog series http://www.intec.co.uk/tag/xpages-to-web-app-tutorial/), within XPages I typipcally use the dominoView object unless I'm extracting a small subset of ViewEntries / Documents. When I use ViewEntryCollection / DocumentCollection, I rarely wrap, preferring to let XPages optimise retrieval rather than re-develop that optimisation myself.

Representing a collection of models in Java MVC (with SWT)

In C#, there are observable collections. In Java how do I represent a list a models? Suppose I have a model Item. I want to show users a list of Items. Do I create a ItemsModel (notice plural, encapsulating an ArrayList<Item>) then in my ItemsView bind (listen to property change events) to that? This model will also need to listen to PropertyChange events from its underlying Item. Is this the right way of implementing this? Is there a better way?
A possible solution could be the Eclipse Databinding. It let's you create a binding from your POJOs to certain SWT Controls. For your special case with Items, you could use the Master-Detail Binding mechanism, for an example see http://wiki.eclipse.org/JFace_Data_Binding/Snippets#Master_Detail
Depending on the source of your domain model, you could consider changing it to use Eclipse Modeling Framework (EMF). EMF have complete a notification framework for all changes made to the model, which makes it easy to use and bind to. Eclipse Databinding - as mentioned by Tom Seidel - also bind to EMF.

How to register a change in a JList Model?

I am having issues understanding which interface I need to listen to changes in a listModel. I thought it was ListDataListener, but I can't understand the methods in it. There are 3 methods in it and this one seems to be the one I want but I can't understand the description:
contentsChanged(ListDataEvent e)
Sent when the contents of the list has changed in a way that's too complex to characterize with the previous methods.
What does it mean by "too complex"? And by "characterize with the previous methods"? Well, what does the whole thing mean? Is this the interface I want?
ListModel dispatches events to its ListDataListener listeners. It's more efficient for the list model to invoke the detailed intervalAdded and intervalRemoved methods when possible. The Listener of the list model (in this case a JList) can use these detailed changes to make minimal changes to the visual component (ie, for intervalAdded it can just add the new row instead of redrawing the whole list).
However, some changes may be too complex to be described as with just added and removed. In this case, the list model has the option of invoking contentsChanged. When JList sees contentsChanged it will most likely refetch the entire list from the list model.
Yes, that's the right listener.
The statement means that this method is the more general one, that will cover every possible change to the list content. The other ones (intervalAdded and intervalRemoved) should be used when those specific events occur.
In my practice you will always use the most general one (even with table listeners).. I guess it was supposed to be used to optimize (especially with big lists).
A tutorial on this listener can be found here.

Displaying class contents in a GUI with Swing

I have some classes with fields and getters/setters and I want to display the fields of the class in a Swing application.
The name of each field should be dosplayed in a Label and the value should be displayed depending on the type of the value, i. e. String uses a TextField, List uses a ComboBox and so on.
One difficulty is that the class can contain fields, which also need to be treated this way itself.
Is there a recommended/standard way of doing that?
I looked a bit into java.beans but I'm not really sure if it isn't primarily used when the class is a Swing component itself.
Another option is to use PropertySheet component from L2FProd. From you description it should do exactly what you wanted.
It wasn't updated for a long time but works well.
I don't think there is an automated way to accomplish this. In fact I think you might even be approaching it incorrectly. What if you List contains objects other than Strings for example, how is a JComboBox going to break this out? I would suggest just using a JTable and putting the name in the first column and the value in a second column.
You could add #Annotations to your fields you want to examine and display in the GUI. In every case you have to use reflections to access and find all the fields you want to display. I think you have to add a custom logic to the databinding which examines a given class for it's fields (maybe filtered with a #Display annotation or stuff like this).
This should be very easy to implement, you can rely on the POJO Bean definition and access all the fields over getter/setter, don't forget to cache the handled classes to avoid circular dependencies of classes.
I hope this helps.
There is ReflectionUI. It can display primitive values objects and lists by just using reflection. It works well with getter/setter properties.

Categories

Resources