Java 类javafx.beans.value.ObservableValueBase 实例源码

项目:TranslationHelper    文件:JFXProjectController.java   
private TableColumn<ResourceSet, Button> createActionColumn() {
    TableColumn<ResourceSet, Button> column = new TableColumn<>("");
    Button addNewButton = new Button("+");
    addNewButton.setOnAction(evt -> {
        resourceSetInput().ifPresent(project::associate);
        // FIXME crutch for actually using Properties in the model-classes
        table.setItems(FXCollections.observableList(project.getAssociatedResources()));
    });
    addNewButton.setMinWidth(40);
    column.setGraphic(addNewButton);
    column.setCellValueFactory(resourceSet -> new ObservableValueBase<Button>() {
        @Override
        public Button getValue() {
            Button removeButton = new Button("-");
            removeButton.setOnAction(evt -> {
                project.disassociate(resourceSet.getValue());
                table.setItems(FXCollections.observableList(project.getAssociatedResources()));
            });
            removeButton.setMinWidth(40);
            return removeButton;
        }
    });
    column.setCellFactory(col -> new TableCell<ResourceSet, Button>() {
        @Override
        public void updateItem(Button item, boolean empty) {
            super.updateItem(item, empty);
            setGraphic(item);
        }
    });
    column.setMaxWidth(40);
    column.setMinWidth(40);
    return column;
}
项目:TranslationHelper    文件:JFXProjectController.java   
private TableColumn<ResourceSet, Pane> createTableColumn() {
    TableColumn<ResourceSet, Pane> column = new TableColumn<>("Resource Sets");
    column.setCellValueFactory(resourceSet -> new ObservableValueBase<Pane>() {
        @Override
        public Pane getValue() {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("/ResourceSetPane.fxml"));
            loader.setController(new JFXResourceSetController(resourceSet.getValue(), resourceSetRequests));
            try {
                final Pane resourceSetPane = loader.load();
                resourceSetPane.setOnMouseClicked(evt -> {
                    if (evt.getClickCount() == 2) {
                        resourceSetRequests.forEach(l -> l.accept(resourceSet.getValue()));
                    }
                });
                return resourceSetPane;
            } catch (IOException e) {
                e.printStackTrace(err);
                return null;
            }
        }
    });
    column.setCellFactory(col -> new TableCell<ResourceSet, Pane>() {
        @Override
        protected void updateItem(Pane item, boolean empty) {
            super.updateItem(item, empty);
            setGraphic(item);
        }
    });
    return column;
}
项目:TranslationHelper    文件:JFXTranslationOverviewController.java   
private static <S, T> TableColumn<S, T> createTableColumn(final Callback<TableColumn<S, T>, TableCell<S, T>> renderer,
                                                          final Function<S, T> valueFactory) {
    TableColumn<S, T> result = new TableColumn<>("");
    result.setCellValueFactory(data -> new ObservableValueBase<T>() {
        @Override
        public T getValue() {
            return valueFactory.apply(data.getValue());
        }
    });
    result.setCellFactory(renderer);
    return result;
}