JavaFX error: incompatible types - Object cannot be converted to Node - javafx-8

I have defined 3 labels in a FXML file within a grid pane. I am trying to read the following XML file and display the labels present in the file in a grid pane. The numerical values in the XML file denotes the row & column position.
<data>
<lbl1>0,0</lbl1>
<lbl2>0,1</lbl2>
<lbl3>0,2</lbl3>
</data>
I have added all the elements to the HashMap and then retrieve it to be displayed. Firstly, I added all the three labels one by one as follows:
hm.put("lbl1", eElement.getElementsByTagName("lbl1").item(0).getTextContent());
hm.put("lbl2", eElement.getElementsByTagName("lbl2").item(0).getTextContent());
hm.put("lbl3", eElement.getElementsByTagName("lbl3").item(0).getTextContent());
Then I display them as follows:
grid.add(lbl1, Integer.parseInt(hm.get("lbl1").toString().split(",")[0]),Integer.parseInt(hm.get("lbl1").toString().split(",")[1]));
grid.add(lbl2, Integer.parseInt(hm.get("lbl2").toString().split(",")[0]),Integer.parseInt(hm.get("lbl2").toString().split(",")[1]));
grid.add(lbl3, Integer.parseInt(hm.get("lbl3").toString().split(",")[0]),Integer.parseInt(hm.get("lbl3").toString().split(",")[1]));
The above code works well without any issues and I can see the labels on the grid.
Now, instead of adding the labels one by one, I added all of them in a single statement through a 'for' loop as shown below:
if (!eElement.getTagName().toString().equals("data"))
hm.put(eElement.getTagName(), eElement.getTextContent());
If I try to display the label, for example:
grid.add(hm.get("lbl1"),0,0);
I get an error:incompatible types - Object cannot be converted to Node.
If I try to typecast:
grid.add((javafx.scene.Node) hm.get("lbl1"),0,0);
I get an error:java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.Node
If I print the hashmap entries, the following output is shown:
lbl1=0,0, lbl2=0,1, lbl3=0,2
How to fix this error? Is there any other way in which I can add all the elements in a single statement and then display them?

in your imports add:-
import javafx.scene.control.Label;
I suspect that the current import is from awt.

From your sample code, I guess that hm is an instance of Map<String, String>
So, when you call hm.get("lbl1") , you get a String.
You're trying to add this String to a GridPane, but the add() method is expecting a javafx.scene.Node. That's why you get a an error "incompatible types".
Instead, you should add your instances of javafx.scene.control.Label (lbl1, lbl2, lbl3)

Related

Creating an array for multiple instances targeting IDs with non static members

I am trying to automate text boxes to fill with a certain value, however the text boxes names are not static so they will always change. I am looking to find a way to always populate them even though they do not have a static name and how to find the second, third, fourth etc instance of the boxes and be able to also fill them without overwriting the previous text boxes
i have tried using the _collect function in sahi pro but could not find how to target the class correctly
I expect to be able to populate any textbox using the same class name without overwriting the first instance of this class.
I am using Sahi pro.
The sahi documentation on _collect seems to be you exactly what you are looking for
// Collect all textboxes matching any identifier, in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxes = _collect("_textbox", "/.*/", _in(_table("listing"));
// Iterate and set values on all textboxes
for (var $i=0; $i<$textboxes.length; $i++) {
_setValue($textboxes[$i], "value");
}
If this does not solve your problem, please provide an example of the html and of your _collect code

Put File Mask on tFileList Component dynamically

I was wondering if you let me know how I can set file mask for tFilelist component in Talend that it recognize date automatically and it will download only data for desired date?
I have tried some approach and I faced with some errors like "the method add (string) in the type list <String> is not applicable for the arguments (Date)"
There are two ways of doing it.
Create context variable and use this variable in file mask.
Directly use TalendDate.getDate() or any other date function in file mask.
See both of them in component
1st approach,
Create context variable named with dateFilter as string type.
Assign value to context.dateFilter=TalendDate.getDate("yyyy-MM-dd");
Suppose you have file name as "ABC_2015-06-19.txt" then
In tFileList file mask use this variable as follows.
"ABC_"+context.dateFilter+".*"
2nd approach
In tFileList file mask use date function as follows.
"ABC_"+TalendDate.getDate("yyyy-MM-dd")+".*"
these are the two best way, you can make changes in file mask per your file names.

Print List<String> each element in new field

I am fresh in JasperReports and I'm having problems solving an issue.
I have a report and a field $F{therapies} that is type of List<String>. If I print this field, the whole List is printed as a single String. Is it possible to print each element of the list in a new line or better - as a new Text Field.
If I try, for instance, $F{therapies}.get(1), it prints correctly the element at position 1. But since the size of List isn't constant I can't solve it that way.
I hope you understand what I want to achieve . Somehow printing List<String> per element.
I solved my problem using subreport and passing List as a datasource.
Here is a link: Passing the List of primitive type objects as datasource for subreport

iReport sum of two measures

I'm having problem with JasperReports report by getting sum of two fields.
I have created so far variables that holds fields "TareWeight" variable that is casting values from double to float
new Float($F{EquipmentTareWeightKg})
"CargoWt" variable that is casting from string to float, etc...
Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04})
So now I have two variables which I can manipulate with.
The problem starts when I wish to do a "recap" using crosstab. I have setup two groups that is done with wizard, and added another in crosstab. (please refer to the printscreen below)
And now, I have created under measures SumOf Tare that is using variable TareWt, and SumOfCargoWt that is using variable CargoWt.
I have tried to create another Measure SumOfGrossWt that would do a sum of variables TareWt + CargoWt but I have got some nonsense values.
I have tried to do another approach by creating variable GrossWt that would basically do exact the same thing as previous attempt
$V{Tare}+$V{CargoWt}
or use an variable: GrossWt
$V{Tare}+$V{CargoWt} or new Float($F{EquipmentTareWeightKg})+(Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04}))
None of these actually worked: (Sum should be done by "Sum Of Tare"+ "Sum of CargoWt" = "Sum of GrossWt") plese refer to the second picture.
Here is a complete jrxml code/file:
jrxml file
save it as *.jrxml
Can please someone help me find a solution? how can I sum those two measure fields and get correct values?
Since CargoWt field had some null values in database, addition float value with null is equal to null, so the only value which was displayed on report are the one that had values for CargoWt, all others with null value were "ignored".

JasperReports customize series labels based on a value other than the Category value

I have a JasperReport with a line chart that I need to display labels on, but I want them to display conditionally for each data point. I've created the customizer class to actually display the value, but I want to use a different field than the value field to decide if it should display or not.
Basically in my DataSet I have 3 fields:
Date: (Category Axis)
Value: (Value Axis)
PrintValue: Boolean field
I want to print the Value in the label only when PrintValue=true
One solution would be to override one of the methods implemented by JRDefaultScriptlet in a scriptlet class, then set the value of "PrintValue" in any manner you desire. Then in your chart dataset you should be able to reference $V{PRINTVALUE} as an operand.
I'm going to assume your using iReport for your report design.
Open your report in iReport and click the report name (Top most node in the report Inspector)
Set the Scriplet class to your package name and class, e.g., org.company.scriptlets.MyChartClass
Declare your report variable in iReport. In this case "PRINTVALUE" would be the variable name.
Create a java class that overrides a scriplet method, like beforeDetailEval, e.g.,:
#Override
public void beforeDetailEval() throws JRScriptletException {
super.beforeDetailEval();
...
this.setVariableValue("PRINTVALUE", true);
}
Since you want to display the category label conditionally for each tick mark, you'll probably need to use a Map of key/val pairs. key would be category label, value would be true/false for "PRINTVALUE". Note I did NOT illustrate this in the sample code above but its entirely possible. Just declare your report variable as a Map, e.g., HashMap<String, Boolean> hm.
You'll need to add your new scriplet class to the Classpath in iReport.
Hope this helps or at least gets you started.