Example usage for javafx.scene.control TableColumn TableColumn

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

Introduction

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

Prototype

public TableColumn(String text) 

Source Link

Document

Creates a TableColumn with the text set to the provided string, with default cell factory, comparator, and onEditCommit implementation.

Usage

From source file:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.java

private TableColumn<NameCluster, String> createColumnFromPrecalc(String colName,
        Table<NameCluster, String, Set<String>> precalc) {
    TableColumn<NameCluster, String> column = new TableColumn<>(colName);
    column.cellValueFactoryProperty().set((TableColumn.CellDataFeatures<NameCluster, String> cdf) -> {
        NameCluster nc = cdf.getValue();

        // There might be columns found in some dataset but not in others
        // so we detect those cases here and put in "NA"s instead.
        String output = "NA";
        if (precalc.contains(nc, colName))
            output = precalc.get(nc, colName).stream().collect(Collectors.joining("; "));

        return new ReadOnlyStringWrapper(output);
    });//from w  w w.j  a va 2s. co m
    column.setPrefWidth(100.0);
    column.setEditable(false);
    return column;
}

From source file:UI.MainStageController.java

/**
 * shows the correlation table in the analysis view
 *//*  www. j  a v  a2s.  c om*/
@FXML
private void displayCorrelationTable() {
    //Delete whatever's been in the table before
    TableView<String[]> analysisTable = new TableView<>();

    //We want to display correlations and p-Values of every node combination
    double[][] correlationMatrix = AnalysisData.getCorrelationMatrix().getData();
    double[][] pValueMatrix = AnalysisData.getPValueMatrix().getData();
    LinkedList<TaxonNode> taxonList = SampleComparison.getUnifiedTaxonList(LoadedData.getSamplesToAnalyze(),
            AnalysisData.getLevelOfAnalysis());

    //Table will consist of strings
    String[][] tableValues = new String[correlationMatrix.length][correlationMatrix[0].length + 1];

    //Add the values as formatted strings
    for (int i = 0; i < tableValues.length; i++) {
        tableValues[i][0] = taxonList.get(i).getName();
        for (int j = 1; j < tableValues[0].length; j++) {
            tableValues[i][j] = String.format("%.3f", correlationMatrix[i][j - 1]).replace(",", ".") + "\n("
                    + String.format("%.2f", pValueMatrix[i][j - 1]).replace(",", ".") + ")";
        }
    }

    for (int i = 0; i < tableValues[0].length; i++) {
        String columnTitle;
        if (i > 0) {
            columnTitle = taxonList.get(i - 1).getName();
        } else {
            columnTitle = "";
        }
        TableColumn<String[], String> column = new TableColumn<>(columnTitle);
        final int columnIndex = i;
        column.setCellValueFactory(cellData -> {
            String[] row = cellData.getValue();
            return new SimpleStringProperty(row[columnIndex]);
        });
        analysisTable.getColumns().add(column);

        //First column contains taxon names and should be italic
        if (i == 0)
            column.setStyle("-fx-font-style:italic;");
    }

    for (int i = 0; i < tableValues.length; i++) {
        analysisTable.getItems().add(tableValues[i]);
    }

    //Display table on a new stage
    Stage tableStage = new Stage();
    tableStage.setTitle("Correlation Table");
    BorderPane tablePane = new BorderPane();
    Button exportCorrelationsButton = new Button("Save correlation table to CSV");
    Button exportPValuesButton = new Button("Save p-value table to CSV");
    exportCorrelationsButton.setOnAction(e -> exportTableToCSV(tableValues, false));
    exportPValuesButton.setOnAction(e -> exportTableToCSV(tableValues, true));
    HBox exportBox = new HBox(exportCorrelationsButton, exportPValuesButton);
    exportBox.setPadding(new Insets(10));
    exportBox.setSpacing(10);
    tablePane.setTop(exportBox);
    tablePane.setCenter(analysisTable);
    Scene tableScene = new Scene(tablePane);
    tableStage.setScene(tableScene);
    tableStage.show();
}

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

/**
 * Create and return table column//from  w  w w .j a  v a  2 s.  c om
 *
 * @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:com.exalttech.trex.ui.views.PacketTableView.java

/**
 * Create and return static width table column
 *
 * @param title/*from   w  ww .j a v a  2 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.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();/*www.ja va 2 s.c  om*/

    // 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:ninja.javafx.smartcsv.fx.SmartCSVController.java

/**
 * Adds a column with the given name to the tableview
 * @param header name of the column header
 * @param tableView the tableview/*w  w w .j a  v a 2  s.c  o  m*/
 */
private void addColumn(final String header, TableView tableView) {
    TableColumn column = new TableColumn(header);
    column.setCellValueFactory(new ObservableMapValueFactory(header));
    column.setCellFactory(cellFactory);
    column.setEditable(true);
    column.setSortable(false);

    ContextMenu contextMenu = contextMenuForColumn(header);
    column.setContextMenu(contextMenu);

    column.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<CSVRow, CSVValue>>() {
        @Override
        public void handle(TableColumn.CellEditEvent<CSVRow, CSVValue> event) {
            event.getTableView().getItems().get(event.getTablePosition().getRow()).getColumns().get(header)
                    .setValue(event.getNewValue());
            runLater(() -> {
                currentCsvFile.setFileChanged(true);
            });
        }
    });

    tableView.getColumns().add(column);
}

From source file:jduagui.Controller.java

private TableColumn extNameColumn() {
    TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Extension");
    col.setCellValueFactory(//from   w  w w.j av  a 2s  .  c o m
            (TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> new ReadOnlyStringWrapper(
                    "." + p.getValue().getKey()));

    return col;
}

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()));
    });/*  www . j  a  v a  2s  .  co m*/
    col.setComparator(new sizeComparator());
    return col;
}

From source file:jduagui.Controller.java

private TableColumn extCountColumn() {
    TableColumn<Map.Entry<String, Extension>, String> col = new TableColumn<>("Items");
    col.setCellValueFactory((TableColumn.CellDataFeatures<Map.Entry<String, Extension>, String> p) -> {
        return new ReadOnlyStringWrapper("" + p.getValue().getValue().getCount());
    });/* w ww.java2  s.c o m*/
    col.setComparator(new longComparator());
    return col;
}

From source file:condorclient.MainFXMLController.java

private void configureTable() {
    //selected.setCellValueFactory(new PropertyValueFactory<>("selected"))
    //s/*from   w w w  . j  a  v a 2  s .  c o  m*/

    table.getColumns().addAll(new TableColumn("??"), new TableColumn("ID"),
            new TableColumn("??"), new TableColumn(""),
            new TableColumn(""), new TableColumn(""), new TableColumn("?"),
            new TableColumn(""), new TableColumn("?"));

    //private 
    ObservableList<DisplayedClassAdStub> data = FXCollections.observableArrayList();

    ObservableList<TableColumn> observableList = table.getColumns();
    observableList.get(0).setCellValueFactory(new PropertyValueFactory(ColClusterNameMapKey));
    observableList.get(1).setCellValueFactory(new PropertyValueFactory(ColClusterIdMapKey));
    observableList.get(2).setCellValueFactory(new PropertyValueFactory(ColInfoFileNameMapKey));
    observableList.get(3).setCellValueFactory(new PropertyValueFactory(ColExpFileNameMapKey));
    observableList.get(4).setCellValueFactory(new PropertyValueFactory(ColTotalSampleNumMapKey));
    observableList.get(5).setCellValueFactory(new PropertyValueFactory(ColSubmittedTimeMapKey));
    observableList.get(6).setCellValueFactory(new PropertyValueFactory(ColRunTimeMapKey));
    observableList.get(7).setCellValueFactory(new PropertyValueFactory(ColProcessStatusMapKey));
    observableList.get(7).setCellFactory(ProgressBarTableCell.forTableColumn());
    observableList.get(8).setCellValueFactory(new PropertyValueFactory(ColJobStatusMapKey));

    table.setItems(tableContent);
    tablePane.getChildren().add(table);
    // table.setSelectionModel(null);
    //sampleTab
    sampleTab.getColumns().addAll(new TableColumn("?"), new TableColumn(""),
            new TableColumn("??"), new TableColumn("?"), new TableColumn(""),
            new TableColumn("?"), new TableColumn(""), new TableColumn("?"));
    ((TableColumn) sampleTab.getColumns().get(6)).setVisible(false);
    ((TableColumn) sampleTab.getColumns().get(2)).setPrefWidth(150);
    ((TableColumn) sampleTab.getColumns().get(5)).setPrefWidth(50);
    ((TableColumn) sampleTab.getColumns().get(7)).setPrefWidth(150);
    //private 
    ObservableList<DisplayedClassAdStub> sampleData = FXCollections.observableArrayList();

    ObservableList<TableColumn> sampleList = sampleTab.getColumns();
    sampleList.get(0).setCellValueFactory(new PropertyValueFactory(ColSampleIdMapKey));
    sampleList.get(1).setCellValueFactory(new PropertyValueFactory(ColEachRunMapKey));
    sampleList.get(2).setCellValueFactory(new PropertyValueFactory(ColSampleSubmittedTimeMapKey));
    sampleList.get(3).setCellValueFactory(new PropertyValueFactory(ColSampleRunTimeMapKey));
    sampleList.get(4).setCellValueFactory(new PropertyValueFactory(ColSampleProcessStatusMapKey));
    sampleList.get(4).setCellFactory(ProgressBarTableCell.forTableColumn());
    sampleList.get(5).setCellValueFactory(new PropertyValueFactory(ColSampleJobStatusMapKey));
    sampleList.get(6).setCellValueFactory(new PropertyValueFactory(ColCpuIdMapKey));
    sampleList.get(7).setCellValueFactory(new PropertyValueFactory(ColSlotIdMapKey));

    sampleTab.setItems(sampleContent);
    sampleBox.getChildren().add(sampleTab);

    //end sampleTab
    // ColConnectInfoMapKey  ColIpMapKey ColMachineIdMapKey ColMemMapKey ColDiskMapKey ColSlotNumMapKey
    //ColJobNameMapKey  ColJobCpuMapKey ColJobMemMapKey
    colConnectInfo.setCellValueFactory(new PropertyValueFactory<>(ColConnectInfoMapKey));
    colIp.setCellValueFactory(new PropertyValueFactory<>(ColIpMapKey));
    colMachineId.setCellValueFactory(new PropertyValueFactory<>(ColMachineIdMapKey));
    colMem.setCellValueFactory(new PropertyValueFactory<>(ColMemMapKey));
    colSlotNum.setCellValueFactory(new PropertyValueFactory<>(ColSlotNumMapKey));
    colDisk.setCellValueFactory(new PropertyValueFactory<>(ColDiskMapKey));
    colCpu.setCellValueFactory(new PropertyValueFactory<>(ColCpuMapKey));
    resourcesTab.setItems(resourcesContent);
    //resourcesTab.setSelectionModel(null);

    colJobName.setCellValueFactory(new PropertyValueFactory<>(ColJobNameMapKey));
    colJobCpu.setCellValueFactory(new PropertyValueFactory<>(ColJobCpuMapKey));
    colJobMem.setCellValueFactory(new PropertyValueFactory<>(ColJobMemMapKey));
    job_resourcesTab.setItems(jobContent);
    job_resourcesTab.setSelectionModel(null);

}