Search in sources :

Example 6 with TreeTableColumn

use of javafx.scene.control.TreeTableColumn in project JFoenix by jfoenixadmin.

the class TreeTableViewController method init.

@PostConstruct
public void init() throws FlowException, VetoException {
    String[] names = { "Morley", "Scott", "Kruger", "Lain", "Kennedy", "Gawron", "Han", "Hall", "Aydogdu", "Grace", "Spiers", "Perera", "Smith", "Connoly", "Sokolowski", "Chaow", "James", "June" };
    Random random = new Random();
    firstNameColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, String> param) -> {
        if (firstNameColumn.validateValue(param))
            return param.getValue().getValue().firstName;
        else
            return firstNameColumn.getComputedValue(param);
    });
    lastNameColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, String> param) -> {
        if (lastNameColumn.validateValue(param))
            return param.getValue().getValue().lastName;
        else
            return lastNameColumn.getComputedValue(param);
    });
    ageColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, Integer> param) -> {
        if (ageColumn.validateValue(param))
            return param.getValue().getValue().age.asObject();
        else
            return ageColumn.getComputedValue(param);
    });
    ObservableList<Person> people = FXCollections.observableArrayList();
    for (int i = 0; i < 100; i++) people.add(new Person(names[random.nextInt(names.length)], names[random.nextInt(names.length)], random.nextInt(100)));
    treeTableView.setRoot(new RecursiveTreeItem<Person>(people, RecursiveTreeObject::getChildren));
    treeTableView.setShowRoot(false);
    treeTableViewCount.textProperty().bind(Bindings.createStringBinding(() -> "( " + treeTableView.getCurrentItemsCount() + " )", treeTableView.currentItemsCountProperty()));
    treeTableViewAdd.disableProperty().bind(Bindings.notEqual(-1, treeTableView.getSelectionModel().selectedIndexProperty()));
    treeTableViewRemove.disableProperty().bind(Bindings.equal(-1, treeTableView.getSelectionModel().selectedIndexProperty()));
    treeTableViewAdd.setOnMouseClicked((e) -> {
        people.add(new Person(names[random.nextInt(names.length)], names[random.nextInt(names.length)], random.nextInt(100)));
        treeTableView.currentItemsCountProperty().set(treeTableView.currentItemsCountProperty().get() + 1);
    });
    treeTableViewRemove.setOnMouseClicked((e) -> {
        people.remove(treeTableView.getSelectionModel().selectedItemProperty().get().getValue());
        treeTableView.currentItemsCountProperty().set(treeTableView.currentItemsCountProperty().get() - 1);
    });
    searchField.textProperty().addListener((o, oldVal, newVal) -> {
        treeTableView.setPredicate(person -> person.getValue().firstName.get().contains(newVal) || person.getValue().lastName.get().contains(newVal) || (person.getValue().age.get() + "").contains(newVal));
    });
    firstNameEditableColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, String> param) -> {
        if (firstNameEditableColumn.validateValue(param))
            return param.getValue().getValue().firstName;
        else
            return firstNameEditableColumn.getComputedValue(param);
    });
    lastNameEditableColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, String> param) -> {
        if (lastNameEditableColumn.validateValue(param))
            return param.getValue().getValue().lastName;
        else
            return lastNameEditableColumn.getComputedValue(param);
    });
    ageEditableColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Person, Integer> param) -> {
        if (ageEditableColumn.validateValue(param))
            return param.getValue().getValue().age.asObject();
        else
            return ageEditableColumn.getComputedValue(param);
    });
    // add editors
    firstNameEditableColumn.setCellFactory((TreeTableColumn<Person, String> param) -> new GenericEditableTreeTableCell<Person, String>(new TextFieldEditorBuilder()));
    firstNameEditableColumn.setOnEditCommit((CellEditEvent<Person, String> t) -> {
        ((Person) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).firstName.set(t.getNewValue());
    });
    lastNameEditableColumn.setCellFactory((TreeTableColumn<Person, String> param) -> new GenericEditableTreeTableCell<Person, String>(new TextFieldEditorBuilder()));
    lastNameEditableColumn.setOnEditCommit((CellEditEvent<Person, String> t) -> {
        ((Person) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).lastName.set(t.getNewValue());
    });
    ageEditableColumn.setCellFactory((TreeTableColumn<Person, Integer> param) -> new GenericEditableTreeTableCell<Person, Integer>(new IntegerTextFieldEditorBuilder()));
    ageEditableColumn.setOnEditCommit((CellEditEvent<Person, Integer> t) -> {
        ((Person) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).age.set(t.getNewValue());
    });
    ObservableList<Person> people2 = FXCollections.observableArrayList();
    for (int i = 0; i < 200; i++) people2.add(new Person(names[random.nextInt(names.length)], names[random.nextInt(names.length)], random.nextInt(100)));
    editableTreeTableView.setRoot(new RecursiveTreeItem<Person>(people2, RecursiveTreeObject::getChildren));
    editableTreeTableView.setShowRoot(false);
    editableTreeTableView.setEditable(true);
    editableTreeTableViewCount.textProperty().bind(Bindings.createStringBinding(() -> "( " + editableTreeTableView.getCurrentItemsCount() + " )", editableTreeTableView.currentItemsCountProperty()));
    searchField2.textProperty().addListener((o, oldVal, newVal) -> {
        editableTreeTableView.setPredicate(person -> person.getValue().firstName.get().contains(newVal) || person.getValue().lastName.get().contains(newVal) || (person.getValue().age.get() + "").contains(newVal));
    });
}
Also used : CellEditEvent(javafx.scene.control.TreeTableColumn.CellEditEvent) TextFieldEditorBuilder(com.jfoenix.controls.cells.editors.TextFieldEditorBuilder) IntegerTextFieldEditorBuilder(com.jfoenix.controls.cells.editors.IntegerTextFieldEditorBuilder) Random(java.util.Random) TreeTableColumn(javafx.scene.control.TreeTableColumn) IntegerTextFieldEditorBuilder(com.jfoenix.controls.cells.editors.IntegerTextFieldEditorBuilder) PostConstruct(javax.annotation.PostConstruct)

Example 7 with TreeTableColumn

use of javafx.scene.control.TreeTableColumn in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketHex method buildPacketView.

/**
     * Build packet view
     *
     * @param packet
     * @return
     */
private VBox buildPacketView() {
    VBox insidePane = new VBox();
    TreeTableColumn<HexData, String> c0 = new TreeTableColumn<>("offst");
    c0.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getOffset()));
    c0.setSortable(false);
    c0.setPrefWidth(120);
    TreeTableColumn<HexData, String> c1 = new TreeTableColumn<>("Hex");
    c1.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getHex()));
    c1.setSortable(false);
    c1.setPrefWidth(375);
    c1.setCellFactory(new TextFieldCellFactory());
    TreeTableColumn<HexData, String> c2 = new TreeTableColumn<>("Payload");
    c2.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getPayLoad()));
    c2.setSortable(false);
    c2.setPrefWidth(130);
    hexTable = new TreeTableView<>();
    hexTable.getStyleClass().add("treeTable");
    hexTable.getColumns().addAll(c0, c1, c2);
    hexTable.setPrefSize(630, 510);
    insidePane.getChildren().add(hexTable);
    return insidePane;
}
Also used : TreeTableColumn(javafx.scene.control.TreeTableColumn) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) VBox(javafx.scene.layout.VBox)

Aggregations

TreeTableColumn (javafx.scene.control.TreeTableColumn)7 TextFieldEditorBuilder (com.jfoenix.controls.cells.editors.TextFieldEditorBuilder)2 CellEditEvent (javafx.scene.control.TreeTableColumn.CellEditEvent)2 Account (jgnash.engine.Account)2 JFXTreeTableColumn (com.jfoenix.controls.JFXTreeTableColumn)1 IntegerTextFieldEditorBuilder (com.jfoenix.controls.cells.editors.IntegerTextFieldEditorBuilder)1 JFXTreeTableCell (com.jfoenix.controls.cells.editors.base.JFXTreeTableCell)1 RecursiveTreeObject (com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)1 BigDecimal (java.math.BigDecimal)1 Random (java.util.Random)1 DoubleBinding (javafx.beans.binding.DoubleBinding)1 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 EventHandler (javafx.event.EventHandler)1 Insets (javafx.geometry.Insets)1 Node (javafx.scene.Node)1 Scene (javafx.scene.Scene)1