/** * 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()); } }); }
/** * 点击处理方法. * * @param treeView treeView */ @Override protected void setAction(TreeView treeView) { super.setOnAction( (event) -> { TreeItem<Label> item = (TreeItem) treeView.getSelectionModel().getSelectedItem(); String flag = item.getValue().getAccessibleHelp(); if ("link".equals(flag)) { String poolId = item.getValue().getAccessibleText(); ConnectPanel connectPanel = new ConnectPanel(); connectPanel.isNewLink(false); connectPanel.showConnectPanel(poolId); } } ); }
public TreeViewSample() { final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList( new TreeItem<String>("Child Node 1"), new TreeItem<String>("Child Node 2"), new TreeItem<String>("Child Node 3"))); treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList( new TreeItem<String>("Child Node 4"), new TreeItem<String>("Child Node 5"), new TreeItem<String>("Child Node 6"), new TreeItem<String>("Child Node 7"), new TreeItem<String>("Child Node 8"), new TreeItem<String>("Child Node 9"), new TreeItem<String>("Child Node 10"), new TreeItem<String>("Child Node 11"), new TreeItem<String>("Child Node 12"))); final TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); getChildren().add(treeView); }
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); }
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; }
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(); }
@Override public List<IJavaFXElement> getByPseudoElement(String selector, Object[] params) { if (selector.equals("select-by-properties")) { return findNodeByProperties(new JSONObject((String) params[0])); } else if (selector.equals("root")) { return Arrays.asList(new JavaFXTreeViewNodeElement(this, 0)); } else if (selector.equals("nth-node")) { return Arrays.asList(new JavaFXTreeViewNodeElement(this, ((Integer) params[0]).intValue() - 1)); } else if (selector.equals("all-nodes")) { TreeView<?> treeView = (TreeView<?>) getComponent(); ArrayList<IJavaFXElement> r = new ArrayList<>(); int nrows = treeView.getExpandedItemCount(); for (int i = 0; i < nrows; i++) { r.add(new JavaFXTreeViewNodeElement(this, i)); } return r; } return super.getByPseudoElement(selector, params); }
@SuppressWarnings("unchecked") private boolean setSelectionPath(String value) { TreeView<?> treeView = (TreeView<?>) getComponent(); JSONArray pathElements = new JSONArray(value); List<TreeItem<?>> paths = new ArrayList<>(); for (int i = 0; i < pathElements.length(); i++) { paths.add(getPath(treeView, pathElements.getString(i))); } treeView.getSelectionModel().clearSelection(); for (@SuppressWarnings("rawtypes") TreeItem treeItem : paths) { if (getVisibleCellAt(treeView, treeItem) == null) { treeView.scrollTo(treeView.getRow(treeItem)); } treeView.getSelectionModel().select(treeItem); } return true; }
@Test public void selectTreeItemCheckBoxSelectedSelected() { TreeView<?> treeViewNode = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeViewNode.getTreeItem(2); treeItem.setSelected(true); JSONObject o = new JSONObject(); o.put("select", "/Root node/Child Node 2"); IJavaFXElement item = treeView.findElementByCssSelector(".::select-by-properties('" + o.toString() + "')"); IJavaFXElement cb = item.findElementByCssSelector(".::editor"); cb.marathon_select("Child Node 2:checked"); new Wait("Wait for tree item check box to be selected") { @Override public boolean until() { String selected = cb.getAttribute("selected"); return selected.equals("true"); } }; }
@Test public void selectTreeItemCheckBoxSelectedNotSelected() { TreeView<?> treeViewNode = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeViewNode.getTreeItem(2); treeItem.setSelected(true); JSONObject o = new JSONObject(); o.put("select", "/Root node/Child Node 2"); IJavaFXElement item = treeView.findElementByCssSelector(".::select-by-properties('" + o.toString() + "')"); IJavaFXElement cb = item.findElementByCssSelector(".::editor"); cb.marathon_select("Child Node 2:unchecked"); new Wait("Wait for tree item check box to be deselected") { @Override public boolean until() { String selected = cb.getAttribute("selected"); return selected.equals("false"); } }; }
public TextFieldTreeViewSample() { final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 1"), new TreeItem<String>("Child Node 2"), new TreeItem<String>("Child Node 3"))); treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 4"), new TreeItem<String>("Child Node 5"), new TreeItem<String>("Child Node 6"), new TreeItem<String>("Child Node 7"), new TreeItem<String>("Child Node 8"), new TreeItem<String>("Child Node 9"), new TreeItem<String>("Child Node 10"), new TreeItem<String>("Child Node 11"), new TreeItem<String>("Child Node 12"))); final TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); treeView.setEditable(true); treeView.setCellFactory(TextFieldTreeCell.forTreeView()); getChildren().add(treeView); }
public ChoiceBoxTreeViewSample() { final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 1"), new TreeItem<String>("Option 2"), new TreeItem<String>("Option 3"))); treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 4"), new TreeItem<String>("Option 5"), new TreeItem<String>("Option 6"))); final TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); treeView.setEditable(true); treeView.setCellFactory(ChoiceBoxTreeCell.forTreeView(items)); getChildren().add(treeView); }
public ComboBoxTreeViewSample() { final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 1"), new TreeItem<String>("Option 2"), new TreeItem<String>("Option 3"))); treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(new TreeItem<String>("Option 4"), new TreeItem<String>("Option 5"), new TreeItem<String>("Option 6"))); final TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); treeView.setEditable(true); treeView.setCellFactory(ComboBoxTreeCell.forTreeView(items)); getChildren().add(treeView); }
public CheckBoxTreeViewSample() { final CheckBoxTreeItem<String> treeRoot = new CheckBoxTreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList(new CheckBoxTreeItem<String>("Child Node 1"), new CheckBoxTreeItem<String>("Child Node 2"), new CheckBoxTreeItem<String>("Child Node 3"))); treeRoot.getChildren().get(2).getChildren() .addAll(Arrays.asList(new CheckBoxTreeItem<String>("Child Node 4"), new CheckBoxTreeItem<String>("Child Node 5"), new CheckBoxTreeItem<String>("Child Node 6"), new CheckBoxTreeItem<String>("Child Node 7"), new TreeItem<String>("Child Node 8"), new CheckBoxTreeItem<String>("Child Node 9"), new CheckBoxTreeItem<String>("Child Node 10"), new CheckBoxTreeItem<String>("Child Node 11"), new CheckBoxTreeItem<String>("Child Node 12"))); final TreeView treeView = new TreeView(); treeView.setCellFactory(CheckBoxTreeCell.forTreeView()); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); getChildren().add(treeView); }
public TreeViewSample1() { final TreeItem<String> treeRoot = new TreeItem<String>("Root node"); treeRoot.getChildren().addAll(Arrays.asList(new TreeItem<String>("Child Node 1"), new TreeItem<String>("Child Node 2"), new TreeItem<String>("Child Node 3"))); treeRoot.getChildren().get(2).getChildren() .addAll(Arrays.asList(new TreeItem<String>("Child Node 4"), new TreeItem<String>("Child Node 5"), new TreeItem<String>("Child Node 6"), new TreeItem<String>("Child Node 7"), new TreeItem<String>( "Child Node 8"), new TreeItem<String>("Child Node 9"), new TreeItem<String>("Child Node 10"), new TreeItem<String>("Child Node 11"), new TreeItem<String>("Child Node 12"), new TreeItem<String>("Child Node 13"), new TreeItem<String>("Child Node 14"), new TreeItem<String>("Child Node 15"), new TreeItem<String>("Child Node 16"), new TreeItem<String>("Child Node 17"), new TreeItem<String>("Child Node 18"), new TreeItem<String>("Child Node 19"), new TreeItem<String>("Child Node 20"), new TreeItem<String>("Child Node 21"), new TreeItem<String>("Child Node 22"), new TreeItem<String>("Child Node 23"), new TreeItem<String>("Child Node 24"))); final TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeRoot.setExpanded(true); getChildren().add(treeView); }
@Test public void getText() { @SuppressWarnings("rawtypes") TreeView treeView = (TreeView) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(new Runnable() { @Override public void run() { RFXTreeView rTreeView = new RFXTreeView(treeView, null, null, lr); treeView.getSelectionModel().select(2); rTreeView.focusLost(new RFXTreeView(null, null, null, null)); text.add(rTreeView.getAttribute("text")); } }); new Wait("Waiting for tree text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("[\"/Root node/Child Node 2\"]", text.get(0)); }
@Test public void getTextForMultipleSelection() { @SuppressWarnings("rawtypes") TreeView treeView = (TreeView) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(new Runnable() { @Override public void run() { RFXTreeView rTreeView = new RFXTreeView(treeView, null, null, lr); @SuppressWarnings("rawtypes") MultipleSelectionModel selectionModel = treeView.getSelectionModel(); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.selectIndices(2, 3); rTreeView.focusLost(new RFXTreeView(null, null, null, null)); text.add(rTreeView.getAttribute("text")); } }); new Wait("Waiting for tree text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("[\"/Root node/Child Node 2\",\"/Root node/Child Node 3\"]", text.get(0)); }
@Test public void select() { TreeView<?> treeView = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { Point2D point = getPoint(treeView, 1); RFXTreeView rfxListView = new RFXTreeView(treeView, null, point, lr); rfxListView.focusGained(rfxListView); CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeView.getTreeItem(1); treeItem.setSelected(true); rfxListView.focusLost(rfxListView); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Child Node 1:checked", recording.getParameters()[0]); }
@Test public void selectSelectedTreeItemCheckBox() { TreeView<?> treeView = (TreeView<?>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(new Runnable() { @Override public void run() { Point2D point = getPoint(treeView, 1); RFXTreeView rfxListView = new RFXTreeView(treeView, null, point, lr); CheckBoxTreeItem<?> treeItem = (CheckBoxTreeItem<?>) treeView.getTreeItem(1); treeItem.setSelected(true); rfxListView.focusGained(rfxListView); treeItem.setSelected(false); rfxListView.focusLost(rfxListView); } }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Child Node 1:unchecked", recording.getParameters()[0]); }
@Test public void select() { @SuppressWarnings("unchecked") TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") TextFieldTreeCell<String> cell = (TextFieldTreeCell<String>) getCellAt(treeView, 2); Point2D point = getPoint(treeView, 2); RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr); rfxTreeView.focusGained(rfxTreeView); cell.startEdit(); cell.updateItem("Child node 4 Modified", false); cell.commitEdit("Child node 4 Modified"); rfxTreeView.focusLost(rfxTreeView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Child node 4 Modified", recording.getParameters()[0]); }
@Test public void select() { @SuppressWarnings("unchecked") TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") ChoiceBoxTreeCell<String> cell = (ChoiceBoxTreeCell<String>) getCellAt(treeView, 1); Point2D point = getPoint(treeView, 1); RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr); rfxTreeView.focusGained(rfxTreeView); cell.startEdit(); cell.updateItem("Option 5", false); cell.commitEdit("Option 5"); rfxTreeView.focusLost(rfxTreeView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Option 5", recording.getParameters()[0]); }
@Test public void select() { @SuppressWarnings("unchecked") TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") ComboBoxTreeCell<String> cell = (ComboBoxTreeCell<String>) getCellAt(treeView, 1); Point2D point = getPoint(treeView, 1); RFXTreeView rfxTreeView = new RFXTreeView(treeView, null, point, lr); rfxTreeView.focusGained(rfxTreeView); cell.startEdit(); cell.updateItem("Option 3", false); cell.commitEdit("Option 3"); rfxTreeView.focusLost(rfxTreeView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Option 3", recording.getParameters()[0]); }
@Test public void selectEditable() { @SuppressWarnings("unchecked") TreeView<String> treeView = (TreeView<String>) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") ComboBoxTreeCell<String> cell = (ComboBoxTreeCell<String>) getCellAt(treeView, 1); cell.setComboBoxEditable(true); Point2D point = getPoint(treeView, 1); RFXTreeView rfxtreeView = new RFXTreeView(treeView, null, point, lr); rfxtreeView.focusGained(rfxtreeView); cell.startEdit(); cell.updateItem("Option 5", false); cell.commitEdit("Option 5"); rfxtreeView.focusLost(rfxtreeView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Option 5", recording.getParameters()[0]); }
@Override public void CreateTreeView(TreeView<String> treeview){ File[] sysroots = File.listRoots(); TreeItem<String> ThisPc = new TreeItem<>("This PC", new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/pc.png")))); TreeItem<String>[] drives = new TreeItem[sysroots.length]; for(int i=0; i<sysroots.length;i++){ drives[i] = new TreeItem<>(sysroots[i].getAbsolutePath(), new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/thumb_Hard_Drive.png")))); try{ drives[i].getChildren().addAll(TreeCreate(sysroots[i])); }catch(NullPointerException x){System.out.println("Exeption x detected: "+x.fillInStackTrace()+drives[i].toString());} finally { ThisPc.getChildren().add(drives[i]); } } treeview.setRoot(ThisPc); }
public TreeView<Concept> getTreeView() { if (treeView == null) { TreeCellFactory cellFactory = new TreeCellFactory(conceptService); treeView = new TreeView<>(); treeView.getStyleClass().add("concepttree-treeview"); treeView.setEditable(false); treeView.setCellFactory(tv -> cellFactory.build()); treeView.setContextMenu(getContextMenu()); conceptService.findRoot() .thenApply(root -> { Platform.runLater(() -> { TreeItem<Concept> rootItem = buildTreeItem(root, null); treeView.setRoot(rootItem); }); return null; }); } return treeView; }
private Node createFilteredTree() { FilterableTreeItem<Actor> root = getTreeModel(); root.predicateProperty().bind(Bindings.createObjectBinding(() -> { if (filterField.getText() == null || filterField.getText().isEmpty()) return null; return TreeItemPredicate.create(actor -> actor.toString().contains(filterField.getText())); }, filterField.textProperty())); TreeView<Actor> treeView = new TreeView<>(root); treeView.setShowRoot(false); TitledPane pane = new TitledPane("Filtered TreeView", treeView); pane.setCollapsible(false); pane.setMaxHeight(Double.MAX_VALUE); return pane; }
@Override public TreeCell<V> call(TreeView<V> param) { TextFieldTreeCell<V> textFieldTreeCell = new TextFieldTreeCell<V>(treeItemStringConverter) { @Override public void updateItem(V item, boolean empty) { super.updateItem(item, empty); if (empty) { setGraphic(null); } else { ObservableList<File> items = item.getItems(); if (!items.isEmpty()) { File file = items.get(0); setGraphic(new FileIconImageView(file)); } } } }; return textFieldTreeCell; }
public FxControlsTreeItem(TreeView<Node> tv) { this.tv = tv; tv.setCellFactory(param -> { TreeCell<Node> treeCell = new TextFieldTreeCell<Node>(new StringConverter<Node>() { @Override public String toString(Node n) { return getName(n); } @Override public Node fromString(String string) { return null; } }); return treeCell; }); }
@Override public void duplicate(@NotNull TreeView<? extends TreeItemEntry> treeView) { String newName = myArmaControl.getClassName() + "_copy1"; int i = 2; Project p = Project.getCurrentProject(); while (p.findControlClassByName(newName) != null) { newName = myArmaControl.getClassName() + "_copy" + i; i++; } ArmaControl dup = myArmaControl.duplicate(newName, p); if (myArmaControl.getHolder() == myArmaControl.getDisplay()) { if (treeView == ArmaDialogCreator.getCanvasView().getBackgroundControlTreeView()) { myArmaControl.getDisplay().getBackgroundControls().add(dup); return; } } myArmaControl.getHolder().getControls().add(dup); }
protected static void clickOnFirstCell(final Wrap<? extends Control> testedControl) { String item = new GetAction<String>() { @Override public void run(Object... os) throws Exception { TreeItem root; Control control = testedControl.getControl(); if (control instanceof TreeView) { root = ((TreeView) control).getRoot(); } else { root = ((TreeTableView) control).getRoot(); } setResult(root.getValue().toString()); } }.dispatch(Root.ROOT.getEnvironment(), testedControl); Wrap<Text> cellWrap = getCellWrap(testedControl, item); cellWrap.as(Showable.class).shower().show(); cellWrap.mouse().click(1, cellWrap.getClickPoint(), Mouse.MouseButtons.BUTTON1); }
protected static Wrap<Text> getCellWrap(final Wrap<? extends Control> testedControl, final Integer index) { final String content = new GetAction<String>() { @Override public void run(Object... os) throws Exception { Control control = testedControl.getControl(); TreeItem item; if (control instanceof TreeView) { item = ((TreeView) control).getTreeItem(index); } else { item = ((TreeTableView) control).getTreeItem(index); } setResult(item.getValue().toString()); } }.dispatch(Root.ROOT.getEnvironment()); scrollTo(testedControl, 0, index); return getCellWrap(testedControl, content); }
protected static HashSet<Point> getSelected(final Wrap<? extends Control> testedControl) { return new GetAction<HashSet<Point>>() { @Override public void run(Object... parameters) throws Exception { HashSet<Point> selected = new HashSet<Point>(); final Control control = testedControl.getControl(); MultipleSelectionModel model; if (control instanceof TreeView) { model = ((TreeView) control).getSelectionModel(); } else { model = ((TreeTableView) control).getSelectionModel(); } for (Object obj : model.getSelectedIndices()) { Integer pos = (Integer) obj; selected.add(new Point(-1, pos)); } setResult(selected); } }.dispatch(Root.ROOT.getEnvironment()); }
@Override public void start(Stage stage) throws Exception { final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); final TreeView<Data> treeView = new TreeView<>(); treeView.setEditable(true); treeView.setId(TREE_VIEW_ID); treeView.setRoot(new TreeItem(new Data("0"))); addContent(treeView.getRoot(), 2, 4, "0"); treeView.setCellFactory(p -> new TextFieldTreeCell()); VBox vBox = new VBox(); vBox.getChildren().setAll(treeView); Scene scene = new Scene(vBox, 800, 500); stage.setScene(scene); stage.show(); }
public static synchronized void setNowObject(Object obj, Field f){ if (!start) start(); while (!start) Animation.sleepSeconds(1); PlatformImpl.startup(() -> {}); Platform.runLater(() -> { TreeItem<String> rootItem = new TreeItem<String>((f == null ? "" : f.getName()) + obj.getClass().getName() + " : " + obj); TreeView<String> tree = new TreeView<String> (rootItem); rootItem.setExpanded(true); try { addChildren(obj, obj, f, null, rootItem); } catch(Exception e){e.printStackTrace();} StackPane root = new StackPane(); root.getChildren().add(tree); stage.setScene(new Scene(root)); }); }
public void displayScreen() { Stage window = new Stage(); BorderPane layout = new BorderPane(); TreeItem<String> pref_general = new TreeItem<>("Settings"); TreeItem<String> pref_general_software = new TreeItem<>("Software settings"); TreeItem<String> pref_general_hotel = new TreeItem<>("Hotel settings"); pref_general.getChildren().addAll(pref_general_software, pref_general_hotel); pref_general.setExpanded(true); TreeView<String> categories = new TreeView(pref_general); layout.setLeft(categories); Scene scene = new Scene(layout, 700, 750); window.initModality(Modality.APPLICATION_MODAL); window.setResizable(false); window.setScene(scene); window.setTitle("Preferences"); window.showAndWait(); }
@SuppressWarnings("unchecked") @Override public void set(Consumer<Object> dispatcher, Object node, String name, VProperty vProperty) { if (!(node instanceof TreeView)) { throw new IllegalStateException("Trying to set cellFactory of node " + node); } final Object value = vProperty.isValueDefined() ? vProperty.getValue() : null; if (!(value == null || value instanceof Function)) { throw new IllegalStateException( String.format("Trying to set a cellFactory on node %s, which is not a function but a %s", node, value)); } ((TreeView) node).setCellFactory( new TreeViewCellFactory(dispatcher, value == null ? Function.identity() : (Function) value)); }
/** * Generate treeView of file items * TODO: work with VUFS items * * @return tree view */ public TreeView<SimpleTreeElement> getSimple() { TreeView<SimpleTreeElement> tree = new TreeView<>(); TreeItem<SimpleTreeElement> root = new TreeItem<>(new SimpleTreeElement("root", 0)); TreeItem<SimpleTreeElement> outer1, outer2, inner1, inner2; outer1 = makeBranch(new SimpleTreeElement("Folder1", 1), root); outer2 = makeBranch(new SimpleTreeElement("Documents", 2), root); makeBranch(new SimpleTreeElement("MyFotos", 3), outer1); makeBranch(new SimpleTreeElement("OtherFiles", 4), outer1); makeBranch(new SimpleTreeElement("WorkFiles", 5), root); makeBranch(new SimpleTreeElement("Projects", 6), root); tree.setRoot(root); tree.setPrefWidth(200); setTreeCellFactory(tree); tree.setShowRoot(false); return tree; }
/** * Generate treeView of settings items * TODO: work with Repository * * @return tree view */ public TreeView<SimpleTreeElement> getSettingsTree() { TreeView<SimpleTreeElement> tree = new TreeView<>(); TreeItem<SimpleTreeElement> root = new TreeItem<>(new SimpleTreeElement("root", 0)); TreeItem<SimpleTreeElement> outer1, outer2, inner1, inner2; outer1 = makeBranch(new SimpleTreeElement("Account", 1), root); outer2 = makeBranch(new SimpleTreeElement("Clouds", 2), root); makeBranch(new SimpleTreeElement("Dropbox", 3), outer2); makeBranch(new SimpleTreeElement("Google Drive", 4), outer2); makeBranch(new SimpleTreeElement("Sync", 5), root); makeBranch(new SimpleTreeElement("Encription", 6), root); tree.setRoot(root); tree.setPrefWidth(200); setTreeCellFactory(tree); tree.setShowRoot(false); return tree; }
/** * Make an effort at updating all the trees, tables or lists that we can find. * * @param parent */ private static void updateListsAndTables(final Parent parent) { if (parent == null) return; for (Node child : parent.getChildrenUnmodifiable()) { if (child instanceof TreeView<?>) ((TreeView)child).refresh(); else if (child instanceof ListView<?>) ((ListView)child).refresh(); else if (child instanceof TableView<?>) ((TableView)child).refresh(); else if (child instanceof TreeTableView<?>) ((TreeTableView)child).refresh(); else if (child instanceof Parent) updateListsAndTables((Parent)child); } }