Example usage for javafx.scene.control TreeItem isLeaf

List of usage examples for javafx.scene.control TreeItem isLeaf

Introduction

In this page you can find the example usage for javafx.scene.control TreeItem isLeaf.

Prototype

public boolean isLeaf() 

Source Link

Document

A TreeItem is a leaf if it has no children.

Usage

From source file:org.eclipse.jubula.rc.javafx.tester.adapter.TreeOperationContext.java

@Override
public boolean isLeaf(final Object node) {
    boolean result = EventThreadQueuerJavaFXImpl.invokeAndWait("isLeaf", //$NON-NLS-1$
            new Callable<Boolean>() {

                @Override/*from w  w  w  .  j  av a  2  s.  c  o  m*/
                public Boolean call() throws Exception {
                    TreeItem<?> item = (TreeItem<?>) node;
                    return item.isLeaf();
                }
            });

    return result;
}

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

private void expand(TreeItem<JEVisClass> item, boolean expand) {
    if (!item.isLeaf()) {
        if (item.isExpanded() && !expand) {
            item.setExpanded(expand);/*  w  w  w.  ja  va 2 s.  c o  m*/
        } else if (!item.isExpanded() && expand) {
            item.setExpanded(expand);
        }

        for (TreeItem<JEVisClass> child : item.getChildren()) {
            expand(child, expand);
        }
    }
}

From source file:sonicScream.controllers.CategoryTabController.java

public CategoryTabController(Category category) {
    URL location = getClass().getResource("/sonicScream/views/CategoryTab.fxml");
    FXMLLoader loader = new FXMLLoader(location);
    loader.setRoot(this);
    loader.setController(this);
    try {//from w w  w  .j  ava  2 s .c o m
        loader.load();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

    _category = category;

    this.textProperty().bind(_category.categoryNameProperty());
    CategoryTabComboBox.setItems(_category.getCategoryScripts());

    //These two bindings handle changing between categories with only a single 
    //script (items) and those with multiple (everything else)
    SimpleListProperty bindableList = new SimpleListProperty();
    bindableList.bind(new SimpleObjectProperty<>(_category.getCategoryScripts()));
    CategoryTabComboBox.visibleProperty().bind(Bindings.greaterThan(bindableList.sizeProperty(), 1));

    selectedScriptNodeProperty().bind(CategoryTabTreeView.getSelectionModel().selectedItemProperty());

    selectedScript.bind(CategoryTabComboBox.getSelectionModel().selectedItemProperty());

    if (_category.getCategoryScripts() != null && !_category.getCategoryScripts().isEmpty()) {
        CategoryTabComboBox.valueProperty().set(_category.getCategoryScripts().get(0));
        handleComboBoxChanged(null);
    }

    SwapDisplayModeButton.textProperty().bind(Bindings.when(displayMode.isEqualTo(CategoryDisplayMode.SIMPLE))
            .then("Advanced >>").otherwise("<< Simple"));

    CategoryTabTreeView.getSelectionModel().selectedItemProperty()
            .addListener((observable, oldValue, newValue) -> {
                if (newValue != null) {
                    TreeItem<String> scriptValue = TreeUtils.getRootMinusOne((TreeItem<String>) newValue);
                    TreeItem<String> selectedValue = (TreeItem<String>) newValue;
                    CategoryTabScriptValueLabel.setText(scriptValue.getValue());
                    selectedScriptNodeIsLeaf.set(selectedValue.isLeaf());
                }
            });
}

From source file:sonicScream.controllers.CategoryTabController.java

/**
 * Replaces the currently-selected node's script value with a generated value based on a user-selected sound file.
 * Updates the selected Script's values, converts it to a local Script, writes the Script out to disk, and copies
 * the selected sound file to the appropriate location in the user's profile folder.
 * Only available to the user in Simple mode.
 * @throws IOException/*from w w  w  .j a  va  2 s  .c om*/
 */
public void replaceSound() throws IOException {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();
    if (!selectedNode.isLeaf()) {
        return; //Shouldn't even be possible, but just in case
    }

    Stage currentStage = (Stage) CategoryTabScriptValueLabel.getScene().getWindow();
    Path newSoundFile = chooseSoundFile(currentStage);

    replaceSound(newSoundFile);
}

From source file:sonicScream.controllers.CategoryTabController.java

public void revertSound() {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();//from   w  w  w .  j av a 2  s .c  o m
    if (!selectedNode.isLeaf()) {
        return; //Shouldn't even be possible, but just in case
    }
    //We use this later to find the correct node to select after a reversion.
    int nodeParentIndex = selectedNode.getParent().getParent().getChildren().indexOf(selectedNode.getParent());

    Script activeScript = (Script) CategoryTabComboBox.getValue();

    //get the index of the selected node relative to its parent.
    int selectedWaveIndex = selectedNode.getParent().getChildren().indexOf(selectedNode);
    VPKFileService vpkService = (VPKFileService) ServiceLocator.getService(VPKFileService.class);
    Script vpkScript = new Script(vpkService.getVPKEntry(activeScript.getVPKPath()), _category);
    List<TreeItem<String>> vpkWaves = TreeUtils.getWaveStrings(vpkScript.getRootNode()).orElse(null);
    if (vpkWaves != null && vpkWaves.size() > selectedWaveIndex) {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        TreeItem<String> selectedNodeInVPKRoot = vpkWaves.get(selectedWaveIndex);
        String vpkNodeString = StringUtils.normalizeSpace((selectedNodeInVPKRoot.getValue()));
        selectedNodeInRoot.setValue(vpkNodeString);
        selectedNode.setValue(StringParsing.rootSoundToSimpleSound(vpkNodeString));
    }
    //if the index does NOT exist, remove the index from the root node, and
    //then do all the updating
    else {
        TreeItem<String> selectedNodeInRoot = TreeUtils.getWaveStrings(activeScript.getRootNode()).get()
                .get(selectedWaveIndex);
        selectedNodeInRoot.getParent().getChildren().remove(selectedNodeInRoot);
        selectedNode.getParent().getChildren().remove(selectedNode);
        //TODO: Delete the parent if it no longer has any children.
    }
}

From source file:sonicScream.utilities.ScriptParser.java

private static StringBuilder recursiveBuildScript(StringBuilder scriptString, TreeItem<String> node,
        int level) {
    String tabs = "";
    for (int i = 1; i < level; i++) {
        tabs += "\t";
    }//from  w  ww. ja va 2  s.  c  o m

    if (node.getParent() != null) {
        scriptString.append(tabs + node.getValue() + "\n");
    }
    /* 
     * TODO: Figure out a way to track brace placement without just checking to see if a node has children. Maybe 
     * a custom node object that tracks whether a node is followed by braces?
     */
    if (!node.isLeaf()) {
        scriptString.append(tabs + "{\n");
        level++;
        for (int i = 0; i < node.getChildren().size(); i++) {
            scriptString = recursiveBuildScript(scriptString, node.getChildren().get(i), level);
        }
        level--;
        scriptString.append(tabs + "}\n");
    }
    return scriptString;
}

From source file:sonicScream.utilities.ScriptParser.java

public static boolean areScriptTreesEqual(TreeItem<String> lhs, TreeItem<String> rhs) {
    if (lhs.getChildren().size() != rhs.getChildren().size() || lhs.isLeaf() != rhs.isLeaf()) {
        return false;
    }/*w w w.j  ava2  s . c  o  m*/

    boolean areEqual = true;

    if (!lhs.isLeaf()) {
        for (int i = 0; i < lhs.getChildren().size() - 1; i++) {
            areScriptTreesEqual(lhs.getChildren().get(i), rhs.getChildren().get(i));
        }
    }

    return lhs.getValue().equals(rhs.getValue());
}