Java Code Examples for javafx.scene.control.TableColumn#setCellValueFactory()

The following examples show how to use javafx.scene.control.TableColumn#setCellValueFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TracesTab.java    From phoebus with Eclipse Public License 1.0 7 votes vote down vote up
private void createArchivesTable()
{
    archives_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    archives_table.setPlaceholder(new Label(Messages.ArchiveListGUI_NoArchives));

    // Archive Name Column ----------
    TableColumn<ArchiveDataSource, String> col = new TableColumn<>(Messages.ArchiveName);
    col.setCellValueFactory(cell -> new SimpleStringProperty(cell.getValue().getName()));
    archives_table.getColumns().add(col);

    // Archive Server URL Column ----------
    col = new TableColumn<>(Messages.URL);
    col.setCellValueFactory(cell -> new SimpleStringProperty(cell.getValue().getUrl()));
    archives_table.getColumns().add(col);

    archives_table.getColumns().forEach(c -> c.setSortable(false));
}
 
Example 2
Source File: AppController.java    From curly with Apache License 2.0 7 votes vote down vote up
private void loadData(List<Map<String, String>> data) {
    batchDataTable.getColumns().clear();

    TableColumn<Map<String, String>, String> numberCol = new TableColumn("");
    numberCol.setCellValueFactory(row -> new ReadOnlyObjectWrapper(
            (row.getTableView().getItems().indexOf(row.getValue()) + 1) + ""));
    batchDataTable.getColumns().add(numberCol);
    numberCol.setMinWidth(50);

    data.get(0).keySet().forEach(varName -> {
        TableColumn<Map<String, String>, String> varCol = new TableColumn(varName);
        varCol.setCellValueFactory(row -> new ReadOnlyObjectWrapper(row.getValue().get(varName)));
        batchDataTable.getColumns().add(varCol);
    });

    batchDataTable.setItems(new ObservableListWrapper<>(data));
}
 
Example 3
Source File: TableSample.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
public TableSample() {
    final ObservableList<Person> data = FXCollections.observableArrayList(
        new Person("Jacob",     "Smith",    "[email protected]" ),
        new Person("Isabella",  "Johnson",  "[email protected]" ),
        new Person("Ethan",     "Williams", "[email protected]" ),
        new Person("Emma",      "Jones",    "[email protected]" ),
        new Person("Michael",   "Brown",    "[email protected]" )
    );
    TableColumn firstNameCol = new TableColumn();
    firstNameCol.setText("First");
    firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
    TableColumn lastNameCol = new TableColumn();
    lastNameCol.setText("Last");
    lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
    TableColumn emailCol = new TableColumn();
    emailCol.setText("Email");
    emailCol.setMinWidth(200);
    emailCol.setCellValueFactory(new PropertyValueFactory("email"));
    TableView tableView = new TableView();
    tableView.setItems(data);
    tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
    getChildren().add(tableView);
}
 
Example 4
Source File: WidgetInfoDialog.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private Tab createMacros(final Macros orig_macros)
{
    final Macros macros = (orig_macros == null) ? new Macros() : orig_macros;
    // Use text field to allow copying the name and value
    // Table uses list of macro names as input
    // Name column just displays the macro name,..
    final TableColumn<String, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(col -> new ReadOnlyTextCell<>());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));

    // .. value column fetches the macro value
    final TableColumn<String, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(col -> new ReadOnlyTextCell<>());
    value.setCellValueFactory(param -> new ReadOnlyStringWrapper(macros.getValue(param.getValue())));

    final TableView<String> table =
        new TableView<>(FXCollections.observableArrayList(macros.getNames()));
    table.getColumns().add(name);
    table.getColumns().add(value);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    return new Tab(Messages.WidgetInfoDialog_TabMacros, table);
}
 
Example 5
Source File: BrowserTab.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public PreferenceTableView() {
    getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    setPrefHeight(100);
    setEditable(false);
    TableColumn<BrowserPreference, String> colName = new TableColumn<>("Name");
    colName.setCellValueFactory(new PropertyValueFactory<>("name"));
    colName.prefWidthProperty().bind(widthProperty().multiply(0.5));
    TableColumn<BrowserPreference, String> colType = new TableColumn<>("Type");
    colType.setCellValueFactory(new PropertyValueFactory<>("type"));
    colType.prefWidthProperty().bind(widthProperty().multiply(0.20));
    TableColumn<BrowserPreference, String> colValue = new TableColumn<>("Value");
    colValue.setCellValueFactory(new PropertyValueFactory<>("value"));
    colValue.prefWidthProperty().bind(widthProperty().multiply(0.25));
    getColumns().add(colName);
    getColumns().add(colType);
    getColumns().add(colValue);
}
 
Example 6
Source File: TableFactory.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
@Override
public FXFormNode call(Void param) {
    tableView.setEditable(true);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    return new FXFormNodeWrapper(new VBox(3, tableView, new HBox(5, addButton, removeButton)), tableView.itemsProperty()) {

        @Override
        public void init(Element element, AbstractFXForm fxForm) {
            super.init(element, fxForm);
            Class wrappedType = element.getWrappedType();
            List<Field> fields = ReflectionUtils.listFields(wrappedType);
            for (Field field : fields) {
                TableColumn col = new TableColumn(field.getName());
                col.setCellValueFactory(new PropertyValueFactory(field.getName()));
                col.setCellFactory(list -> new TextFieldTableCell(new DefaultStringConverter()));

                tableView.getColumns().add(col);

            }

            addButton.setOnAction(event -> {
                try {
                    tableView.getItems().add(element.getWrappedType().newInstance());
                    tableView.edit(tableView.getItems().size() - 1, (TableColumn) tableView.getColumns().get(0));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

            removeButton.setOnAction(event -> {
                tableView.getItems().removeAll(tableView.getSelectionModel().getSelectedItems());
            });
        }
    };
}
 
Example 7
Source File: DefaultTable.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
protected void addColumnNumber(String heading, int width, String propertyName)
{
  TableColumn<T, Number> column = new TableColumn(heading);
  column.setPrefWidth(width);
  column.setCellValueFactory(new PropertyValueFactory(propertyName));
  getColumns().add(column);
  column.setStyle("-fx-alignment: CENTER-RIGHT;");
}
 
Example 8
Source File: TaskSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TaskSample() {
    TableView<DailySales> tableView = new TableView<DailySales>();
    Region veil = new Region();
    veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
    ProgressIndicator p = new ProgressIndicator();
    p.setMaxSize(150, 150);
    //Define table columns
    TableColumn idCol = new TableColumn();
    idCol.setText("ID");
    idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
    tableView.getColumns().add(idCol);
    TableColumn qtyCol = new TableColumn();
    qtyCol.setText("Qty");
    qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
    tableView.getColumns().add(qtyCol);
    TableColumn dateCol = new TableColumn();
    dateCol.setText("Date");
    dateCol.setCellValueFactory(new PropertyValueFactory("date"));
    dateCol.setMinWidth(240);
    tableView.getColumns().add(dateCol);
    StackPane stack = new StackPane();
    stack.getChildren().addAll(tableView, veil, p);

    // Use binding to be notified whenever the data source chagnes
    Task<ObservableList<DailySales>> task = new GetDailySalesTask();
    p.progressProperty().bind(task.progressProperty());
    veil.visibleProperty().bind(task.runningProperty());
    p.visibleProperty().bind(task.runningProperty());
    tableView.itemsProperty().bind(task.valueProperty());

    getChildren().add(stack);
    new Thread(task).start();
}
 
Example 9
Source File: IndexController.java    From WIFIProbe with Apache License 2.0 5 votes vote down vote up
private void initProcessTable() {
    ObservableList<TableColumn<Process, ?>> processCols = processTable.getColumns();
    processCols.get(0).setCellValueFactory(new PropertyValueFactory<>("status"));
    TableColumn<Process,Double> processCol = new TableColumn<>("进度");
    processCol.setPrefWidth(475);
    processCol.setCellValueFactory(new PropertyValueFactory<>("progress"));
    processCol.setCellFactory(ProgressBarTableCell.forTableColumn());
    processCols.set(1,processCol);
    processCols.get(2).setCellValueFactory(new PropertyValueFactory<>("percent"));
    processCols.get(3).setCellValueFactory(new PropertyValueFactory<>("lastUpdate"));
}
 
Example 10
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param index Column index, -1 to add to end
 *  @param header Header text
 */
private void createTableColumn(final int index, final String header)
{
    final TableColumn<List<ObservableCellValue>, CellValue> table_column = new TableColumn<>(header);
    table_column.setCellValueFactory(VALUE_FACTORY);
    // Prevent column re-ordering
    // (handled via moveColumn which also re-orders the data)
    table_column.setReorderable(false);

    // By default, use text field editor. setColumnOptions() can replace
    table_column.setCellFactory(list -> new StringTextCell());
    table_column.setOnEditStart(event -> editing = true);
    table_column.setOnEditCommit(event ->
    {
        editing = false;
        final int col = event.getTablePosition().getColumn();
        List<ObservableCellValue> row = event.getRowValue();
        if (row == MAGIC_LAST_ROW)
        {
            // Entered in last row? Create new row
            row = createEmptyRow();
            final List<List<ObservableCellValue>> data = table.getItems();
            data.add(data.size()-1, row);
        }
        row.get(col).setValue(event.getNewValue());
        fireDataChanged();

        // Automatically edit the next row, same column
        editCell(event.getTablePosition().getRow() + 1, table_column);
    });
    table_column.setOnEditCancel(event -> editing = false);
    table_column.setSortable(false);

    if (index >= 0)
        table.getColumns().add(index, table_column);
    else
        table.getColumns().add(table_column);
}
 
Example 11
Source File: TaskSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TaskSample() {
    TableView<DailySales> tableView = new TableView<DailySales>();
    Region veil = new Region();
    veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.4)");
    ProgressIndicator p = new ProgressIndicator();
    p.setMaxSize(150, 150);
    //Define table columns
    TableColumn idCol = new TableColumn();
    idCol.setText("ID");
    idCol.setCellValueFactory(new PropertyValueFactory("dailySalesId"));
    tableView.getColumns().add(idCol);
    TableColumn qtyCol = new TableColumn();
    qtyCol.setText("Qty");
    qtyCol.setCellValueFactory(new PropertyValueFactory("quantity"));
    tableView.getColumns().add(qtyCol);
    TableColumn dateCol = new TableColumn();
    dateCol.setText("Date");
    dateCol.setCellValueFactory(new PropertyValueFactory("date"));
    dateCol.setMinWidth(240);
    tableView.getColumns().add(dateCol);
    StackPane stack = new StackPane();
    stack.getChildren().addAll(tableView, veil, p);

    // Use binding to be notified whenever the data source chagnes
    Task<ObservableList<DailySales>> task = new GetDailySalesTask();
    p.progressProperty().bind(task.progressProperty());
    veil.visibleProperty().bind(task.runningProperty());
    p.visibleProperty().bind(task.runningProperty());
    tableView.itemsProperty().bind(task.valueProperty());

    getChildren().add(stack);
    new Thread(task).start();
}
 
Example 12
Source File: LogUI.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
public LogUI(){
    // Initializing the main grid
    logGrid = new GridPane();
    logGrid.setPadding(new Insets(5, 5, 5, 5));
    
    // Adding separators
    logGrid.add(new Text("Log"),0,0);
    logGrid.add(new Separator(),0,1);
    
    // App status monitoring
    memoryLabel = new Label();
    UIUtils.setSize(memoryLabel, Main.columnWidthLEFT, 24);
    progressBar = new ProgressBar(0);
    UIUtils.setSize(progressBar, Main.columnWidthRIGHT, 12);
    HBox appStatusBox = new HBox(5);
    appStatusBox.setAlignment(Pos.CENTER);
    appStatusBox.getChildren().addAll(memoryLabel,progressBar);
    logGrid.add(appStatusBox,0,2);
    
    // Creating the log table
    logTable = new TableView<>();
    UIUtils.setSize(logTable,Main.windowWidth-10,150);
    TableColumn logTimeColumn = new TableColumn("Time");
    logTimeColumn.setMinWidth(90);
    logTimeColumn.setMaxWidth(90);
    TableColumn logDetailsColumn = new TableColumn("Log");
    logDetailsColumn.setMinWidth(Main.windowWidth-85);
    logTimeColumn.setCellValueFactory(new PropertyValueFactory<>("time"));
    logDetailsColumn.setCellValueFactory(new PropertyValueFactory<>("info"));
    logTable.getColumns().addAll(logTimeColumn,logDetailsColumn);
    logGrid.add(logTable,0,3);
}
 
Example 13
Source File: HistoryConfigController.java    From Vert.X-generator with MIT License 5 votes vote down vote up
/**
 * 初始化配置table
 */
public void initTable() {
	LOG.debug("初始化配置信息窗口....");
	LOG.debug("初始化配置信息表格...");
	ObservableList<HistoryConfigCVF> data = null;
	try {
		data = getHistoryConfig();
	} catch (Exception e) {
		tblConfigInfo.setPlaceholder(new Label("加载配置文件失败!失败原因:\r\n" + e.getMessage()));
		LOG.error("初始化配置信息表格出现异常!!!" + e);
	}

	TableColumn<HistoryConfigCVF, String> tdInfo = new TableColumn<HistoryConfigCVF, String>("配置信息文件名");
	tdInfo.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_TD_INFO));
	TableColumn<HistoryConfigCVF, String> tdOperation = new TableColumn<HistoryConfigCVF, String>("操作");
	tdOperation.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_TD_OPERATION));
	tdInfo.setCellValueFactory(new PropertyValueFactory<>("name"));
	tdOperation.setCellValueFactory(new PropertyValueFactory<>("hbox"));
	tblConfigInfo.getColumns().add(tdInfo);
	tblConfigInfo.getColumns().add(tdOperation);
	tblConfigInfo.setItems(data);
	StringProperty property = Main.LANGUAGE.get(LanguageKey.HISTORY_CONFIG_TABLE_TIPS);
	String tips = property == null ? "尚未添加任何配置信息;可以通过首页保存配置新增" : property.get();
	tblConfigInfo.setPlaceholder(new Label(tips));
	// 设置列的大小自适应
	tblConfigInfo.setColumnResizePolicy(resize -> {
		double width = resize.getTable().getWidth();
		tdInfo.setPrefWidth(width * 2 / 3);
		tdOperation.setPrefWidth(width / 3);
		return true;
	});
	lblTips.textProperty().bind(Main.LANGUAGE.get(LanguageKey.CONFIG_LBL_TIPS));
	LOG.debug("初始化配置信息完成!");
	LOG.debug("初始化配置信息窗口完成!");
}
 
Example 14
Source File: PVTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void createTableColumns()
{
    // Selected column
    final TableColumn<TableItemProxy, Boolean> sel_col = new TableColumn<>(Messages.Selected);
    sel_col.setCellValueFactory(cell -> cell.getValue().selected);
    sel_col.setCellFactory(column -> new BooleanTableCell());
    table.getColumns().add(sel_col);

    // PV Name
    TableColumn<TableItemProxy, String> col = new TableColumn<>(Messages.PV);
    col.setPrefWidth(250);
    col.setCellValueFactory(cell_data_features -> cell_data_features.getValue().name);
    col.setCellFactory(column -> new PVNameTableCell());
    col.setOnEditCommit(event ->
    {
        final String new_name = event.getNewValue().trim();
        final TableItemProxy proxy = event.getRowValue();
        if (proxy == TableItemProxy.NEW_ITEM)
        {
            if (!new_name.isEmpty())
                model.addItem(new_name);
            // else: No name entered, do nothing
        }
        else
        {
            // Set name, even if empty, assuming user wants to continue
            // editing the existing row.
            // To remove row, use context menu.
            proxy.getItem().updateName(new_name);
            proxy.update(proxy.getItem());
            // Content of model changed.
            // Triggers full table update.
            model.fireModelChange();
        }
    });
    // Use natural order for PV name
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    // Description
    if (Settings.show_description)
    {
        col = new TableColumn<>(Messages.Description);
        col.setCellValueFactory(cell -> cell.getValue().desc_value);
        table.getColumns().add(col);
    }

    // Time Stamp
    col = new TableColumn<>(Messages.Time);
    col.setCellValueFactory(cell ->  cell.getValue().time);
    table.getColumns().add(col);

    // Editable value
    col = new TableColumn<>(Messages.Value);
    col.setCellValueFactory(cell -> cell.getValue().value);
    col.setCellFactory(column -> new ValueTableCell(model));
    col.setOnEditCommit(event ->
    {
        event.getRowValue().getItem().setValue(event.getNewValue());
        // Since updates were suppressed, refresh table
        model.performPendingUpdates();
    });
    col.setOnEditCancel(event ->
    {
        // Since updates were suppressed, refresh table
        model.performPendingUpdates();
    });
    // Use natural order for value
    col.setComparator(CompareNatural.INSTANCE);
    table.getColumns().add(col);

    // Alarm
    col = new TableColumn<>(Messages.Alarm);
    col.setCellValueFactory(cell -> cell.getValue().alarm);
    col.setCellFactory(column -> new AlarmTableCell());
    table.getColumns().add(col);

    // Saved value
    col = new TableColumn<>(Messages.Saved);
    col.setCellValueFactory(cell -> cell.getValue().saved);
    // Use natural order for saved value
    col.setComparator(CompareNatural.INSTANCE);
    saved_value_col = col;
    table.getColumns().add(col);

    // Saved value's timestamp
    col = new TableColumn<>(Messages.Saved_Value_TimeStamp);
    col.setCellValueFactory(cell -> cell.getValue().time_saved);
    saved_time_col = col;
    table.getColumns().add(col);

    // Completion checkbox
    final TableColumn<TableItemProxy, Boolean> compl_col = new TableColumn<>(Messages.Completion);
    compl_col.setCellValueFactory(cell -> cell.getValue().use_completion);
    compl_col.setCellFactory(column -> new BooleanTableCell());
    completion_col = compl_col;
    table.getColumns().add(compl_col);
}
 
Example 15
Source File: SQLColumnSettingsComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public SQLColumnSettingsComponent() {
    columnsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    value = new SQLColumnSettings();
    TableColumn<SQLRowObject,String> columnName=new TableColumn<SQLRowObject,String> (value.getColumnName(0));
    TableColumn<SQLRowObject,SQLExportDataType>  columnType=new TableColumn<SQLRowObject,SQLExportDataType> (value.getColumnName(1));
    TableColumn<SQLRowObject,String>  columnValue= new TableColumn<SQLRowObject,String> (value.getColumnName(2));

    columnName.setCellValueFactory(new PropertyValueFactory<>("Name")); //this is needed during connection to a database
    columnType.setCellValueFactory(new PropertyValueFactory<>("Type"));
    columnValue.setCellValueFactory(new PropertyValueFactory<>("Value"));

    columnsTable.getColumns().addAll(columnName,columnType,columnValue);  //added all the columns in the table
    setValue(value);
    columnsTable.setStyle("-fx-selection-bar: #3399FF; -fx-selection-bar-non-focused: #E3E3E3;"); //CSS color change on selection of row


    columnsTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    columnName.setSortable(false);
    columnValue.setSortable(false);
    columnType.setSortable(false);

    columnName.setReorderable(false);
    columnValue.setReorderable(false);
    columnType.setReorderable(false);

    columnsTable.setPrefSize(550, 220);
    columnsTable.setFixedCellSize(columnsTable.getFixedCellSize()+20);
    columnsTable.setStyle("-fx-font: 10 \"Plain\"");

    //Setting action event on cells
    columnsTable.getSelectionModel().setCellSelectionEnabled(true);  //individual cell selection enabled
    columnsTable.setEditable(true);

    //Editors on each cell
  columnName.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnName.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 0);
    setValue(getValue()); //refresh the table
  });

  columnValue.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnValue.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue().toUpperCase(), event.getTablePosition().getRow(), 2);
    setValue(getValue()); //refresh the table
  });

  ArrayList<SQLExportDataType> exportDataTypeValues=new ArrayList<SQLExportDataType>(Arrays.asList(SQLExportDataType.values()));

  columnType.setCellFactory(ComboBoxTableCell.forTableColumn(FXCollections.observableArrayList(SQLExportDataType.values())));
  columnType.setOnEditCommit(event -> {
    boolean selected = event.getNewValue().isSelectableValue();
    if(!selected){ //case of  invalid(Title) datatype selection
      getValue().setValueAt(exportDataTypeValues.get(exportDataTypeValues.indexOf(event.getNewValue())+1),event.getTablePosition().getRow(),1);
    }
    else {
      getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 1);
    }
    setValue(getValue());
  });

    // Add buttons
    VBox buttonsPanel=new VBox(20);
    addColumnButton=new Button("Add");
    removeColumnButton=new Button("Remove");
    addColumnButton.setOnAction(this::actionPerformed);
    removeColumnButton.setOnAction(this::actionPerformed);
    buttonsPanel.getChildren().addAll(addColumnButton,removeColumnButton);


    this.setRight(buttonsPanel);
    this.setCenter(columnsTable);
    BorderPane.setMargin(buttonsPanel, new Insets(10));

}
 
Example 16
Source File: FeatureTable.java    From sis with Apache License 2.0 4 votes vote down vote up
public FeatureTable(Resource res, int i) throws DataStoreException {
    TableView<AbstractFeature> ttv = new TableView<>();
    final ScrollPane scroll = new ScrollPane(ttv);
    scroll.setFitToHeight(true);
    scroll.setFitToWidth(true);
    ttv.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
    ttv.setTableMenuButtonVisible(true);
    ttv.setFixedCellSize(100);
    scroll.setPrefSize(600, 400);
    scroll.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    setCenter(scroll);
    final List<AbstractFeature> list;
    if (res instanceof FeatureSet) {
        try (Stream<AbstractFeature> stream = ((FeatureSet) res).features(false)) {
            list = stream.collect(Collectors.toList());
            ttv.setItems(FXCollections.observableArrayList(list));
            for (AbstractIdentifiedType pt : list.get(0).getType().getProperties(false)) {
                final TableColumn<AbstractFeature, BorderPane> column = new TableColumn<>(generateFinalColumnName(pt));
                column.setCellValueFactory((TableColumn.CellDataFeatures<AbstractFeature, BorderPane> param) -> {
                    final Object val = param.getValue().getPropertyValue(pt.getName().toString());
                    if (val instanceof Geometry) {
                        return new SimpleObjectProperty<>(new BorderPane(new Label("{geometry}")));
                    } else {
                        SimpleObjectProperty<BorderPane> sop = new SimpleObjectProperty<>();
                        if (val instanceof CheckedArrayList<?>) {
                            Iterator<String> it = ((CheckedArrayList<String>) val).iterator();
                            TreeItem<String> ti = new TreeItem<>(it.next());
                            while (it.hasNext()) {
                                ti.getChildren().add(new TreeItem<>(it.next()));
                            }
                            BorderPane bp = new BorderPane(new TreeView<>(ti));
                            sop.setValue(bp);
                            return sop;
                        } else {
                            sop.setValue(new BorderPane(new Label(String.valueOf(val))));
                            return sop;
                        }
                    }
                });
                ttv.getColumns().add(column);
            }
        }
    }
}
 
Example 17
Source File: SongDataView.java    From beatoraja with GNU General Public License v3.0 4 votes vote down vote up
private void initColumn(TableColumn column, String value) {
	column.setCellValueFactory(new PropertyValueFactory(value));		
	columnMap.put(value, column);
}
 
Example 18
Source File: GUI.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private TableView<Instance> createTable()
{
    final TableView<Instance> table = new TableView<>(FXCollections.observableList(model.getInstances()));
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    table.getSelectionModel().setCellSelectionEnabled(true);

    table.setEditable(true);

    TableColumn<Instance, String> col = new TableColumn<>(Messages.SystemColumn);
    col.setCellValueFactory(cell -> new SimpleStringProperty(cell.getValue().getName()));
    table.getColumns().add(col);

    int col_index = 0;
    for (Column column : model.getColumns())
    {
        final int the_col_index = col_index;
        col = new TableColumn<>(column.getName());
        col.setCellFactory(info -> new PACETableCell());
        col.setCellValueFactory(cell -> cell.getValue().getCell(the_col_index).getObservable());
        table.getColumns().add(col);

        if (column.isReadonly())
            col.setEditable(false);
        else
        {
            col.setOnEditCommit(event ->
            {
                event.getRowValue().getCell(the_col_index).setUserValue(event.getNewValue());
                final int row = event.getTablePosition().getRow();
                // Start to edit same column in next row
                if (row < table.getItems().size() - 1)
                    Platform.runLater(() ->  table.edit(row+1, event.getTableColumn()));
            });
        }

        ++col_index;
    }

    return table;
}
 
Example 19
Source File: ResultPane.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void initResultTable() {
    resultTable.setId("resultTable");
    setLabel();
    TableColumn<Failure, String> messageColumn = new TableColumn<>("Message");
    messageColumn.setCellValueFactory(new PropertyValueFactory<>("message"));
    messageColumn.prefWidthProperty().bind(resultTable.widthProperty().multiply(0.50));

    TableColumn<Failure, String> fileNameColumn = new TableColumn<>("File");
    fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("fileName"));
    fileNameColumn.prefWidthProperty().bind(resultTable.widthProperty().multiply(0.245));

    TableColumn<Failure, String> locationColumn = new TableColumn<>("Location");
    locationColumn.setCellValueFactory(new PropertyValueFactory<>("lineNumber"));
    locationColumn.prefWidthProperty().bind(resultTable.widthProperty().multiply(0.249));

    failuresList.addListener(new ListChangeListener<Failure>() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Failure> c) {
            if (failuresList.size() == 0) {
                clearButton.setDisable(true);
            } else {
                clearButton.setDisable(false);
            }
        }
    });

    resultTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && newValue.getMessage() != null) {
            showMessageButton.setDisable(false);
        } else {
            showMessageButton.setDisable(true);
        }
    });

    resultTable.setRowFactory(e -> {
        TableRow<Failure> tableRow = new TableRow<>();
        tableRow.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && !tableRow.isEmpty()) {
                SourceLine[] traceback = tableRow.getItem().getTraceback();
                if (traceback.length > 0) {
                    fireResultPaneSelectedEvent(traceback[0]);
                }
            }
        });
        return tableRow;
    });

    resultTable.setItems(failuresList);
    resultTable.getColumns().addAll(messageColumn, fileNameColumn, locationColumn);
    VBox tableContent = new VBox(tableLabel, resultTable);
    VBox.setVgrow(tableContent, Priority.ALWAYS);
    VBox.setVgrow(resultTable, Priority.ALWAYS);
    resultPaneLayout.setCenter(tableContent);
}
 
Example 20
Source File: LogView.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private void initLogTable() {
    logTable.setId("logTable");
    TableColumn<LogRecord, Integer> iconColumn = new TableColumn<>("");
    iconColumn.prefWidthProperty().bind(logTable.widthProperty().multiply(0.05));
    iconColumn.setCellValueFactory(new PropertyValueFactory<>("type"));
    iconColumn.setCellFactory(new Callback<TableColumn<LogRecord, Integer>, TableCell<LogRecord, Integer>>() {
        @Override
        public TableCell call(TableColumn<LogRecord, Integer> param) {
            return new IconTableCell();
        }
    });

    TableColumn<LogRecord, String> messageColumn = new TableColumn<>("Message");
    messageColumn.setCellValueFactory(new PropertyValueFactory<>("message"));
    messageColumn.prefWidthProperty().bind(logTable.widthProperty().multiply(0.50));

    TableColumn<LogRecord, String> moduleColumn = new TableColumn<>("Module");
    moduleColumn.setCellValueFactory(new PropertyValueFactory<>("module"));
    moduleColumn.prefWidthProperty().bind(logTable.widthProperty().multiply(0.195));

    TableColumn<LogRecord, String> dateColumn = new TableColumn<>("Date");
    dateColumn.setCellValueFactory(new PropertyValueFactory<>("date"));
    dateColumn.prefWidthProperty().bind(logTable.widthProperty().multiply(0.25));

    logList.addListener(new ListChangeListener<LogRecord>() {
        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends LogRecord> c) {
            if (logList.size() == 0) {
                clearButton.setDisable(true);
            } else {
                clearButton.setDisable(false);
            }
        }
    });

    logTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null && newValue.getDescription() != null) {
            showMessageButton.setDisable(false);
        } else {
            showMessageButton.setDisable(true);
        }
    });
    logTable.setRowFactory(e -> {
        TableRow<LogRecord> tableRow = new TableRow<>();
        tableRow.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && !tableRow.isEmpty()) {
                LogRecord rowData = tableRow.getItem();
                if (rowData.getDescription() != null) {
                    showMessage(rowData);
                }
            }
        });
        return tableRow;
    });

    errorButton.setSelected(true);
    FilteredList<LogRecord> filtered = logList.filtered(new Predicate<LogRecord>() {
        @Override
        public boolean test(LogRecord t) {
            if (t.getType() == ILogger.ERROR || t.getType() == ILogger.MESSAGE) {
                return true;
            }
            return false;
        }
    });
    logTable.setItems(filtered);
    logTable.refresh();
    logTable.getColumns().addAll(iconColumn, messageColumn, moduleColumn, dateColumn);
}