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() 

Source Link

Document

Creates a default TableColumn with default cell factory, comparator, and onEditCommit implementation.

Usage

From source file:br.com.ajaio.midas.desktop.controller.DashBoardController.java

private void populaTabelaConta() {
    contas = contaService.findByUsuario(usuarioLogado);
    ArrayList<Conta> contasDM = new ArrayList<Conta>();
    for (ContaEntity c : contas) {
        Conta conta = new Conta(c);
        contasDM.add(conta);//from   w  ww .java 2s  .c  o  m
    }
    final ObservableList<Conta> data = FXCollections.observableArrayList(contasDM);
    TableColumn<Conta, String> contaNomeColumn = new TableColumn<Conta, String>();
    contaNomeColumn.setCellValueFactory(new PropertyValueFactory<Conta, String>("nome"));
    tbContas.setItems(data);
    tbContas.getColumns().addAll(contaNomeColumn);
}

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

/**
 * Show lookup dialog./* w  w  w .  j  a v a 2s . c o 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.summary.HighLowMedianTempPanel.java

/**
 * Constructor./*from w w  w .  ja  v a2s . c o m*/
 * 
 * @param interval The interval for which this graph is being used. Intervals are typically day, week, month or year.
 * @param launcher A class that is used to launch sub-views when a data item is double-clicked
 * @param supporter A class that aids in the generalization of this graph
 */
@SuppressWarnings("LeakingThisInConstructor")
public HighLowMedianTempPanel(SummaryInterval interval, ViewLauncher launcher, SummarySupporter supporter) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    tableHeadings = getTableColumnLabels();
    chart = ChartFactory.createXYLineChart("", "", "", null, PlotOrientation.VERTICAL, true, true, true);
    plot = (XYPlot) chart.getPlot();
    viewLauncher = launcher;
    this.supporter = supporter;

    StandardXYToolTipGenerator ttgen = new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, interval.getLegacyFormat(),
            Temperature.getDefaultFormatter());

    diffRenderer.setBaseToolTipGenerator(ttgen);

    plot.setRenderer(LOW_DATASET, diffRenderer);
    plot.setRenderer(HIGH_DATASET, diffRenderer);
    plot.setRenderer(MEDIAN_DATASET, diffRenderer);

    valueAxis.setAutoRangeIncludesZero(false);

    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);

    plot.setRangeAxis(valueAxis);
    dateAxis = new DateAxis("Date");
    dateAxis.setDateFormatOverride(interval.getLegacyFormat());
    dateAxis.setVerticalTickLabels(true);
    //dateAxis.setTickUnit(interval.getDateTickUnit());

    plot.setDomainAxis(dateAxis);

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

    dataTable = new TableView();

    for (int i = 0; i < tableHeadings.length; i++) {
        TableColumn col = new TableColumn();
        //col.setHeaderValue(tableHeadings[i]);
        //col.setModelIndex(i);
        //colModel.addColumn(col);
    }

    this.setTabContents(chartViewer, dataTable);
}

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

public TemperatureDeviationPlotPanel(SummaryInterval interval, ViewLauncher theLauncher,
        SummarySupporter theSupporter) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    chart = ChartFactory.createXYBarChart("Deviation from Average Temperature", "Date", true,
            "Deviation (" + Temperature.getDefaultUnit() + ")", null, PlotOrientation.VERTICAL, true, true,
            false);/*from ww w  . j a  v  a  2 s. c o m*/

    chartViewer = new ChartViewer(chart);
    chartViewer.setPrefSize(500, 300);
    chartViewer.addChartMouseListener(new ChartMouseListenerFX() {
        @Override
        public void chartMouseClicked(ChartMouseEventFX event) {
            ChartEntity entity = event.getEntity();
            //
            // Was a point on the plot selected?
            //
            if (entity instanceof XYItemEntity) {
                XYItemEntity itemEntity = (XYItemEntity) entity;
                XYDataset dataset = itemEntity.getDataset();
                Number x = dataset.getXValue(itemEntity.getSeriesIndex(), itemEntity.getItem());
                LocalDate date = LocalDate.from(Instant.ofEpochMilli(x.longValue()));
                boolean doubleClick = event.getTrigger().getClickCount() == 2;
                if (doubleClick) {
                    supporter.launchView(launcher, date);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEventFX event) {
            // Do nothing
        }
    });
    deviationPlot = (XYPlot) chart.getPlot();
    this.launcher = theLauncher;
    this.supporter = theSupporter;

    DateFormat dateFormat = interval.getLegacyFormat();
    StandardXYItemLabelGenerator labelGen = new StandardXYItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, dateFormat,
            Temperature.getDefaultFormatter());

    StandardXYToolTipGenerator ttGen = new StandardXYToolTipGenerator(
            StandardCategoryToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT_STRING, dateFormat,
            Temperature.getDefaultFormatter());

    valueAxis = deviationPlot.getRangeAxis();
    valueAxis.setUpperMargin(.20);
    valueAxis.setLowerMargin(.20);

    deviationPlot.getDomainAxis().setVerticalTickLabels(true);
    DateAxis dateAxis = (DateAxis) deviationPlot.getDomainAxis();
    dateAxis.setDateFormatOverride(dateFormat);
    //dateAxis.setTickUnit(interval.getDateTickUnit());

    //DefaultTableColumnModel colModel = new DefaultTableColumnModel();

    dataTable = new TableView();
    //dataTable.setModel(tableModel);
    //dataTable.setColumnModel(colModel);

    //dataTable.setAutoCreateColumnsFromModel(false);

    for (int i = 0; i < TABLE_HEADINGS.length; i++) {
        TableColumn col = new TableColumn();
        col.setText(TABLE_HEADINGS[i]);
        //col.setModelIndex(i);
        //colModel.addColumn(col);
    }

    //tableModel.setColumnCount(TABLE_HEADINGS.length);

    this.setTabContents(chartViewer, dataTable);

    lowRenderer.setBasePaint(Color.BLUE);
    lowRenderer.setBaseItemLabelGenerator(labelGen);
    lowRenderer.setBaseToolTipGenerator(ttGen);
    lowRenderer.setBarAlignmentFactor(.6);
    lowRenderer.setShadowVisible(false);

    meanRenderer.setSeriesPaint(0, Color.CYAN);
    meanRenderer.setBaseItemLabelGenerator(labelGen);
    meanRenderer.setBaseToolTipGenerator(ttGen);
    meanRenderer.setBarAlignmentFactor(.3);
    meanRenderer.setShadowVisible(false);

    highRenderer.setSeriesPaint(0, Color.GRAY);
    highRenderer.setBaseItemLabelGenerator(labelGen);
    highRenderer.setBaseToolTipGenerator(ttGen);
    highRenderer.setShadowVisible(false);
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@FXML
void onShowCompoundIntensityTable(MouseEvent event) {
    if (tableCompound.getSelectionModel().isEmpty())
        return;/*from   www  .j  ava  2 s  .  c o  m*/

    IntensityMatrixImpl intensityMatrix = dataManager.getIntensityMatrix();

    for (CompoundImpl compound : tableCompound.getSelectionModel().getSelectedItems()) {

        TableView<IntensityValue> tableView = new TableView<>(
                FXCollections
                        .observableArrayList(intensityMatrix
                                .getColumnKeys().stream().map(it -> new IntensityValue(it.getPlate(),
                                        it.getSample(), it, intensityMatrix.get(compound, it)))
                                .collect(Collectors.toList())));

        Arrays.asList("Plate", "Sample", "Injection", "Intensity").forEach(it -> {
            TableColumn<IntensityValue, Double> column = new TableColumn<>();
            column.setText(it);
            //noinspection unchecked
            column.setCellValueFactory(new PropertyValueFactory(it));
            tableView.getColumns().add(column);
        });

        Scene scene = new Scene(tableView);
        Stage stage = new Stage(StageStyle.UTILITY);
        stage.setScene(scene);
        stage.setWidth(800);
        stage.setHeight(600);
        stage.setTitle(compound.toString());
        stage.show();
    }

}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@SuppressWarnings("unchecked")
private void initializeTable(TableView tableView, Class clazz) {
    ArrayList<TableColumn> columns = new ArrayList<>();
    HashSet<String> methodNames = new HashSet<>();
    method: for (Method one : clazz.getMethods()) {
        for (String black : new String[] { "getClass", "getAttributeKeySet" })
            if (one.getName().equals(black))
                continue method;
        if (!one.getName().startsWith("get") && !one.getName().startsWith("is"))
            continue;
        if (one.getParameterCount() != 0)
            continue;
        if (methodNames.contains(one.getName()))
            continue;
        methodNames.add(one.getName());//  ww  w.ja  v  a2s.  co m

        TableColumn oneColumn = new TableColumn();
        String name = one.getName().substring(3);
        if (one.getName().startsWith("is")) {
            name = one.getName().substring(2);
        }
        oneColumn.setText(name);
        oneColumn.setCellValueFactory(new PropertyValueFactory(name));

        if (one.getName().equals("getId"))
            columns.add(0, oneColumn);
        else
            columns.add(oneColumn);
    }

    tableView.getColumns().addAll(columns.toArray());
}