Hey I have following situation:
Class Foo has a List of Foos,
Every Foo contains one or more Objects of the Class Bar and has therefore a List Bars.
Every Bar has one or more Objects of Qux, which is another class and because of that is safed in a List named Quxs.
Is it even possible to loop through these Lists / Sets with a Wicket TableTree, TreeTable, DefaultTreeTable or whatever else.
Right now I'm trying to solve this with 3 nested ListViews, which seems not to be the best solution.
Because if you have to use a ListView, whitin a ListView of ListView, it is difficult to get the Object you are refering to.
The decision whether to use ListViews or one of the Tree components should really be made based on the desired look&feel (ie. possible user interactions like opening/closing nodes in a tree). It is definitely possible to present your nested list with its three different classes in a tree (though you may not be able to take advantage of Java generics in this case, unless all the classes have some suitable common interface).
The ITreeProvider interface is a good place to start, if you want to build your own tree structure (https://ci.apache.org/projects/wicket/apidocs/7.x/org/apache/wicket/extensions/markup/html/repeater/tree/ITreeProvider.html).
Related
This is updated version of the question javafx-TableView as combobox popup (Tried and able to achieve partially. need help further)
Based on few inputs I got here and referred some existing custom controls (controlsFX), I started implementing my custom control and achieved most of it but got stuck in middle. So need your support.
I have attached my whole project here for reference.
Let me explain my requirement first.
My real application consists of around 40 to 50 text fields in the scene. Suggesstions should be poped up, based of the text typed by the user in the text fields and user should select something using keyboard and able to tab out to the next text field. The suggesstion popup should be a table view with 2 or more columns. The search can be applied on any 1 column or all columns which should be configured by the user while instantiating the control. Please see the screen shot for your reference.
Now what I have achieved.
I have created a CustomControl with 2 classess which will show a popup with a table view inside below the configured node.
**TableViewPopup.java extends PopupControl
TableViewPopupSkin.java implements Skin<TableViewPopup<T>>**
refering AutoCompletePopup.java and AutoCompletePopupSkin.java from controlsFX project.
This is working as expected (atleast most of the functionalities).
Then I should be able to attach the TableViewPopup to a TextField.
So I created another CustomControl with 2 classess
SearchableTextField.java extends TextField
SearchableTextFieldSkin.java extends TextFieldSkin
So this is the control user will add it to their scene finally and tell this control what tableviewpopup should be displayed when the text changes.
Till here everything works fine.
Where I got stuck or what I want to do?
<SearchableTextField fx:id="personSearchableTextField" referenceDataControlNameToLoad="/view/PersonReferenceDataTableView" />
<SearchableTextField fx:id="vehicleSearchableTextField" referenceDataControlNameToLoad="/view/VehicleReferenceDataTableView" />
In the above code snippet, I have 2 instances of my SearchableTextField each shows 2 different TableViewPopup(one with Person and other with Vehicle).
Now I want to apply different predicates to the tableview's filtered list as the user started typing in the text field.
I have attached a textChangedListener which is inside the SearchableTextFieldSkin class. First of all I dont know how to get the filtered list inside the textChangedListener (Please advice is there any better way.) but somehow I'm referring the filtered list but dont know how to apply the predicates bcoz it may be any different enitties (in my case it may be Person entity or Vehicle entity).
I dont want to check the instances hard coded bcoz in my real application i have around 150 entities.
I also dont want the predicates related logic inside the SearchableTextFieldSkin class. means, i want all my different predicates in a separate file and just want to call them.
Or atleast somehow route the filtering logic from the SearchableTextFieldSkin class.
Please suggest a way and a better way. I really concerened about performance bcoz what i am doing is a c# with dev express components project that i am currently rewriting in java using javafx bcoz the performance is worse like anything in c#.
Thanks in Advance.
I would be trying to keep the Predicates close to, or inside, the controller that needs to use them. PersonController should deal with Person predicates, VehicleController with the Vehicles ones, and also with any logic for deciding which fields are searched etc.
There are a few ways to do what I'm thinking, but they all boil down to passing the search field text back through to the IGenericReferenceDataController implementation, which resets the Predicate on the FilteredList.
You could expose a StringProperty on IGenericReferenceDataController to track the filter text. A helper class that encapsulates the FilteredList and the Predicates for a particular controller, exposes the filterText property and handles the logic for resetting it would be better as that should be fairly generic code that you can plug into the IGenericReferenceDataController keeping it all isolated. Something along the lines of:
public interface FilterHelper {
public StringProperty filterTextProperty();
// any methods to assign filters for columns etc. such as
public void assignCurrentFilter(...);
... etc ...
}
Then get IGenericReferenceDataController to expose it's instance of this class:
public interface IGenericReferenceDataController extends IGenericController {
public FilteredList<?> getInnerTableViewControlDataSource();
public FilterHelper getFilterHelper();
}
You would need to pass that out through TableViewPopupSkin and TableViewPopup until it finally gets to SearchableTextFieldSkin where you can have:
private void registerListeners() {
tableViewPopup.getFilterHelper().filterTextProperty().bind(sourceSearchableTextField.textProperty());
...
}
Your FilterHelper implementation then handles resetting the filter on the list every time the search text changes and SearchableTextField knows nothing.
If there is a faster way to get from SearchableTextFieldSkin to IGenericReferenceDataController you could cut out some of the intermediary methods that just pass the reference along, but I couldn't see any in your code and I don't use fxml so I have no idea what magic might be possible there.
I'm developing a game in Java which I can only describe as a variant of The Sims.
The main interface for the game consists of a level and will have a large variety of furniture which can be placed on the map. My problem is that whilst I can think of ways to construct a system which will allow me to assign properties to each item of furniture, I want to make sure I do it the correct way before I head down a long path to completing it. For example, if I referenced an object with an identifier of "sofa", the furniture object's members could be accessed through searching through all available objects and finding the one with the matching identifier.
My method would be to make a very large .java file with instances from a base furniture class for each item of furniture, with each one having an identifier and all its different properties assigned, such as image, position, rotation etc, plus their own unique code for each different function they provide (eg. sitting, sleeping).
For saving/storing these objects in a text file, I would just store the name of the identifier in the string array in the text file and when loading, I could just create the object by instantiating the object the identifier points to.
Would I be correct in using most of these methods, or are better ones available? If you've found it a struggle to comprehend what I've written (and I had trouble writing it clearly), then a more simple question would be:
How are items of furniture managed in The Sims with respect to the sheer amount available and the many different variations/rotations they can be placed in (and stored/saved)?
I think what you need to do here is try and abstract as much of the common functionality to the base classes and then each item should extend as necessary.
Eg
A Sofa... Seat extends Furniture extends Object
A Office chair would be the same
A DiningTable would be different tho... Table extends Furniture extends Object
You will also want various Interfaces so that a Sofa implements Sittable think of the functionailty that might be common to different objects, like they might all be Placeable
Also for saving and loading you might want to make your objects serializable.
Read up on Abstraction, Interfaces and Serialization
Component-Entity-System may be a good thing for you to look into. It's basically what you're describing. There's a large collection of entities, each entity has a collection of Components, and there are systems which know what to do with certain components.
EG: A piece of furniture is an entity named "chair". It has many components, one of them is "Renderable". And your game loop passes all renderables into the "renderer" System which calls the Renderable.render() method.
Note, this isn't very object oriented, but I find it's tough to design games like this in an OO way because the object hierarchies explode. Everything has some things in common with everything else. You'd end up with generic classes like "Unit" and "Thing" which isn't very OO either.
I am building an application which is basically just a GUI for displaying and editing one single object. Since the class for this object was created with JAXB, it is basically a tree with many Strings and integers as children, but there are also some List<E>s. For each simple child JAXB provides a getter and a setter, but for all lists only a getter is provided, since it gives a reference to the internal list, which can now be modified.
Since I need to display every child (and branch for that matter) in a separate swing GUI component, I need these views to handle some data. According to my current knowledge about the model view controller design pattern, I should strictly separate the model from the view. Following this, it would be a bad idea to let a JList operate directly on an internal list of my base object. (Actually doing so would be a pretty easy solution to my specific use case, but since additional functionality might be added later on, I think I should refrain from this idea.)
Then I started thinking: If I do not let the components work on the list directly, I have to make them use a copy of the original. But since I cannot set the original list to a new one returned by my GUI component, I have to copy the items another time when saving the view data to my model. Also, it would not be wise to hand out references to internal lists of a custom ListModel, which would mean, that depending on the depth of the GUI structure, the list may be copied additional times.
Since I also want my application to be efficient, this does also not seem like the correct approach. How do I build this "correctly"?
Summary:
The List<E> from the original object is a reference to an internal list of
the object.
The JList displaying the list should not get this reference,
hence it must copy the list.
Getting the list from the JListshould not yield in a
reference to the internal list either, hence it must be copied again.
Saving the list to the original object must copy the list a third
time, because the original object does not have a setter method for the list. (see
above for details)
Is my grasp on this correct? How do I build this properly and make it efficient?
P.S: Adding setter methods to the original class structure is not an option!
was created with JAXB, it is basically a tree with many Strings and
integers as children, but there are also some List<E>s. For each
simple child JAXB provides a getter and a setter, but for all lists
only a getter is provided, since it gives a reference to the internal
list, which can now be modified.
see
JTreeTable
JList (unmodifiable), better could be JTable (with / without JTableHeader) in JTree
All of the components suggested by #mKorbel provide some kind of selection listener that will allow you to loosely couple a selection in one panel to the selected item's display in another. FileBrowser illustrates a TreeSelectionListener; Outline can have a ListSelectionListener, shown here; etc.
Addendum: In this related example, DisplayPanel listens to an adjacent TableModel, which it can query to update a model in one of it's own components. Note that each model is loosely coupled to its respective view. Common notification mechanisms are mentioned here.
Wicket has many implementations of AbstractRepeaters: ListView, DataView, GridView, Loop, PropertyListView etc.
Personally, I find it hard to determine which view would be ideal for which scenario. I usually stick to DataView but that's simply because I'm used to it. Maybe GridView would be better for scenario A, a PropertyListView for B, ....
Is anyone aware of a blog or any tutorial where the differences of the views are explained or anyone who can explain which view is best for which use case?
Wicket has a lot of additional, trivial classes, which is causing your confusion. Different components are better for different scenarios, but there are a lot of Wicket components for rare cases that don't add any real complexity.
For example, RequiredTextField is an entire class that is equivalent to:
TextField x = new TextField("text");
x.setRequired(true);
I presume this stems from an older version where setting required was more complicated, but it's still there to cause some confusion.
Many of your repeaters are similar. PropertyListView just wraps the model in a CompoundPropertyModel, making property expressions easier (see below). However, you could easily make this change yourself.
So, here is my quick summary as I have been unable to find an up-to-date blog post as you've described:
RepeatingView - very useful when you do not have a list or you are adding different types of components (and therefore different internal markup).
ListView - useful if you have a List and you're displaying the whole thing. Sadly, it does not work with other sorted collections.
DataView - useful if you are loading from a Database. Additional methods allow you to easily sort, page, and modify the data set.
PropertyListView - useful if you are simply displaying values via a property expression. Allows you to do
item.add(new Label("name"));
instead of
item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")))
Loop - useful if you want to repeat an Integer number of times instead of a set list of data. This would be equivalent to a ListView whose model object is a List<Integer> filled with integers from 0 to length
GridView - useful for taking a single list (e.g. 21 strings) and using two sets of markup (inner/outer) to display that list in groups (e.g. a 7x3 grid). It assumes, however, that your markup uses certain wicket:id's, which is not well documented. I think you would be better off with a pair of nested RepeatingView components, which accomplish the same thing.
Hope that helps!
I would like to have a composite structure which is build from JSON. Each element can has only one type of children - so a group can contain only groups or only leaves. Then based on this tree I want to draw graphic user interface component, which will render diferrently and run different actions due to the type of itself (group or leaf).
The question is how to determine what to render and which listeners to attach on drawing. The tree is only a model, so it should not contain methods to do the graph or controlling.
Is it a good or bad pratice to check if it is instance of something and cast component to to right type and then do the right set up?
What about having a enum and getter to determine it?
I know answers that will work but I want to hear about good pratices.
Is it a good or bad pratice to check if it is instance of something
and cast component to to right type and then do the right set up?
Personally I think this will break the pattern.
Accordingly to wikipedia:
When dealing with tree-structured data, programmers often have to
discriminate between a leaf-node and a branch. This makes code more
complex, and therefore, error prone. The solution is an interface that
allows treating complex and primitive objects uniformly. In
object-oriented programming, a composite is an object designed as a
composition of one-or-more similar objects, all exhibiting similar
functionality.
Composite is a pattern that help you to use both container and leaf as the same type.
Look this diagram.
I suggest you to add and abstract draw method to the component class and let its subclasses implement it. Leaf will have a different implementation than Composite. This way a client class traversing your tree doesn't need to be aware if a node is a Leaf or not, but can simply call draw method on it.