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:com.bdb.weather.display.day.DayRainPane.java

/**
 * Constructor./*w  w w  . j  a v a 2s. co  m*/
 */
public DayRainPane() {
    setPrefSize(400, 300);
    chart = ChartFactory.createBarChart("Water Cycle", "Hour", "", null, PlotOrientation.VERTICAL, true, true,
            false);

    chartViewer = new ChartViewer(chart);

    rainPlot = (CategoryPlot) chart.getPlot();
    rainPlot.setNoDataMessage("There is no data for the specified day");

    BarRenderer renderer = (BarRenderer) rainPlot.getRenderer();
    renderer.setBasePaint(Color.BLUE);
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesItemLabelGenerator(0, new RainItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, Depth.getDefaultFormatter()));
    StandardCategoryToolTipGenerator ttgen = new StandardCategoryToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, Depth.getDefaultFormatter());
    rainPlot.getRenderer().setSeriesToolTipGenerator(0, ttgen);

    NumberFormat etFormatter = (NumberFormat) Depth.getDefaultFormatter().clone();
    etFormatter.setMaximumFractionDigits(etFormatter.getMaximumFractionDigits() + 1);
    renderer.setSeriesItemLabelGenerator(1, new RainItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, etFormatter));
    ttgen = new StandardCategoryToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            etFormatter);
    rainPlot.getRenderer().setSeriesToolTipGenerator(1, ttgen);

    rainPlot.setRangeAxis(valueAxis);
    rainPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);

    dataTable = new TableView();

    TableColumn<RainItem, Integer> hourColumn = new TableColumn<>(HOUR_ROW_KEY);
    hourColumn.setCellValueFactory(new PropertyValueFactory(HOUR_ROW_KEY));
    dataTable.getColumns().add(hourColumn);

    TableColumn<RainItem, Depth> rainfallColumn = new TableColumn<>("Rainfall");
    rainfallColumn.setCellValueFactory(new PropertyValueFactory(RAIN_ROW_KEY));
    dataTable.getColumns().add(rainfallColumn);

    TableColumn<RainItem, Depth> etColumn = new TableColumn<>(ET_ROW_KEY);
    etColumn.setCellValueFactory(new PropertyValueFactory(ET_ROW_KEY));
    dataTable.getColumns().add(etColumn);

    this.setTabContents(chartViewer, dataTable);
}

From source file:com.ggvaidya.scinames.summary.HigherStabilityView.java

private TableColumn<String, String> createTableColumn(String colName, Function<String, String> func) {
    TableColumn<String, String> tableColumn = new TableColumn<>(colName);
    tableColumn.setCellValueFactory(features -> new ReadOnlyStringWrapper(func.apply(features.getValue())));

    tableColumn.setPrefWidth(100.0);//from   ww w. j  a v a 2s . c o  m

    return tableColumn;
}

From source file:org.opendolphin.mvndemo.clientlazy.DemoController.java

private void createTableLazy(List<Map> data) {
    //Tabellen Spalten wieder sortieren.
    SortedMap<Integer, String> ms = new TreeMap<>(data.get(0));
    colNames = ms.values().toArray(colNames);
    // Model Listener
    initLazyModle(colNames);//from  w  w w  .ja  v  a 2  s .com
    DemoApp.clientDolphin.addModelStoreListener(TYPE_LAZY, new ModelStoreListener() {

        @Override
        public void modelStoreChanged(ModelStoreEvent event) {
            PresentationModel pm = event.getPresentationModel();
            used.setValue(used.get() + 1);
            unused.setValue(lazyRows.size() - used.get());
            //
            int i = 0;
            for (Map<String, SimpleStringProperty> m : lazyModel) {
                String v = null;
                Attribute atr = pm.getAt(colNames[i]);
                if (atr != null) {
                    v = (String) atr.getValue();
                }
                m.get(pm.getId()).setValue(v);
                i++;
            }
        }
    });
    //Create table columns
    TableColumn<Integer, String> tableColID = new TableColumn<>("rowID");
    tableColID.setSortable(true);
    tableColID.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<Integer, String>, ObservableValue<String>>() {

                @Override
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<Integer, String> cellDataFeature) {
                    return new SimpleStringProperty(cellDataFeature.getValue().toString());
                }
            });
    tableLazy.getColumns().add(tableColID);

    for (int i = 0; i < colNames.length; i++) {
        TableColumn<Integer, String> tableCol = new TableColumn<>(colNames[i]);
        tableCol.setSortable(false);
        tableLazy.getColumns().add(tableCol);
        final int index = i;
        tableCol.setCellValueFactory(
                new Callback<TableColumn.CellDataFeatures<Integer, String>, ObservableValue<String>>() {

                    @Override
                    public ObservableValue<String> call(
                            TableColumn.CellDataFeatures<Integer, String> cellDataFeature) {
                        String lazyId = cellDataFeature.getValue().toString();
                        SimpleStringProperty placeholder = lazyModel.get(index).get(lazyId);
                        if ("...".equals(placeholder.getValue())) {
                            DemoApp.clientDolphin.getClientModelStore().withPresentationModel(lazyId, (pm) -> {
                                /*NOP*/
                            });
                            // Wrong Way
                            //                  GetPresentationModelCommand pmc = new GetPresentationModelCommand();
                            //                  pmc.setPmId(lazyId);
                            //                  MonitorApp.clientDolphin.getClientConnector().send(pmc);
                        }
                        return placeholder;
                    }
                });
    }
    //
    tableLazy.setItems(lazyRows);
}

From source file:com.bdb.weather.display.summary.HighLowPanel.java

@SuppressWarnings("LeakingThisInConstructor")
public HighLowPanel(String title, SummaryInterval interval, ViewLauncher launcher, SummarySupporter supporter,
        ValueAxis rangeAxis, String domainAxisLabel, SeriesInfo<T>[] seriesList, NumberFormat format) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    this.launcher = launcher;
    this.supporter = supporter;

    chart = ChartFactory.createHighLowChart(title, domainAxisLabel, "", seriesCollection, true);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    plot = (XYPlot) chart.getPlot();/*from  ww w . ja va2  s  .c o m*/
    renderer = (HighLowRenderer) plot.getRenderer();
    renderer.setDrawCloseTicks(false);

    plot.setRangeAxis(rangeAxis);

    dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setDateFormatOverride(interval.getLegacyFormat());
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    //dateAxis.setTickUnit(interval.getDateTickUnit());
    //dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 2));

    ChartViewer chartViewer = new ChartViewer(chart);
    chartViewer.addChartMouseListener(this);
    chartViewer.setPrefSize(500, 300);

    series = new OHLCSeries[seriesList.length];

    for (int i = 0; i < seriesList.length; i++) {
        series[i] = new OHLCSeries(seriesList[i].getSeriesName());
        seriesCollection.addSeries(series[i]);
    }

    seriesInfo = Arrays.copyOf(seriesList, seriesList.length);

    TableColumn<SummaryRecord, String> column = new TableColumn<>("Date");
    column.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));

    dataTable.getColumns().add(column);

    String headingPrefix[] = { HIGH_COL_HEADING, LOW_COL_HEADING, AVG_COL_HEADING };

    for (SeriesInfo<T> seriesColumn : seriesList) {
        for (String heading : headingPrefix) {
            column = new TableColumn<>(heading + " - " + seriesColumn.getSeriesName());
            column.setCellValueFactory(seriesColumn);
            column.setUserData(heading);
            dataTable.getColumns().add(column);
        }
    }

    this.setTabContents(chartViewer, dataTable);

    HighLowItemLabelGenerator ttg = new HiLoItemLabelGenerator(interval.getLegacyFormat(), format);
    plot.getRenderer().setBaseToolTipGenerator(ttg);
}

From source file:analyzer.code.FXMLAnalyzerController.java

@FXML
private void calculateMetricButtonAction(ActionEvent event) {
    List<String> nameFiles = nameFile;
    ArrayList<List<String>> metrs;
    if (curLang == C) {
        analyzer.setMetricSettings(metricSettings.get(curLang));
    }//from   w  ww. j av  a2 s .c  om
    //??  ?  
    for (String src : source) {
        analyzer.solutMetrics(src);
    }

    //   
    metrs = analyzer.getResult();

    //?       ??
    nameFile.add(" ");

    // 
    tableMetric.refresh();
    tableMetric.getItems().clear();
    tableMetric.getColumns().clear();
    tableDescript.refresh();
    tableDescript.getItems().clear();
    tableDescript.getColumns().clear();

    //? ?  
    for (int i = 0; i < source.size() + 1; i++) {
        tableMetric.getItems().add(i);
        tableDescript.getItems().add(i);
    }

    //? ? ?  
    TableColumn<Integer, String> nameFl = new TableColumn<>("Name File");
    nameFl.setCellValueFactory(cellData -> {
        Integer rowIndex = cellData.getValue();
        return new ReadOnlyStringWrapper(nameFiles.get(rowIndex));
    });
    tableMetric.getColumns().add(nameFl); //? ?  

    //  ? ? 
    EnumNameMetricC[] enumName = EnumNameMetricC.values();
    for (int i = 0; i < metrs.size(); i++) {
        List<String> list = metrs.get(i);
        TableColumn<Integer, String> nameColumn = new TableColumn<>(enumName[i].getName());
        nameColumn.setCellValueFactory(cellData -> {
            Integer rowIndex = cellData.getValue();
            return new ReadOnlyStringWrapper(list.get(rowIndex));
        });
        tableMetric.getColumns().add(nameColumn);
    }

    if (curLang == C) {
        tableDescript.getColumns().add(nameFl);

        TableColumn<Integer, String> columnDesc = new TableColumn<>("Count Operators");
        columnDesc.setCellValueFactory(cellData -> {
            Integer rowIndex = cellData.getValue();
            return new ReadOnlyStringWrapper(CountOperators.getMark(metricSettings.get(curLang).get(0).getMin(),
                    metricSettings.get(curLang).get(0).getMax(), Double.valueOf(metrs.get(0).get(rowIndex))));
        });
        tableDescript.getColumns().add(columnDesc);

        TableColumn<Integer, String> columnDesc1 = new TableColumn<>("Level Nest");
        columnDesc1.setCellValueFactory(cellData -> {
            Integer rowIndex = cellData.getValue();
            return new ReadOnlyStringWrapper(LevelNesting.getMark(metricSettings.get(curLang).get(1).getMin(),
                    metricSettings.get(curLang).get(1).getMax(), Double.valueOf(metrs.get(1).get(rowIndex))));
        });
        tableDescript.getColumns().add(columnDesc1);

        TableColumn<Integer, String> columnDesc2 = new TableColumn<>("Middle Len Ident");
        columnDesc2.setCellValueFactory(cellData -> {
            Integer rowIndex = cellData.getValue();
            return new ReadOnlyStringWrapper(MiddleLenIdent.getMark(metricSettings.get(curLang).get(2).getMin(),
                    metricSettings.get(curLang).get(2).getMax(), Double.valueOf(metrs.get(2).get(rowIndex))));
        });
        tableDescript.getColumns().add(columnDesc2);

        double mark = analyzer.getMark();
        labelMark.setText(": " + String.format(Locale.US, "%.2f", mark) + "  5");
        labelMark.setVisible(true);
    }
}

From source file:com.mycompany.songbitmaven.RecommendationController.java

public void loadTable() {
    ObservableList<SongInfo> tracks = FXCollections.observableArrayList();
    TableColumn nameColumn = new TableColumn("Name");
    nameColumn.setMinWidth(250);//from   w ww.j  ava 2  s  .  co  m
    nameColumn.setCellValueFactory(new PropertyValueFactory<SongInfo, String>("name"));

    TableColumn artistColumn = new TableColumn("Artist");
    artistColumn.setMinWidth(250);
    artistColumn.setCellValueFactory(new PropertyValueFactory<SongInfo, String>("artist"));

    table.getColumns().setAll(nameColumn, artistColumn);
    tracks.clear();

    for (int i = 0; i < recommendations.size(); i++) {
        recommendations.get(i).updateArtist();
        tracks.add(recommendations.get(i));
    }

    table.setItems(tracks);
}

From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java

private TableView<?> createNewFileNamesPane(ObservableList<UpdateFileNamesFromTagsItem> items) {

    TableColumn<UpdateFileNamesFromTagsItem, String> currentFileNameColumn = new TableColumn<>(
            this.getLocalization().currentFileName());
    currentFileNameColumn.setSortable(false);
    currentFileNameColumn.setCellValueFactory(p -> p.getValue().getCurrentFileName());
    TableColumn<UpdateFileNamesFromTagsItem, String> newFileNameColumn = new TableColumn<>(
            this.getLocalization().newFileName());
    newFileNameColumn.setSortable(false);
    newFileNameColumn.setCellValueFactory(p -> p.getValue().getNewFileName());

    TableView<UpdateFileNamesFromTagsItem> tableView = new TableView<>(items);
    tableView.getColumns().addAll(Arrays.asList(currentFileNameColumn, newFileNameColumn));
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return tableView;

}

From source file:com.github.douglasjunior.simpleCSVEditor.FXMLController.java

private TableColumn<CSVRow, String> createColumn(int index) {
    TableColumn<CSVRow, String> col = new TableColumn<>((index + 1) + "");
    col.setSortable(false);/*from w ww  .  java 2  s  .c o m*/
    col.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<CSVRow, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(TableColumn.CellDataFeatures<CSVRow, String> param) {
                    adjustColumns(param.getValue().getColumns());
                    return param.getValue().getColumns().get(index);
                }
            });
    col.setCellFactory(TextFieldTableCell.forTableColumn());
    col.setOnEditCommit(new EventHandler<CellEditEvent<CSVRow, String>>() {
        @Override
        public void handle(CellEditEvent<CSVRow, String> event) {
            adjustColumns(event.getRowValue().getColumns());
            event.getRowValue().getColumns().get(index).set(event.getNewValue());
            setNotSaved();
        }
    });
    col.setEditable(true);
    return col;
}

From source file:com.panemu.tiwulfx.control.LookupFieldController.java

/**
 * Show lookup dialog./*from   w w w .j  ava  2  s.  co m*/
 *
 * @param stage parent
 * @param initialValue this value will be returned if user clik the close
 * button instead of double clicking a row or click Select button
 * @param propertyName propertyName corresponds to searchCriteria
 * @param searchCriteria searchCriteria (nullable)
 * @return selected object or the initialValue
 */
public T show(final Window stage, T initialValue, String propertyName, String searchCriteria) {
    if (dialogStage == null) {
        PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors(recordClass);
        lookupWindow = new LookupWindow();
        for (String clm : getColumns()) {
            for (PropertyDescriptor prop : props) {
                if (prop.getName().equals(clm)) {
                    Class type = prop.getPropertyType();
                    if (type.equals(Boolean.class)) {
                        lookupWindow.table.addColumn(new CheckBoxColumn<T>(clm));
                    } else if (type.equals(String.class)) {
                        lookupWindow.table.addColumn(new TextColumn<T>(clm));
                    } else if (type.equals(Date.class)) {
                        lookupWindow.table.addColumn(new LocalDateColumn<T>(clm));
                    } else if (Number.class.isAssignableFrom(type)) {

                        if (Long.class.isAssignableFrom(type)) {
                            lookupWindow.table.addColumn(new NumberColumn<T, Long>(clm, type));
                        } else {
                            lookupWindow.table.addColumn(new NumberColumn<T, Double>(clm, type));
                        }
                    } else {
                        TableColumn column = new TableColumn();
                        column.setCellValueFactory(new PropertyValueFactory(clm));
                        lookupWindow.table.addColumn(column);
                    }
                    break;
                }
            }

        }
        dialogStage = new Stage();
        if (stage instanceof Stage) {
            dialogStage.initOwner(stage);
            dialogStage.initModality(Modality.WINDOW_MODAL);
        } else {
            dialogStage.initOwner(null);
            dialogStage.initModality(Modality.APPLICATION_MODAL);
        }
        dialogStage.initStyle(StageStyle.UTILITY);
        dialogStage.setResizable(true);
        dialogStage.setScene(new Scene(lookupWindow));
        dialogStage.getIcons().add(new Image(
                LookupFieldController.class.getResourceAsStream("/com/panemu/tiwulfx/res/image/lookup.png")));
        dialogStage.setTitle(getWindowTitle());
        dialogStage.getScene().getStylesheets()
                .add(getClass().getResource("/com/panemu/tiwulfx/res/tiwulfx.css").toExternalForm());
        initCallback(lookupWindow, lookupWindow.table);
    }

    for (TableColumn column : lookupWindow.table.getTableView().getColumns()) {
        if (column instanceof BaseColumn && ((BaseColumn) column).getPropertyName().equals(propertyName)) {
            if (searchCriteria != null && !searchCriteria.isEmpty()) {
                TableCriteria tc = new TableCriteria(propertyName, TableCriteria.Operator.ilike_anywhere,
                        searchCriteria);
                ((BaseColumn) column).setTableCriteria(tc);
            } else {
                ((BaseColumn) column).setTableCriteria(null);
            }

            break;
        }
    }
    selectedValue = initialValue;
    beforeShowCallback(lookupWindow.table);
    lookupWindow.table.reloadFirstPage();

    if (stage != null) {
        /**
         * Since we support multiple monitors, ensure that the stage is
         * located in the center of parent stage. But we don't know the
         * dimension of the stage for the calculation, so we defer the
         * relocation after the stage is actually displayed.
         */
        Runnable runnable = new Runnable() {
            public void run() {
                dialogStage.setX(stage.getX() + stage.getWidth() / 2 - dialogStage.getWidth() / 2);
                dialogStage.setY(stage.getY() + stage.getHeight() / 2 - dialogStage.getHeight() / 2);

                //set the opacity back to fully opaque
                dialogStage.setOpacity(1);
            }
        };

        Platform.runLater(runnable);

        //set the opacity to 0 to minimize flicker effect
        dialogStage.setOpacity(0);
    }

    dialogStage.showAndWait();
    return selectedValue;
}

From source file:com.bdb.weather.display.day.DayXYPlotPane.java

protected final void createElements() {
    createChartElements();/*  ww  w.  java 2s.co  m*/

    //
    // Build the table for the data tab
    //
    dataTable = new TableView<>();

    this.setTabContents(chartViewer, dataTable);

    TableColumn<HistoricalRecord, String> col = new TableColumn<>(TIME_HEADING);
    col.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            DisplayConstants.formatTime(rec.getValue().getTime().toLocalTime())));
    dataTable.getColumns().add(col);

    doConfigure(displayMenu);
    this.layout();
}