B4J Question Tableview nested column

Firpas

Active Member
Licensed User
Longtime User
Hi to everybody.

I've found this thread

https://www.b4x.com/android/forum/threads/tableview-nested-column-help.94138/#content

but i can't compile the code:

B4X:
B4J Versión: 6.30
Parseando código.    (0.16s)
Compilando código    (0.38s)
Compilado código de diseños    (0.02s)
Organizando librerías.    (0.00s)
Compilando el código Java generado.    Error
B4J line: 16
End Sub
javac 1.8.0_121
src\com\firpas\evalconvo.java:268: error: lambda expressions are not supported in -source 1.7
            tc -> {
               ^
  (use -source 8 or higher to enable lambda expressions)
1 error

Any idea??

Thanks in advance
 

Daestrum

Expert
Licensed User
Longtime User
As I posted when I added the code to that thread, you need to change some of the code where I use streams.

I compile in b4x using source & target of 10 so I have access to lambda's and streams etc.

You will need to revert the streams etc back to for type loops in order to compile the code using b4x without my modified javac.

Or an alternative is to compile the code in eclipse and use it as a library.
 
Last edited:
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
I'm sorry, but I do not understand what it means "compile in b4x using source & target of 10 so I have access to lambda's and streams etc"

Would you be so kind as to compile the code as a library and publish it?

Thanks
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
I have tried another way ...
I have designed my layout in Scene Builder and I have edited the FXML file adding the "children" columns but B4J only finds the main columns.
 

Attachments

  • Nested.zip
    1.8 KB · Views: 272
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I have recoded it for lower version java - see the comments in the code. It will be slower as it is not using streams now.
B4X:
#if java
import javafx.scene.control.*;
import java.util.stream.Stream;
import javafx.collections.FXCollections.*;
import javafx.collections.*;
import java.util.ArrayList;
import javafx.util.*;
import javafx.beans.property.StringProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
 static int ii = 0;
public static void correctCellValueFactoryParallel(TableView t) {
/*    t.getColumns().parallelStream().forEach(
            tc -> {
                ((TableColumn) tc).setCellValueFactory(
                        new TestCellValueFactory(((TableColumn) tc).getTableView().getVisibleLeafColumns().indexOf(tc)));
            });*/
 // above code for java 1.8+  
 for (Object tc : t.getColumns()){
  ((TableColumn)tc).setCellValueFactory(new TestCellValueFactory(((TableColumn) tc).getTableView().getVisibleLeafColumns().indexOf(tc)));
 }  
}
private static class TestCellValueFactory
        implements Callback<TableColumn.CellDataFeatures<Object[], Object>, ObservableValue<Object>> {
    private final int index;
    public TestCellValueFactory(int index) {
        this.index = index;
    }
    @Override
    public ObservableValue<Object> call(TableColumn.CellDataFeatures<Object[], Object> arg0) {
        return new ReadOnlyObjectWrapper(((Object[]) arg0.getValue())[this.index]);
    }
} 
public static void addLeafColumn(TableView t,Integer col,String... names){
    int i = t.getVisibleLeafColumns().indexOf((TableColumn) t.getColumns().get(col));
    TableColumn tc = (TableColumn) t.getColumns().get(col);
    ii = i < 0 ? 0 : i;
/*    Stream.of(names).forEach(name -> {
        TableColumn x = new TableColumn(name);
        x.setCellValueFactory(new TestCellValueFactory(ii++));
        tc.getColumns().add(x);
    });*/
 // above code for java 1.8+
 for (Object name : names){
        TableColumn x = new TableColumn((String)name);
        x.setCellValueFactory(new TestCellValueFactory(ii++));
        tc.getColumns().add(x);
 }
    correctCellValueFactoryParallel(t);
 }
 
Upvote 0

Firpas

Active Member
Licensed User
Longtime User
Hello again
I think I've detected a bug
The code works well by filling the tableview with text, but it produces strange effects with TextFields.
Take a look at the example project below.
 

Attachments

  • Nested.zip
    2.9 KB · Views: 254
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
If you add the leaf columns from left to right eg, col1 then col2 then col3 (you have 3 then 2 then 1) then it works correctly.
B4X:
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 0, Array As String("1-1", "1-2", "1-3", "1-4", "1-5")))
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 1, Array As String("2-1", "2-2", "2-3", "2-4", "2-5")))
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 2, Array As String("3-1", "3-2", "3-3", "3-4", "3-5")))
the above works as expected

B4X:
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 2, Array As String("3-1", "3-2", "3-3", "3-4", "3-5")))
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 1, Array As String("2-1", "2-2", "2-3", "2-4", "2-5")))
 asJO(Me).RunMethod("addLeafColumn",Array(TableView1, 0, Array As String("1-1", "1-2", "1-3", "1-4", "1-5")))
Exhibits the bad behaviour, probably as it is trying to re-order the cell factories multiple times.
 
Upvote 0
Top