Search in sources :

Example 1 with RecursiveTreeObject

use of com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject in project JFoenix by jfoenixadmin.

the class JFXTreeTableRowSkin method layoutChildren.

//	@Override protected void updateChildren() {
//		super.updateChildren();				
//		if(getSkinnable().getIndex() > -1){
//			if(oldSkin != this){
//				if( (!(expandedIndex == getSkinnable().getIndex() || expandTriggered) || rippler == null)
//						|| !getSkinnable().isSelected()){
//					rippler = new JFXRippler(new StackPane());
//				}else{
//					this.rippler = oldSkin.rippler;
//				}	
//			}else{
//				if(!expandTriggered){
//					rippler = new JFXRippler(new StackPane());
//				}else if(!getSkinnable().isSelected()){
//					rippler = new JFXRippler(new StackPane());
//				}
//			}
//			getChildren().add(0,rippler);
//		}
//	}
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    // allow custom skin to grouped rows
    getSkinnable().getStyleClass().remove("tree-table-row-group");
    if (getSkinnable().getTreeItem() != null && getSkinnable().getTreeItem().getValue() instanceof RecursiveTreeObject && getSkinnable().getTreeItem().getValue().getClass() == RecursiveTreeObject.class)
        getSkinnable().getStyleClass().add("tree-table-row-group");
    if (getSkinnable().getIndex() > -1 && getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()) != null) {
        super.layoutChildren(x, y, w, h);
        // disclosure row case
        if (getSkinnable().getTreeItem() != null && !getSkinnable().getTreeItem().isLeaf()) {
            //				Control c = getVirtualFlowOwner();
            //				final double defaultDisclosureWidth = disclosureWidthMap.containsKey(c) ? disclosureWidthMap.get(c) : 0;
            //				double disclosureWidth =  getDisclosureNode().prefWidth(h);
            //				if (disclosureWidth > defaultDisclosureWidth) {
            //					disclosureWidthMap.put(c, disclosureWidth);
            //					Parent p = getSkinnable();
            //					while (p != null) {
            //						if (p instanceof VirtualFlow)
            //							break;
            //						p = p.getParent();
            //					}
            //					if(p!=null){
            //						final VirtualFlow<?> flow = (VirtualFlow<?>) p;
            //						for (int i = flow.getFirstVisibleCell().getIndex() ; i <= flow.getLastVisibleCell().getIndex(); i++) {
            //							IndexedCell<?> cell = flow.getCell(i);							
            //							if (cell == null || cell.isEmpty() || cell.getIndex() >= getSkinnable().getIndex()) continue;
            //							cell.requestLayout();
            //							cell.layout();
            //						}
            //					}
            //				}
            Node arrow = ((Parent) getDisclosureNode()).getChildrenUnmodifiable().get(0);
            // relocating the disclosure node according to the grouping column
            if (((RecursiveTreeObject<?>) getSkinnable().getItem()).getGroupedColumn() != null) {
                Node col = getChildren().get((getSkinnable().getTreeTableView().getTreeItemLevel(getSkinnable().getTreeItem()) + 1));
                if (getSkinnable().getItem() instanceof RecursiveTreeObject) {
                    int index = getSkinnable().getTreeTableView().getColumns().indexOf(((RecursiveTreeObject<?>) getSkinnable().getItem()).getGroupedColumn());
                    //						getSkinnable().getTreeTableView().getColumns().get(index).getText();
                    // index + 2 , if the rippler was added
                    col = getChildren().get(index + 1);
                }
                arrow.getParent().setTranslateX(col.getBoundsInParent().getMinX());
                arrow.getParent().setLayoutX(0);
            } else {
                arrow.getParent().setTranslateX(0);
                arrow.getParent().setLayoutX(0);
            }
            // add disclosure node animation 	
            if (expandedAnimation == null || !expandedAnimation.getStatus().equals(Status.RUNNING)) {
                expandedAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 90, Interpolator.EASE_BOTH)));
                expandedAnimation.setOnFinished((finish) -> arrow.setRotate(90));
            }
            if (collapsedAnimation == null || !collapsedAnimation.getStatus().equals(Status.RUNNING)) {
                collapsedAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 0, Interpolator.EASE_BOTH)));
                collapsedAnimation.setOnFinished((finish) -> arrow.setRotate(0));
            }
            getSkinnable().getTreeItem().expandedProperty().removeListener(expandedListener);
            getSkinnable().getTreeItem().expandedProperty().addListener(expandedListener);
            if (expandTriggered) {
                if (getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()).isExpanded()) {
                    arrow.setRotate(0);
                    expandedAnimation.play();
                } else {
                    arrow.setRotate(90);
                    collapsedAnimation.play();
                }
                expandTriggered = false;
            } else {
                if (getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()).isExpanded()) {
                    if (!expandedAnimation.getStatus().equals(Status.RUNNING))
                        arrow.setRotate(90);
                } else {
                    if (!collapsedAnimation.getStatus().equals(Status.RUNNING))
                        arrow.setRotate(0);
                }
            }
        }
    }
}
Also used : Node(javafx.scene.Node) RecursiveTreeObject(com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)

Example 2 with RecursiveTreeObject

use of com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject in project JFoenix by jfoenixadmin.

the class JFXTreeTableView method buildGroupedRoot.

/*
	 * this method is used to update tree items and set the new root 
	 * after grouping the data model
	 */
private void buildGroupedRoot(Map groupedItems, RecursiveTreeItem parent, int groupIndex) {
    boolean setRoot = false;
    if (parent == null) {
        parent = new RecursiveTreeItem<>(new RecursiveTreeObject(), RecursiveTreeObject::getChildren);
        setRoot = true;
    }
    for (Object key : groupedItems.keySet()) {
        RecursiveTreeObject groupItem = new RecursiveTreeObject<>();
        groupItem.setGroupedValue(key);
        groupItem.setGroupedColumn(groupOrder.get(groupIndex));
        RecursiveTreeItem node = new RecursiveTreeItem<>(groupItem, RecursiveTreeObject::getChildren);
        // TODO: need to be removed once the selection issue is fixed
        node.expandedProperty().addListener((o, oldVal, newVal) -> {
            getSelectionModel().clearSelection();
        });
        parent.originalItems.add(node);
        parent.getChildren().add(node);
        Object children = groupedItems.get(key);
        if (children instanceof List) {
            node.originalItems.addAll((List) children);
            node.getChildren().addAll((List) children);
        } else if (children instanceof Map) {
            buildGroupedRoot((Map) children, node, groupIndex + 1);
        }
    }
    // update ui
    if (setRoot) {
        final RecursiveTreeItem<S> newParent = parent;
        JFXUtilities.runInFX(() -> {
            ArrayList<TreeTableColumn<S, ?>> sortOrder = new ArrayList<>();
            sortOrder.addAll(getSortOrder());
            setRoot(newParent);
            getSortOrder().addAll(sortOrder);
            getSelectionModel().select(0);
        });
    }
}
Also used : RecursiveTreeObject(com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject) ObservableList(javafx.collections.ObservableList) RecursiveTreeObject(com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)

Example 3 with RecursiveTreeObject

use of com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject in project JFoenix by jfoenixadmin.

the class TreeTableDemo method start.

@Override
public void start(Stage primaryStage) throws Exception {
    try {
        JFXTreeTableColumn<User, String> deptColumn = new JFXTreeTableColumn<>("Department");
        deptColumn.setPrefWidth(150);
        deptColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
            if (deptColumn.validateValue(param))
                return param.getValue().getValue().department;
            else
                return deptColumn.getComputedValue(param);
        });
        JFXTreeTableColumn<User, String> empColumn = new JFXTreeTableColumn<>("Employee");
        empColumn.setPrefWidth(150);
        empColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
            if (empColumn.validateValue(param))
                return param.getValue().getValue().userName;
            else
                return empColumn.getComputedValue(param);
        });
        JFXTreeTableColumn<User, String> ageColumn = new JFXTreeTableColumn<>("Age");
        ageColumn.setPrefWidth(150);
        ageColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<User, String> param) -> {
            if (ageColumn.validateValue(param))
                return param.getValue().getValue().age;
            else
                return ageColumn.getComputedValue(param);
        });
        ageColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
        ageColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
            ((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).age.set(t.getNewValue());
        });
        empColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
        empColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
            ((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).userName.set(t.getNewValue());
        });
        deptColumn.setCellFactory((TreeTableColumn<User, String> param) -> new GenericEditableTreeTableCell<User, String>(new TextFieldEditorBuilder()));
        deptColumn.setOnEditCommit((CellEditEvent<User, String> t) -> {
            ((User) t.getTreeTableView().getTreeItem(t.getTreeTablePosition().getRow()).getValue()).department.set(t.getNewValue());
        });
        // data
        ObservableList<User> users = FXCollections.observableArrayList();
        users.add(new User("Computer Department", "23", "CD 1"));
        users.add(new User("Sales Department", "22", "Employee 1"));
        users.add(new User("Sales Department", "22", "Employee 2"));
        users.add(new User("Sales Department", "25", "Employee 4"));
        users.add(new User("Sales Department", "25", "Employee 5"));
        users.add(new User("IT Department", "42", "ID 2"));
        users.add(new User("HR Department", "22", "HR 1"));
        users.add(new User("HR Department", "22", "HR 2"));
        for (int i = 0; i < 40000; i++) {
            users.add(new User("HR Department", i % 10 + "", "HR 2" + i));
        }
        for (int i = 0; i < 40000; i++) {
            users.add(new User("Computer Department", i % 20 + "", "CD 2" + i));
        }
        for (int i = 0; i < 40000; i++) {
            users.add(new User("IT Department", i % 5 + "", "HR 2" + i));
        }
        // build tree
        final TreeItem<User> root = new RecursiveTreeItem<User>(users, RecursiveTreeObject::getChildren);
        JFXTreeTableView<User> treeView = new JFXTreeTableView<User>(root);
        treeView.setShowRoot(false);
        treeView.setEditable(true);
        treeView.getColumns().setAll(deptColumn, ageColumn, empColumn);
        FlowPane main = new FlowPane();
        main.setPadding(new Insets(10));
        main.getChildren().add(treeView);
        JFXButton groupButton = new JFXButton("Group");
        groupButton.setOnAction((action) -> {
            new Thread(() -> treeView.group(empColumn)).start();
        });
        main.getChildren().add(groupButton);
        JFXButton unGroupButton = new JFXButton("unGroup");
        unGroupButton.setOnAction((action) -> treeView.unGroup(empColumn));
        main.getChildren().add(unGroupButton);
        JFXTextField filterField = new JFXTextField();
        main.getChildren().add(filterField);
        Label size = new Label();
        filterField.textProperty().addListener((o, oldVal, newVal) -> {
            treeView.setPredicate(user -> user.getValue().age.get().contains(newVal) || user.getValue().department.get().contains(newVal) || user.getValue().userName.get().contains(newVal));
        });
        size.textProperty().bind(Bindings.createStringBinding(() -> treeView.getCurrentItemsCount() + "", treeView.currentItemsCountProperty()));
        main.getChildren().add(size);
        Scene scene = new Scene(main, 475, 500);
        scene.getStylesheets().add(TreeTableDemo.class.getResource("/resources/css/jfoenix-components.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();
    //						ScenicView.show(scene);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) Scene(javafx.scene.Scene) CellEditEvent(javafx.scene.control.TreeTableColumn.CellEditEvent) TextFieldEditorBuilder(com.jfoenix.controls.cells.editors.TextFieldEditorBuilder) TreeTableColumn(javafx.scene.control.TreeTableColumn) FlowPane(javafx.scene.layout.FlowPane) RecursiveTreeObject(com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)

Aggregations

RecursiveTreeObject (com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)3 TextFieldEditorBuilder (com.jfoenix.controls.cells.editors.TextFieldEditorBuilder)1 ObservableList (javafx.collections.ObservableList)1 Insets (javafx.geometry.Insets)1 Node (javafx.scene.Node)1 Scene (javafx.scene.Scene)1 Label (javafx.scene.control.Label)1 TreeTableColumn (javafx.scene.control.TreeTableColumn)1 CellEditEvent (javafx.scene.control.TreeTableColumn.CellEditEvent)1 FlowPane (javafx.scene.layout.FlowPane)1