public void setFddObjectModel(FddObjectModel fddObjectModel) {
    logger.entry();
    if (fddObjectModel != null) {
      fddObjectModel
          .getInteractionClasses()
          .values()
          .stream()
          .forEach(
              (value) -> {
                interactions.add(new InteractionState(value));
              });
      InteractionTableView.setItems(interactions);
      interactions.forEach(
          (interaction) -> {
            interaction
                .onProperty()
                .addListener(
                    (observable, oldValue, newValue) -> {
                      if (!newValue) {
                        cb.setSelected(false);
                      } else if (interactions.stream().allMatch(a -> a.isOn())) {
                        cb.setSelected(true);
                      }
                    });
          });
      InteractionTableColumn.setCellValueFactory(new PropertyValueFactory<>("interactionName"));
      CheckTableColumn.setCellValueFactory(
          new Callback<
              TableColumn.CellDataFeatures<InteractionState, Boolean>, ObservableValue<Boolean>>() {
            @Override
            public ObservableValue<Boolean> call(
                TableColumn.CellDataFeatures<InteractionState, Boolean> param) {
              return param.getValue().onProperty();
            }
          });

      CheckTableColumn.setCellFactory(CheckBoxTableCell.forTableColumn(CheckTableColumn));
      cb.setUserData(CheckTableColumn);
      cb.setOnAction(
          (ActionEvent event) -> {
            CheckBox cb1 = (CheckBox) event.getSource();
            TableColumn tc = (TableColumn) cb1.getUserData();
            InteractionTableView.getItems()
                .stream()
                .forEach(
                    (item) -> {
                      item.setOn(cb1.isSelected());
                    });
          });
      CheckTableColumn.setGraphic(cb);
    }
    logger.exit();
  }
예제 #2
0
  /**
   * Create the active column, which holds the activity state and also creates a callback to the
   * string property behind it.
   */
  private void setUpActiveColumn(TableView<FilterInput> tableView) {
    // Set up active column
    final TableColumn<FilterInput, Boolean> activeColumn = new TableColumn<>("Active");
    activeColumn.setMinWidth(50);
    activeColumn.setPrefWidth(50);
    tableView.getColumns().add(activeColumn);
    activeColumn.setSortable(false);

    activeColumn.setCellFactory(
        CheckBoxTableCell.forTableColumn(
            (Callback<Integer, ObservableValue<Boolean>>)
                param -> {
                  final FilterInput input = tableView.getItems().get(param);
                  input
                      .getActiveProperty()
                      .addListener(
                          l -> {
                            notifyUpdateCommand(input);
                          });
                  return input.getActiveProperty();
                }));
  }
예제 #3
0
  /**
   * Create the color column, which holds the color and also creates a callback to the string
   * property behind it.
   */
  private void setUpColorColumn(TableView<FilterInput> tableView) {
    final TableColumn<FilterInput, Color> colorColumn = new TableColumn<>("Color");
    colorColumn.setMinWidth(50);
    colorColumn.setPrefWidth(50);
    colorColumn.setSortable(false);
    tableView.getColumns().add(colorColumn);

    // Set the cell value factory for the color
    colorColumn.setCellValueFactory(p -> p.getValue().getColorProperty());

    // Set the cell factory for the color
    colorColumn.setCellFactory(
        param ->
            new TableCell<FilterInput, Color>() {

              final Rectangle rectangle = new Rectangle();

              @Override
              public void updateItem(Color item, boolean empty) {
                // Add the color to the row
                if (item != null) {
                  HBox hBox = new HBox();
                  hBox.getChildren().add(rectangle);
                  rectangle.setHeight(20);
                  rectangle.setWidth(30);
                  hBox.setAlignment(Pos.CENTER);

                  rectangle.setFill(item);

                  setGraphic(hBox);
                }

                // Remove the color if the row has been removed
                if (empty) {
                  setGraphic(null);
                }
              }
            });
  }