Example usage for javafx.scene.control TableColumn setCellValueFactory

List of usage examples for javafx.scene.control TableColumn setCellValueFactory

Introduction

In this page you can find the example usage for javafx.scene.control TableColumn setCellValueFactory.

Prototype

public final void setCellValueFactory(Callback<CellDataFeatures<S, T>, ObservableValue<T>> value) 

Source Link

Usage

From source file:jduagui.Controller.java

private TableColumn extNameColumn() {
    TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Extension");
    col.setCellValueFactory(
            (TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> new ReadOnlyStringWrapper(
                    "." + p.getValue().getKey()));

    return col;/*from  w w w . j  a  va 2  s . c  om*/
}

From source file:jduagui.Controller.java

private TableColumn extSizeColumn() {
    TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Size Total");
    col.setCellValueFactory((TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> {
        return new ReadOnlyStringWrapper(getByteSize(p.getValue().getValue().getSize()));
    });//w  w w  .j a  v a2 s. c  om
    col.setComparator(new sizeComparator());
    return col;
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Create and return static width table column
 *
 * @param title//from   w  w w  . j  av a2 s . co  m
 * @param propertyName
 * @param width
 * @param hasCheckbox
 * @return
 */
private TableColumn createStaticTableColumn(String title, String propertyName, double width,
        boolean hasCheckbox) {
    TableColumn col = new TableColumn(title);
    col.setPrefWidth(width);
    col.setResizable(false);
    col.setEditable(false);
    col.setSortable(false);
    col.setCellValueFactory(new PropertyValueFactory<>(propertyName));
    if (hasCheckbox) {
        col.setEditable(true);
        col.setCellFactory(new CheckBoxTableViewCell(this));
    }
    return col;
}

From source file:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Create and return table column//www  . ja v  a2s.co  m
 *
 * @param title
 * @param propertyName
 * @param width
 * @return
 */
private TableColumn createTableColumn(String title, String propertyName, double width) {
    TableColumn col = new TableColumn(title);
    col.prefWidthProperty().bind((streamPacketTableView.widthProperty().subtract(86)).multiply(width));
    col.setResizable(false);
    col.setSortable(false);
    col.setEditable(false);
    col.setCellValueFactory(new PropertyValueFactory<>(propertyName));
    return col;
}

From source file:Main.java

@SuppressWarnings("unchecked")
private void initializeBoundsTableView() {
    boundsTableView.setPrefSize(200, 100);
    boundsTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    boundsTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    TableColumn<BoundsRecord, String> boundsTypeCol = new TableColumn<>("Bounds Type");
    boundsTypeCol.setCellValueFactory(new PropertyValueFactory<>("boundsType"));

    TableColumn<BoundsRecord, Double> xCol = new TableColumn<>("MinX");
    xCol.setCellValueFactory(new PropertyValueFactory<>("x"));

    TableColumn<BoundsRecord, Double> yCol = new TableColumn<>("MinY");
    yCol.setCellValueFactory(new PropertyValueFactory<>("y"));

    TableColumn<BoundsRecord, Double> wCol = new TableColumn<>("Width");
    wCol.setCellValueFactory(new PropertyValueFactory<>("w"));

    TableColumn<BoundsRecord, Double> hCol = new TableColumn<>("Height");
    hCol.setCellValueFactory(new PropertyValueFactory<>("h"));

    boundsTableView.getColumns().setAll(boundsTypeCol, xCol, yCol, wCol, hCol);
}

From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java

private AdditionalData<String, DatasetRow> createDataAdditionalData() {
    Map<String, List<DatasetRow>> map = new HashMap<>();
    map.put("All data (" + dataset.getRowCount() + " rows)", new ArrayList<DatasetRow>(dataset.rowsProperty()));

    List<TableColumn<DatasetRow, String>> cols = new LinkedList<>();
    for (DatasetColumn col : dataset.getColumns()) {
        TableColumn<DatasetRow, String> column = new TableColumn<>(col.getName());
        column.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().get(col)));
        cols.add(column);/*from   w w  w  .jav  a 2s .c  o m*/
    }

    return new AdditionalData("Data", Arrays.asList("All data (" + dataset.getRowCount() + " rows)"), map,
            cols);
}

From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java

private AdditionalData<String, Map.Entry<String, String>> createPropertiesAdditionalData() {
    List<Map.Entry<String, String>> datasetProperties = new ArrayList<>(dataset.getProperties().entrySet());

    Map<String, List<Map.Entry<String, String>>> map = new HashMap<>();
    map.put("Dataset (" + datasetProperties.size() + ")", datasetProperties);

    List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>();

    TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Key");
    colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey()));
    cols.add(colKey);// w w  w  .jav  a 2s. co m

    TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value");
    colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue()));
    cols.add(colValue);

    return new AdditionalData("Properties", Arrays.asList("Dataset (" + datasetProperties.size() + ")"), map,
            cols);
}

From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java

private void fillTableViewWithDatasetRows(TableView<DatasetRow> tableView) {
    // We need to precalculate.
    ObservableList<DatasetRow> rows = dataset.rowsProperty();

    // Setup table.
    tableView.editableProperty().set(false);

    ObservableList<TableColumn<DatasetRow, ?>> cols = tableView.getColumns();
    cols.clear();/*from w ww.j  a v  a  2 s.co m*/

    // Set up columns.
    TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name");
    colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
        DatasetRow row = features.getValue();
        Set<Name> names = dataset.getNamesInRow(row);

        if (names.isEmpty()) {
            return new ReadOnlyStringWrapper("(None)");
        } else {
            return new ReadOnlyStringWrapper(
                    names.stream().map(n -> n.getFullName()).collect(Collectors.joining("; ")));
        }
    });
    colRowName.setPrefWidth(100.0);
    cols.add(colRowName);

    // Create a column for every column here.
    dataset.getColumns().forEach((DatasetColumn col) -> {
        String colName = col.getName();
        TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName);
        colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
            DatasetRow row = features.getValue();
            String val = row.get(colName);

            return new ReadOnlyStringWrapper(val == null ? "" : val);
        });
        colColumn.setPrefWidth(100.0);
        cols.add(colColumn);
    });

    // Set table items.
    tableView.itemsProperty().set(rows);

    // What if it's empty?
    tableView.setPlaceholder(new Label("No data contained in this dataset."));
}

From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java

private AdditionalData<Name, Map.Entry<String, String>> createDataByNameAdditionalData() {
    // Which names area we interested in?
    List<Change> selectedChanges = changesTableView.getItems();

    List<Name> names = selectedChanges.stream().flatMap(ch -> {
        Set<Name> allNames = ch.getAllNames();
        List<Name> binomials = allNames.stream().flatMap(n -> n.asBinomial()).collect(Collectors.toList());
        List<Name> genus = allNames.stream().flatMap(n -> n.asGenus()).collect(Collectors.toList());

        allNames.addAll(binomials);/*from   www. j  av a  2  s .  c  o  m*/
        allNames.addAll(genus);

        return allNames.stream();
    }).distinct().sorted().collect(Collectors.toList());

    Project proj = datasetView.getProjectView().getProject();

    Map<Name, List<Map.Entry<String, String>>> map = new HashMap<>();
    for (Name n : names) {
        Map<DatasetColumn, Set<String>> dataForName = proj.getDataForName(n);
        Map<String, String> mapForName = dataForName.entrySet().stream()
                .collect(Collectors.toMap(
                        (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getKey().toString(),
                        (Map.Entry<DatasetColumn, Set<String>> entry) -> entry.getValue().toString()));
        map.put(n, new ArrayList<>(mapForName.entrySet()));
    }

    List<TableColumn<Map.Entry<String, String>, String>> cols = new ArrayList<>();

    TableColumn<Map.Entry<String, String>, String> colKey = new TableColumn<>("Key");
    colKey.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getKey()));
    cols.add(colKey);

    TableColumn<Map.Entry<String, String>, String> colValue = new TableColumn<>("Value");
    colValue.setCellValueFactory(cdf -> new ReadOnlyStringWrapper(cdf.getValue().getValue()));
    cols.add(colValue);

    return new AdditionalData<Name, Map.Entry<String, String>>("Data by name", names, map, cols,
            changes -> changes.stream().flatMap(ch -> ch.getAllNames().stream()).collect(Collectors.toList()));
}

From source file:com.ggvaidya.scinames.model.Dataset.java

/** 
 * Set up a TableView to contain the data contained in this dataset.
 * /*from   w  w w. j a va 2  s. c o  m*/
 * @param tv The TableView to populate.
 */
public void displayInTableView(TableView<DatasetRow> tv) {
    // Setup table.
    tv.setEditable(false);
    //controller.setTableColumnResizeProperty(TableView.CONSTRAINED_RESIZE_POLICY);
    ObservableList<TableColumn<DatasetRow, ?>> cols = tv.getColumns();
    cols.clear();
    // We need to precalculate.
    ObservableList<DatasetRow> rows = this.rowsProperty();
    // Set up columns.
    TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name");
    colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
        DatasetRow row = features.getValue();
        Set<Name> names = getNamesInRow(row);
        if (names.isEmpty()) {
            return new ReadOnlyStringWrapper("(None)");
        } else {
            return new ReadOnlyStringWrapper(
                    names.stream().map(name -> name.getFullName()).collect(Collectors.joining("; ")));
        }
    });
    colRowName.setPrefWidth(100.0);
    cols.add(colRowName);
    // Create a column for every column here.
    this.getColumns().forEach((DatasetColumn col) -> {
        String colName = col.getName();
        TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName);
        colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
            DatasetRow row = features.getValue();
            String val = row.get(colName);
            return new ReadOnlyStringWrapper(val == null ? "" : val);
        });
        colColumn.setPrefWidth(100.0);
        cols.add(colColumn);
    });

    // Set table items.
    // tv.getItems().clear();
    tv.setItems(rows);
}