JavaFX 8 Overriding a property value for a specifc control - properties

I'm creating a JavaFX app. Is there a way for a control to override a parent container's property value with a different one which will be relevant only for itself?
My specific case is having an HBox which has a value for the spacing property, but I want 2 controls to be closer togather, meaning overriding the spacing property for one of the controls and only on a single side (like the padding property) so the controls will be closer togather? Or do I have to do it with an additional HBox which will hold these 2 controls?
If you could also answer the general case and not just the specific one, that would be great.

It is not possible for one property to be two different values for different children, as can be seen from the API:
public final void setSpacing(double value)
public final double getSpacing()
If the HBox were to save different spacing on a per-child basis, it would the child would have to be passed into the getSpacing/setSpacing methods.
Just use one outer HBox (big spacing), which contains an inner HBox (small spacing).

Related

Adapting the number of EditText inputs in Kotlin from user defined int value?

I am working on building an application in Android Studio and I have my Edittexts to accept user input (as int) and can pass it to the subsequent activity after clicking 'next'. However, my question is do I take this integer input and convert it to that number of subsequent inputs in the next activity? User inputs '5' for example and now I want in the next activity to be able for the user to define their 5 inputs. If 4, only create 4 new textEdits in the next activity etc.
I haven't seen a solution for this online and don't know how to create this variable input.
Two different approaches.
If they are part of a big or complicated layout in a ScrollView, this is probably the one you should pick. Create a parent view for them, such as GridView or LinearLayout, in your XML layout for the Activity. You can add two or three EditTexts to this parent in your layout temporarily to figure out what layout params you want to give them to get the right look.
Then create another xml file to represent each individual EditText by itself, with the parameters it will have when added to the parent view. (You could alternatively skip this step and do all the EditText setup in Kotlin code, but that's a bit more complicated to get right.) This is just an example. You should use the layout parameters that make sense for what you're putting it in.
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:id="#+id/editText"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:inputType="text"/>
Then in onCreate(), you can instantiate them in a List constructor, and add them to the parent at the same time. Use the LayoutInflater to do this. The layout ID is the one for the XML file of the single EditText. PAssing true as the third parameter adds the newly inflated view to the parent view group.
val parentView = binding.editTextsParent // or findViewById if not using view binding
val editTexts = List(numberOfEditTexts) {
layoutInflater.inflate(R.layout.single_edit_text, parentView, true)
}
And now you have a List of your EditTexts that you can use to grab data from them, or iterate to set up TextWatchers, etc.
Use this if there are a lot of them or they are going to be the only thing on the screen. In this case, we would use a RecyclerView. There are tons of tutorials on RecyclerViews, so I won't explain exactly how it's done. But to apply a RecyclerView in this case, your backing list of data would be a List of Strings that is the same size as the number of EditTexts you want to create. The layout you create for each item to put in the RecyclerView.Adapter would have just an EditText in it. You would have to add a TextWatcher to each EditText that updates the values in the backing List as they are edited. This is so if an EditText is recycled (a new one scrolls onto the screen), you can update it with the text that the corresponding list item was last showing before it scrolled off the screen.

Saving Entity does not update class-hierachy labels correctly

I have an abstract superclass Report and two Subclasses SimpleReport and ExtendedReport, which I want to persist in my database.
If a SimpleReport is created, it has the labels "Report" and "SimpleReport" attached to it, as expected.
A user can modify such a SimpleReport, which leads to the SimpleReport becoming an ExtendedReport.
If I now save this ExtendedReport (using the same ID as the SimpleReport, because I just want to update it) it has the labels "Report", "SimpleReport"and "ExtendedReport" attached to it.
IMHO the label "SimpleReport" should be removed on save. I`m currently deleting the wrong label using a cypher query after saving the updated report.
I´m asking if there is a better way to archive this, if may approach is wrong or if this is a bug in ogm?
The rules for labels are as follows:
any plain concrete class in the hierarchy generates a label by default
plain abstract class does not generate a label by default
plain interface does not generate a label by default
any class annotated with #NodeEntity or #NodeEntity(label="something") generates a label
empty or null labels must not be allowed
classes / hierarchies that are not to be persisted must be annotated with #Transient
Therefore if you remove abstract from your base class, or add a #NodeEntity annotation, you will see the results you expect.
Edit:
The OGM does not remove labels when a class is renamed. Any additional labels are left intact.
You can remove these manually using direct database access.
You can declare a field with the #Labels annotation to manage adding/removing additional labels from an entity.

DataTemplateSelector in SemanticZoom.ZoomedOutView

I have a set of groups of different types of item, all inheriting form a common base type (ItemBase). Each of my groups has an Items collection of type ObservableCollection<ItemBase>.
In my SemanticZoom.ZoomedInView, I can set a DataTemplateSelector, and in SelectTemplateCore() I can cast the item parameter to detrmine which template to apply.
In my zoomed out view, though, the objects are passed around as DependencyObjects, and I can't for the life of me figure out how I can take the data passsed in to determine which template to use.
To set the items source of the GridView in the zoomed out view, I use
(semZm.ZoomedOutView as ListViewBase).ItemsSource = this.groupedItemsViewSource.View.CollectionGroups;
as this appears to be the only way to get the zoomedin and zoomedout views to synchronise (when you click on a group in the zoomed out view it should take me to the appropriate place in the zoomedinview to see that group's detail.
So, am I missing something obvious in terms of getting the actual group in SelectTemplateCore(), or failing that is there a better way of binding my ItemsSource of the ZoomedOutView?
For the appropriate way to handle casting of the DependencyObject to a usable type, see the answer to This question.
Essentially, cast it to ICollectionViewGroup to access the members.

Reusing property editors for Blend 4

I have a custom silverlight control, which exposes a property with DataGridLength type. Now I want that property to have the same editor as a common DataGridColumn's Width property, with the combobox and everything, like this:
instead, I only get a simple TextBox, with "Auto" written in, with no way to set to SizeToCells and so on.
I assume I need a DesignTime attribute, but none of the ones I found in ComponentModel namespace even came close...
I guess you just have to create an Enum with the all the values autorized (Pixels, SizeToCells, etc ...), you that Enum as the type of your property DataGridLength and then, in the code of your control, take the corresponding action regarding the value sent.

How to use GtkTreeView correctly

I am using a TreeView with a ListStore as model. When the user clicks on a row I want to take some action but not using the values in the cells, but using the data I created the row from...
Currently I have the TreeView, the TreeModel (ListStore) and my own data (which I ironically call model)..
So the Questions are:
Is it "right" to have a model - an object representation of the data I want to display and fill a ListStore with that data to display in a TreeView, or would it be better to implement an own version of TreeModel (wrapping my data-model) to display the data?
And also:
If someone double-clicks in a row I can get the RowActivated event (using C#/Gtk#) which provides a Path to the activated row. With that I can get a TreeIter and using that I can get the value of a cell. But what is the best practice to find the data object from which the row was constructed in the first place?\
(Somehow this question got me to the first one - by thinking would getting the data object more easy if I tried to implement my own TreeModel...)
It's quite awkward/difficult to implement TreeModel, so most people simply synch the data from their "real" model into a TreeStore or ListStore.
The columns in the store do not have to match the columns in the view in any way. For example, you can have a column that contains your real managed data objects.
When you add a cellrenderer to a TreeView (visual) column, you can add mappings between its properties and the columns of the store. For example, you could map one store column to the font of a text cellrenderer, and another store column to the text property of the same cellrenderer. Each time the cellrenderer is used to render a particular cell, the mappings will be used to retrieve the values from the store and apply them to the properties of the renderer before it renders.
Here's an example of a mapping:
treeView.AppendColumn ("Title", renderer, "text", 0, "editable", 4);
This maps store column 0 to the renderer's text GTK property and maps store column 4 to the editable property. For GTK property names you can check the GTK docs. Note that the example above uses a convenience method that adds a column, adds a renderer to it and add an arbitrary number of mapping via params. To add mappings directly to a column, for example a column with multiple renderers, pack the renderers into the column then use TreeViewColumn.AddAttribute or TreeViewColumn.SetAttributes.
You can also set up a custom data function that will be used instead of mappings. This allows you to set the properties of the renderer directly, given a TreeIter and the store - so, if all the data you want to display is trivially derived from your real data objects, you could even have your store only contain a single column of these objects, and use data funcs for all the view columns.
Here's an example of a data func that does exactly what the mapping example above does:
treeColumn.SetCellDataFunc (renderer, delegate (TreeViewColumn col,
CellRenderer cell, TreeModel model, TreeIter iter)
{
var textCell = (CellRendererText) cell;
textCell.Text = (string) model.GetValue (iter, 0);
textCell.Editable = (bool) model.GetValue (iter, 4);
});
Obviously data functions are much more powerful because they enable you not only to use properties of more complex GTK objects, but also to implement more complex display logic - for example, lazily processing derived values only when the cell is actually rendered.