javafx.scene.control.TreeCell Java Examples

The following examples show how to use javafx.scene.control.TreeCell. 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: TransactionTypeNodeProvider.java    From constellation with Apache License 2.0 7 votes vote down vote up
private void setCellFactory() {
    // A shiny cell factory so the tree nodes show the correct text and graphic.
    treeView.setCellFactory(p -> new TreeCell<SchemaTransactionType>() {
        @Override
        protected void updateItem(final SchemaTransactionType item, boolean empty) {
            super.updateItem(item, empty);
            if (!empty && item != null) {
                setText(item.getName());
                if (item.getColor() != null) {
                    final Rectangle icon = getSquare(item.getColor().getJavaFXColor());
                    icon.setSmooth(true);
                    icon.setCache(true);
                    setGraphic(icon);
                }
            } else {
                setGraphic(null);
                setText(null);
            }
        }
    });
}
 
Example #2
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public int getRowAt(TreeView<?> treeView, Point2D point) {
    if (point == null) {
        return treeView.getSelectionModel().getSelectedIndex();
    }
    point = treeView.localToScene(point);
    int itemCount = treeView.getExpandedItemCount();
    @SuppressWarnings("rawtypes")
    List<TreeCell> cells = new ArrayList<>();
    for (int i = 0; i < itemCount; i++) {
        cells.add(getCellAt(treeView, i));
    }
    TreeCell<?> selected = null;
    for (Node cellNode : cells) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (TreeCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
 
Example #3
Source File: Synchronization.java    From PeerWasp with MIT License 6 votes vote down vote up
private void createTreeView(FileNode fileNode){
		PathItem pathItem = new PathItem(userConfig.getRootPath(), false, fileNode.getUserPermissions());
		SyncTreeItem invisibleRoot = new SyncTreeItem(pathItem);
//		invisibleRoot.setIndependent(true);
	    fileTreeView.setRoot(invisibleRoot);
        fileTreeView.setEditable(false);

        fileTreeView.setCellFactory(new Callback<TreeView<PathItem>, TreeCell<PathItem>>(){
            @Override
            public TreeCell<PathItem> call(TreeView<PathItem> p) {
                return new CustomizedTreeCell(getFileEventManager(),
                		recoverFileHandlerProvider,
                		shareFolderHandlerProvider,
                		forceSyncHandlerProvider);
            }
        });

        fileTreeView.setShowRoot(false);


        addChildrensToTreeView(fileNode);
	}
 
Example #4
Source File: ModFuncTreeCellFactory.java    From erlyberly with GNU General Public License v3.0 6 votes vote down vote up
@Override
public TreeCell<ModFunc> call(TreeView<ModFunc> tree) {
    ModFuncGraphic mfg;

    mfg = new ModFuncGraphic(
        dbgController::toggleTraceModFunc,
        dbgController::isTraced
    );
    mfg.setShowModuleName(isShowModuleName());

    dbgController.addTraceListener((Observable o) -> {
        mfg.onTracesChange();
    });

    return new FXTreeCell<ModFunc>(mfg, mfg);
}
 
Example #5
Source File: TreeViewFactory.java    From ariADDna with Apache License 2.0 6 votes vote down vote up
/**
 * Customizing treeView
 *
 * @param tree treeView
 */
private void setTreeCellFactory(TreeView<SimpleTreeElement> tree) {
    tree.setCellFactory(param -> new TreeCell<SimpleTreeElement>() {
        @Override
        public void updateItem(SimpleTreeElement item, boolean empty) {
            super.updateItem(item, empty);
            //setDisclosureNode(null);

            if (empty) {
                setText("");
                setGraphic(null);
            } else {
                setText(item.getName());
            }
        }

    });

    tree.getSelectionModel().selectedItemProperty()
            .addListener((observable, oldValue, newValue) -> {
                if (newValue != null) {
                    System.out.println(newValue.getValue());
                }
            });
}
 
Example #6
Source File: FunctionStage.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private Node createTree() {
    VBox treeContentBox = new VBox();
    tree.setRoot(functionInfo.getRoot(true));
    tree.setShowRoot(false);
    tree.getSelectionModel().selectedItemProperty().addListener(new TreeViewSelectionChangeListener());
    tree.setCellFactory(new Callback<TreeView<Object>, TreeCell<Object>>() {
        @Override
        public TreeCell<Object> call(TreeView<Object> param) {
            return new FunctionTreeCell();
        }
    });
    filterByName.setOnAction((e) -> {
        tree.setRoot(functionInfo.refreshNode(filterByName.isSelected()));
        expandAll();
    });
    filterByName.setSelected(true);
    expandAll();
    treeContentBox.getChildren().addAll(topButtonBar, tree, filterByName);
    VBox.setVgrow(tree, Priority.ALWAYS);
    return treeContentBox;
}
 
Example #7
Source File: NavigationPresenter.java    From PreferencesFX with Apache License 2.0 6 votes vote down vote up
/**
 * Makes the TreeItems' text update when the description of a Category changes (due to i18n).
 */
public void setupCellValueFactory() {
  navigationView.treeView.setCellFactory(param -> new TreeCell<Category>() {
    @Override
    protected void updateItem(Category category, boolean empty) {
      super.updateItem(category, empty);
      textProperty().unbind();
      if (empty || category == null) {
        setText(null);
        setGraphic(null);
      } else {
        textProperty().bind(category.descriptionProperty());
        setGraphic(category.getItemIcon());
      }
    }
  });
}
 
Example #8
Source File: DnDCellFactory.java    From milkman with MIT License 6 votes vote down vote up
private void drop(DragEvent event, TreeCell<Node> treeCell, TreeView<Node> treeView) {
  	
      try {
	Dragboard db = event.getDragboard();
	boolean success = false;
	if (!db.hasContent(JAVA_FORMAT)) return;

	TreeItem<Node> thisItem = treeCell.getTreeItem();
	RequestContainer draggedRequest = (RequestContainer) draggedItem.getValue().getUserData();
	// remove from previous location
	removeFromPreviousContainer(draggedRequest);
	
	addToNewLocation(treeView, thisItem, draggedRequest);
	treeView.getSelectionModel().select(draggedItem);
	event.setDropCompleted(success);
} catch (Throwable t) {
	t.printStackTrace();
}
  }
 
Example #9
Source File: DnDCellFactory.java    From milkman with MIT License 6 votes vote down vote up
private void dragOver(DragEvent event, TreeCell<Node> treeCell, TreeView<Node> treeView) {
    if (!event.getDragboard().hasContent(JAVA_FORMAT)) return;
    TreeItem<Node> thisItem = treeCell.getTreeItem();

    // can't drop on itself
    if (draggedItem == null || thisItem == null || thisItem == draggedItem) return;
    // ignore if this is the root
    if (draggedItem.getParent() == null) {
        clearDropLocation();
        return;
    }

    event.acceptTransferModes(TransferMode.MOVE);
    if (!Objects.equals(dropZone, treeCell)) {
        clearDropLocation();
        this.dropZone = treeCell;
        dropZone.setStyle(DROP_HINT_STYLE);
    }
}
 
Example #10
Source File: TreeViewWrapper.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns true if the item at the given index
 * is visible in the TreeView.
 */
boolean isIndexVisible(int index) {
    if (reflectionImpossibleWarning) {
        return false;
    }

    if (virtualFlow == null && wrapped.getSkin() == null) {
        return false;
    } else if (virtualFlow == null && wrapped.getSkin() != null) {
        // the flow is cached, so the skin must not be changed
        virtualFlow = getVirtualFlow(wrapped.getSkin());
    }

    if (virtualFlow == null) {
        return false;
    }

    Optional<TreeCell<T>> first = getFirstVisibleCell();
    Optional<TreeCell<T>> last = getLastVisibleCell();

    return first.isPresent()
            && last.isPresent()
            && first.get().getIndex() < index
            && last.get().getIndex() > index;
}
 
Example #11
Source File: DnDCellFactory.java    From milkman with MIT License 6 votes vote down vote up
private void dragDetected(MouseEvent event, TreeCell<Node> treeCell, TreeView<Node> treeView) {
    draggedItem = treeCell.getTreeItem();

    // root can't be dragged
    if (draggedItem.getParent() == null) return;
    
    //only Requests can be dragged for now:
    if (!(draggedItem.getValue().getUserData() instanceof RequestContainer))
    	return;
    
    Dragboard db = treeCell.startDragAndDrop(TransferMode.MOVE);

    ClipboardContent content = new ClipboardContent();
    content.put(JAVA_FORMAT, serialize(draggedItem.getValue().getUserData()));
    db.setContent(content);
    db.setDragView(treeCell.snapshot(null, null));
    event.consume();
}
 
Example #12
Source File: TextTreeSection.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
public void updateCell(TreeCell cell){
    cell.setOnMouseClicked(null);

    cell.setMaxHeight(30);
    cell.setStyle("-fx-padding: 6 6 6 2; -fx-background-color: " + StyleManager.getHexAccentColor() + ";");
    cell.setContextMenu(menu);

    cell.setGraphic(pane);
}
 
Example #13
Source File: TreeViewWrapper.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Optional<TreeCell<T>> getCellFromAccessor(Method accessor) {
    return Optional.ofNullable(accessor).map(m -> {
        try {
            @SuppressWarnings("unchecked")
            TreeCell<T> cell = (TreeCell<T>) m.invoke(virtualFlow);
            return cell;
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    });
}
 
Example #14
Source File: ProjectFileTreeView.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private TreeCell<File> createCell(TreeView<File> treeView) {
	FileTreeCell treeCell = new FileTreeCell();
	treeCell.setOnDragDetected(event -> {
		TreeItem<File> draggedItem = treeCell.getTreeItem();
		Dragboard db = treeCell.startDragAndDrop(TransferMode.COPY);

		ClipboardContent content = new ClipboardContent();
		content.putString(draggedItem.getValue().getAbsolutePath());
		content.put(DataFormat.FILES, Collections.singletonList(draggedItem.getValue()));
		db.setContent(content);

		event.consume();
	});
	return treeCell;
}
 
Example #15
Source File: EditableTreeCellFactory.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
EditableTreeCellFactory(@NotNull EditableTreeView<Tv, Td> treeView, @Nullable TreeCellSelectionUpdate treeCellSelectionUpdate) {
	this.treeCellSelectionUpdate = treeCellSelectionUpdate;
	this.treeView = treeView;
	this.setEditable(true);
	// first method called when the user clicks and drags a tree item
	TreeCell<Td> myTreeCell = this;

	//		addDragListeners(treeView, myTreeCell);
}
 
Example #16
Source File: RFXComponentTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TreeCell<?> getCellAt(TreeView<?> treeView, int index) {
    Set<Node> lookupAll = treeView.lookupAll(".tree-cell");
    for (Node node : lookupAll) {
        TreeCell<?> cell = (TreeCell<?>) node;
        if (cell.getIndex() == index) {
            return cell;
        }
    }
    return null;
}
 
Example #17
Source File: RFXComponentTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public Point2D getPoint(TreeView<?> treeView, int index) {
    Set<Node> cells = treeView.lookupAll(".tree-cell");
    for (Node node : cells) {
        TreeCell<?> cell = (TreeCell<?>) node;
        if (cell.getIndex() == index) {
            Bounds bounds = cell.getBoundsInParent();
            return cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
        }
    }
    return null;
}
 
Example #18
Source File: RFXTreeView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private String getTreeCellValue(TreeView<?> treeView, int index) {
    if (index == -1) {
        return null;
    }
    TreeCell<?> treeCell = getCellAt(treeView, index);
    RFXComponent cellComponent = getFinder().findRCellComponent(treeCell, null, recorder);
    return cellComponent == null ? null : cellComponent.getValue();
}
 
Example #19
Source File: JavaFXTreeViewNodeElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Node getTextObj(TreeCell<?> cell) {
    for (Node child : cell.getChildrenUnmodifiable()) {
        if (child instanceof Text) {
            return child;
        }
    }
    return cell;
}
 
Example #20
Source File: JavaFXTreeViewNodeElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((TreeCell<?>) cell);
    Point2D targetXY = node.localToScene(xoffset, yoffset);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
Example #21
Source File: JavaFXTreeViewNodeElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private Node getEditor() {
    TreeCell cell = (TreeCell) getPseudoComponent();
    TreeView treeView = (TreeView) getComponent();
    treeView.edit(cell.getTreeItem());
    Node cellComponent = cell.getGraphic();
    cellComponent.getProperties().put("marathon.celleditor", true);
    cellComponent.getProperties().put("marathon.cell", cell);
    return cellComponent;
}
 
Example #22
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Set<Node> getTreeCells(TreeView<?> treeView) {
    Set<Node> l = treeView.lookupAll("*");
    Set<Node> r = new HashSet<>();
    for (Node node : l) {
        if (node instanceof TreeCell<?>) {
            if (!((TreeCell<?>) node).isEmpty())
                r.add(node);
        }
    }
    return r;
}
 
Example #23
Source File: TextTreeItem.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
public void updateCell(TreeCell<String> cell){ // Réattribue une cell à la pane

		if(cell == null) return;
		if(name.getText().isEmpty()) updateGraphic();

		name.setFill(StyleManager.convertColor(color.get()));
		rect.setFill(StyleManager.convertColor(Color.WHITE));

		cell.setGraphic(pane);
		cell.setStyle(null);
		cell.setStyle("-fx-padding: 0 -35;");
		cell.setContextMenu(menu);
		cell.setOnMouseClicked(onMouseCLick);

	}
 
Example #24
Source File: ResourceView.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ResourceView(IResourceActionSource source, Resource root, IResourceActionHandler handler,
        IResourceChangeListener listener) {
    this.source = source;
    this.handler = handler;
    setEditable(true);
    setRoot(root);
    getRoot().addEventHandler(ResourceModificationEvent.ANY, (event) -> {
        if (event.getEventType() == ResourceModificationEvent.DELETE) {
            listener.deleted(source, event.getResource());
        }
        if (event.getEventType() == ResourceModificationEvent.UPDATE) {
            listener.updated(source, event.getResource());
        }
        if (event.getEventType() == ResourceModificationEvent.MOVED) {
            listener.moved(source, event.getFrom(), event.getTo());
        }
        if (event.getEventType() == ResourceModificationEvent.COPIED) {
            listener.copied(source, event.getFrom(), event.getTo());
        }
    });
    setContextMenu(contextMenu);
    setContextMenuItems();
    getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    getSelectionModel().getSelectedItems().addListener(new ListChangeListener<TreeItem<Resource>>() {
        @Override
        public void onChanged(Change<? extends TreeItem<Resource>> c) {
            setContextMenuItems();
        }
    });
    Callback<TreeView<Resource>, TreeCell<Resource>> value = new Callback<TreeView<Resource>, TreeCell<Resource>>() {
        @Override
        public TreeCell<Resource> call(TreeView<Resource> param) {
            return new TextFieldTreeCellImpl();
        }
    };
    setCellFactory(value);
}
 
Example #25
Source File: MarathonFileChooser.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void initTreeView() {
    parentTreeView.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {
        @Override
        public TreeCell<File> call(TreeView<File> param) {
            return new ParentFileCell();
        }
    });
    parentTreeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newVlaue) -> {
        TreeItem<File> selectedItem = parentTreeView.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            newFolderButton.setDisable(false);
            fileNameBox.setEditable(true);
            File selectedFile = selectedItem.getValue();
            fillUpChildren(selectedFile);
        } else {
            fileNameBox.setEditable(false);
            newFolderButton.setDisable(true);
            childrenListView.getItems().clear();
        }
    });
    File root = fileChooserInfo.getRoot();
    TreeItem<File> rootItem = new TreeItem<>(root);
    parentTreeView.setRoot(rootItem);
    rootItem.setExpanded(true);
    parentTreeView.getSelectionModel().select(0);
    populateChildren(root, rootItem);
}
 
Example #26
Source File: JavaFXTreeCellElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public String _getValue() {
    TreeCell<?> cell = (TreeCell<?>) getComponent();
    Node graphic = cell.getGraphic();
    JavaFXElement cellElement = (JavaFXElement) JavaFXElementFactory.createElement(graphic, driver, window);
    if (graphic != null && cellElement != null) {
        return cellElement._getValue();
    }
    return super._getValue();
}
 
Example #27
Source File: GradeTreeView.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
public GradeTreeView(LBGradeTab gradeTab){

        disableProperty().bind(MainWindow.mainScreen.statusProperty().isNotEqualTo(MainScreen.Status.OPEN));
        setBackground(new Background(new BackgroundFill(Color.rgb(244, 244, 244), CornerRadii.EMPTY, Insets.EMPTY)));
        prefHeightProperty().bind(gradeTab.pane.heightProperty().subtract(layoutYProperty()));
        prefWidthProperty().bind(gradeTab.pane.widthProperty());

        setCellFactory(new Callback<>() {
            @Override
            public TreeCell<String> call(TreeView<String> param) {
                return new TreeCell<>() {
                    @Override protected void updateItem(String item, boolean empty){
                        super.updateItem(item, empty);

                        // Enpty cell or String Data
                        if(empty || item != null){
                            setGraphic(null);
                            setStyle(null);
                            setContextMenu(null);
                            setOnMouseClicked(null);
                            setTooltip(null);
                            return;
                        }
                        // TreeGradeData
                        if(getTreeItem() instanceof GradeTreeItem){
                            ((GradeTreeItem) getTreeItem()).updateCell(this);
                            return;
                        }
                        // Other
                        setStyle(null);
                        setGraphic(null);
                        setContextMenu(null);
                        setOnMouseClicked(null);
                        setTooltip(null);
                    }
                };
            }
        });
    }
 
Example #28
Source File: TreeFactoryGen.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
@Override
public TreeCell<E> call(javafx.scene.control.TreeView<E> view) {
	return this.factory.getNewInstance();
}
 
Example #29
Source File: CoursesTreeView.java    From iliasDownloaderTool with GNU General Public License v2.0 4 votes vote down vote up
public CoursesTreeView(Dashboard dashboard) {
	super();
	setId("coursesTree");
	setMinWidth(270);
	this.dashboard = dashboard;
	rootItem = new TreeItem<IliasTreeNode>(new IliasFolder("Übersicht", null, null));
	rootItem.setExpanded(true);
	setRoot(rootItem);
	setShowRoot(false);
	getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
	menu = new ContextMenu();
	setCellFactory(new Callback<TreeView<IliasTreeNode>, TreeCell<IliasTreeNode>>() {

		@Override
		public TreeCell<IliasTreeNode> call(TreeView<IliasTreeNode> arg0) {
			return new IliasTreeCell();
		}
	});

	setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			menu.hide();
			final TreeItem<IliasTreeNode> selectedItem = getSelectionModel().getSelectedItem();
			if (selectedItem == null) {
				return;
			}
			if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
				if (selectedItem.getValue() instanceof IliasForum) {
					openForum();
					return;
				} else if (selectedItem.getValue() instanceof IliasFile) {
					if (Settings.getInstance().getFlags().isUserLoggedIn()) {
						new Thread(new IliasPdfDownloadCaller(
								((CoursesTreeView) event.getSource()).getSelectionModel()
										.getSelectedItem().getValue())).start();
					}
				}
			} else if (event.getButton() == MouseButton.SECONDARY) {
				showContextMenu(getSelectionModel().getSelectedItems(), event);
			}
		};
	});
}
 
Example #30
Source File: SortPanelTreeItem.java    From PDF4Teachers with Apache License 2.0 4 votes vote down vote up
public void updateCell(TreeCell cell) {
    cell.setContextMenu(null);
    cell.setOnMouseClicked(null);
    cell.setStyle("-fx-padding: 0 0 0 -40; -fx-margin: 0; -fx-background-color: " + StyleManager.getHexAccentColor() + ";");
    cell.setGraphic(pane);
}