0

I have JFXTreeTableView which consist of 5 columnsx In that first 2 columns have Delete & Edit Buttons for each cell. After populating table

  • I want first columns should disable on save Button click.
  • If above case is not possible then delete Buttons inside first column's cells should be disabled on Save button click.

I did like this but dont know how to disable column or buttons inside cells.

Controller Class

public class FinanceActionsController implements Initializable {
@FXML
private JFXTreeTableView<InvoiceItems> tblInvoiceItemsView;
private JFXButton btnSave;
@FXML
private HBox hbBottonBtnBar;
ObservableList<InvoiceItems> invoiceItems = FXCollections.observableArrayList();

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    tableStructure();

    btnSave.setOnAction((ActionEvent event) -> {
        if (invoiceItems.isEmpty()) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setHeaderText("Please add Atleast one Invoice Item");
            alert.showAndWait();
        } else {
            onClickBtnSaveInvoice();
            disableAndAddControlsOnSave();
            //tblInvoiceItemsView.setDisable(true);
        }
    });     
}

private void tableStructure() {
    JFXTreeTableColumn<InvoiceItems, Boolean> delItem = new JFXTreeTableColumn<>("Delete");
    JFXTreeTableColumn<InvoiceItems, String> editItem = new JFXTreeTableColumn<>("Edit");
    JFXTreeTableColumn<InvoiceItems, String> billItem = new JFXTreeTableColumn<>("Billable Head");
    delItem.setCellValueFactory((TreeTableColumn.CellDataFeatures<InvoiceItems, Boolean> param) -> param.getValue().getValue().getBtnFlag());
    delItem.setCellFactory(new Callback<TreeTableColumn<InvoiceItems, Boolean>, TreeTableCell<InvoiceItems, Boolean>>() {
        @Override
        public TreeTableCell<InvoiceItems, Boolean> call(TreeTableColumn<InvoiceItems, Boolean> param) {
            final TreeTableCell<InvoiceItems, Boolean> cell = new TreeTableCell<InvoiceItems, Boolean>() {

                MaterialIconView del = new MaterialIconView(MaterialIcon.DELETE_FOREVER, "1.5em");
                final JFXButton btnDel = new JFXButton("", del);

                @Override
                public void updateItem(Boolean item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setGraphic(null);
                        setText(null);
                    } else {
                 btnDel.disableProperty().bind(txtN.disableProperty());
                        del.setFill(Color.RED);
                        btnDel.setButtonType(JFXButton.ButtonType.RAISED);
                        btnDel.setOnAction(event -> {
                        });
                        setGraphic(btnDel);
                        setText(null);
                    }
                }
            };
            return cell;
        }
    });

    billItem.setCellValueFactory((TreeTableColumn.CellDataFeatures<InvoiceItems, String> param) -> param.getValue().getValue().getBillItemDesc());

    final TreeItem<InvoiceItems> root = new RecursiveTreeItem<>(invoiceItems, RecursiveTreeObject::getChildren);
    tblInvoiceItemsView.getColumns().setAll(delItem, editItem, billItem);
    tblInvoiceItemsView.setRoot(root);
    tblInvoiceItemsView.setShowRoot(false);
}

Class InvoiceItems -

class InvoiceItems extends RecursiveTreeObject<InvoiceItems> {

    StringProperty billItemDesc;
    BooleanProperty btnFlag;

    public InvoiceItems(String billItemDesc) {
        this.billItemDesc = new SimpleStringProperty(billItemDesc);
    }

    public StringProperty getBillItemDesc() {
        return billItemDesc;
    }

    public BooleanProperty getBtnFlag() {
        return btnFlag;
    }

    public void setBtnFlag(Boolean btnFlag) {
        this.btnFlag = new SimpleBooleanProperty(btnFlag);
    }
}

I have tried to pass InvoiceItems setBtnFlag as True in Observable list to work in setCellFactory's updateItem method but not working. Please help any help will be appreciable, Thank You.

  • You can create a `BooleanProperty` which indicates if the buttons should be enabled/disabled; when you create the buttons in the `cell`, just bind the `disableProperty()` to that property. Then set the property when the button is pressed. – James_D May 10 '20 at 17:36
  • How, It's not working @James_D – Santosh Bhoir May 10 '20 at 18:34
  • Update your question showing how you tried to do that. What actually happens, other than "it's not working"? – James_D May 10 '20 at 18:47

0 Answers0