dooApp/FXForm2

SimpleListProperty table - How to implement pagination

Closed this issue · 8 comments

SimpleListProperty table - How to implement pagination, could you suggest logic.

To display the list property elements in several pages, you could define a custom paginated table view control and provide a custom factory for the fields that should use this control (see https://github.com/dooApp/FXForm2/wiki/Advanced-customization).

Does it suit your needs ?

Thanks for reply. Could you suggest where should I implement my anchor pane for pagination in the factory?

Should I create VBox and have tableview and anchorpane as its child and wrap vbox in FXFormNodeWrapper and return fxformnodewrapper containing vbox ?

public class MyTableViewFactory implements Callback<Void, FXFormNode> {

@Override
public FXFormNode call(Void aVoid) {
    final TableView tableView = new MyTableView();

    FXFormNodeWrapper x =new FXFormNodeWrapper(tableView, new TableViewProperty(tableView)) {
        @Override
        public void init(Element element) {
            Class wrappedType = element.getWrappedType();
            List<Field> fields = ReflectionUtils.listFields(wrappedType);
            for (Field field : fields) {
                TableColumn col = new TableColumn(field.getName());
                col.setCellValueFactory(new PropertyValueFactory(field.getName()));
                tableView.getColumns().add(col);
            }
        }
    };



    return x; 
}

}

public class MyTableView extends TableView {
public MyTableView() {

    addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            System.out.println("I was clicked" + getSelectionModel().selectedIndexProperty());

            Pane p = (Pane) (getParent().getParent().getParent().getParent().getParent());

            FXForm fxForm = new FXForm();
            fxForm.setResourceBundle(ResourceBundle.getBundle("MyLabel"));
            ReadOnlyObjectProperty selectedItemProperty = getSelectionModel().selectedItemProperty();

            fxForm.sourceProperty().bind(selectedItemProperty);

            ((BorderPane) p).setRight(fxForm);

            Controller.baseModel = (BaseModel)fxForm.getSource();

            new MyObjectPropertyObserver(Controller.baseModel);


            System.out.println("I was clicked");
        }
    });
}

}

Hi,

I have pushed an example of implementation of a very simple paginated tableview factory : PaginatedTableViewFactory

Try it on the field you need by annotating your field with

@FormFactory(PaginatedTableViewFactory.class)
private final ListProperty listField;

Thanks for example.

First page appears but when I go to second page , table view does not get refreshed and tableview shrinks with only header visible and pagination appears on top. Clicking on pagination picks correct items in predicate in logs.

May be I am doing some thing wrong , will try to debug and check.

I did not made a lot of tests on the implementation and provided it just as a starting point, so it might actually requires some debugging.

It looks like a layout issue of the TableView in the Pagination control. Maybe you can try to create a new instance of TableView for each page of the Pagination control and not reuse the same instance ?

Thanks for reply. Yes you are right problem is with the layout , data is present in table but it is visible only when I click on table itself.

image

when I tab out from create button , table appears. Will try to fix it and post the CRUD application code on git.
image

Hi,
Thanks for your help. I have uploaded the example on github. But still I am not able to manage the pagination.

https://github.com/amitjain3/JAVAFX_CRUD_DYNAMIC

Ignore my comments for now. I messed with my git repository. It got deleted from both github and also from my local eclipse work space.