3

SOAP サービス用の JavaFX クライアントを作成しています。私の fxml ページには、Product クラスのエンティティで構成される完全に編集可能な TableView を含める必要があります。私のテーブルは、2 つのテキスト列と Double 値で構成される 1 つの列で構成されています。セルに CheckBox アイテムを含む選択列を追加したいと考えています。Ensemble デモ アプリを使用して、CheckBoxes を使用するために Cell クラスを拡張しました。

public class CheckBoxCell<S, T> extends TableCell<S, T> {

private final CheckBox checkBox;
private ObservableValue<T> ov;

public CheckBoxCell() {
    this.checkBox = new CheckBox();
    this.checkBox.setAlignment(Pos.CENTER);
    setAlignment(Pos.CENTER);
    setGraphic(checkBox);
}

@Override
public void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);
    if (empty) {
        setText(null);
        setGraphic(null);
    } else {
        setGraphic(checkBox);
        if (ov instanceof BooleanProperty) {
            checkBox.selectedProperty().unbindBidirectional((BooleanProperty) ov);
        }
        ov = getTableColumn().getCellObservableValue(getIndex());
        if (ov instanceof BooleanProperty) {
            checkBox.selectedProperty().bindBidirectional((BooleanProperty) ov);
        }
    }
}

@Override
public void startEdit() {
    super.startEdit();
    if (isEmpty()) {
        return;
    }
    checkBox.setDisable(false);
    checkBox.requestFocus();
}

@Override
public void cancelEdit() {
    super.cancelEdit();
    checkBox.setDisable(true);
}
}

次に、fxml ビュー コントローラー クラスで、要求された TableColumn の cellFactory を設定します。

private Callback<TableColumn, TableCell> createCheckBoxCellFactory() {
    Callback<TableColumn, TableCell> cellFactory = new Callback<TableColumn, TableCell>  () {
        @Override
        public TableCell call(TableColumn p) {
            return new CheckBoxCell();
        }
    };
    return cellFactory;
}

...
products_table_remove.setCellFactory(createCheckBoxCellFactory());

私の質問は:

1) PropertyValueFactory を使用して、チェックされていないチェック ボックスをこの列に入力する方法

private final ObservableList <Boolean> productsToRemove= FXCollections.observableArrayList();

Boolean.FALSE 値で構成される場合、ビューが作成されます。(TableView は、Boolean プロパティを持たない Product クラスで構成されます (3 つの String と 1 つの Double プロパティのみ)) ?

2) EventHandler を使用して選択した行を含む Product オブジェクトにアクセスできますか:

private void setProductDescColumnCellHandler() {
    products_table_remove.setOnEditCommit(new EventHandler() {
        @Override
        public void handle(CellEditEvent t) {
        ...

Boolean フィールドを持つ Entites の例をたくさん見ました。私の場合、jax-ws で生成されたクラスに boolean フィールドを追加したくありません。

4

1 に答える 1

3

1) 事前定義されたクラスjavafx.scene.control.cell.CheckBoxTableCellは、ユーザーの代わりに使用できます。

2) 既存のインスタンスに情報を追加するには、データインスタンスごとに継承 + 委任をお勧めします。TableView のフィードに使用できるビューインスタンスをインスタンス化します。

class ProductV extends Product {

   ProductV( Product product ) {
      this.product = product;
   }

   final Product         product;
   final BooleanProperty delected = new SimpleBooleanProperty( false );
}
于 2012-09-26T04:20:44.150 に答える