Example usage for javafx.scene.control TreeItem setValue

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

Introduction

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

Prototype

public final void setValue(T value) 

Source Link

Document

Sets the application-specific data represented by this TreeItem.

Usage

From source file:sonicScream.models.ScriptTest.java

/**
 * Tested last using the class annotation, because it causes side effects 
 * on the loaded scripts.//  ww w.  j  a v a 2s . co m
 */
@Test
public void z_testUpdateRootNodeWithSimpleTree() {
    allTestScripts.stream().forEach(s -> {
        try {
            TreeItem<String> simple = s.getSimpleTree();
            TreeItem<String> simpleNode = simple.getChildren().get(0).getChildren().get(0);
            String simpleSoundString = "some_test_sound.mp3";
            String value = "some_test_sound.mp3";

            simpleNode.setValue(value);
            s.updateRootNodeWithSimpleTree();

            String rootSoundString = TreeUtils.getWaveStrings(s.getRootNode()).get().get(0).getValue();
            String soundPrefix = StringUtils.substringBetween(rootSoundString, "\"", "\"");
            soundPrefix = soundPrefix.substring(0, soundPrefix.length() - 1); //Remove the number from the prefix
            String expected = "\"" + soundPrefix + "0\" \"" + simpleSoundString + "\"";
            String actual = TreeUtils.getWaveStrings(s.getRootNode()).get().get(0).getValue();
            assertEquals(expected, actual);
        } catch (Exception ex) {
            System.err.println("testUpdateRootNodeWithSimpleTree failed on script " + s.toString() + ": "
                    + ex.getMessage());
        }
    });
}

From source file:sonicScream.controllers.CategoryTabController.java

public void revertSound() {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();//  w  ww.  j a  v a 2  s  .co  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.models.Script.java

/**
 * Returns the Script's tree with everything removed but each entry's title
 * and its wave file list, and flattens the hierarchy.
 * Initializes the rootNode if it has not yet been initialized.
 * @param forceUpdate If true, will force the method to regenerate the simple tree from the current rootNode tree.
 * @return A simplified version of the Script's tree.
 *///from  www.j a v a 2 s.  co m
public TreeItem<String> getSimpleTree(boolean forceUpdate) {
    if (_simpleRootNode != null && !forceUpdate) {
        return _simpleRootNode;
    }
    if (_rootNode == null) {
        _rootNode = getRootNode();
    }
    TreeItem<String> local = new TreeItem<String>("root");
    for (TreeItem<String> child : getRootNode().getChildren()) {
        List<TreeItem<String>> localWaveStrings = FXCollections.observableArrayList();
        List<TreeItem<String>> waveStrings = getWaveStrings(child).orElse(null);
        if (waveStrings == null)
            continue;
        for (TreeItem<String> wave : waveStrings) {
            TreeItem<String> sound = new TreeItem<String>();
            //Remove whitespace, quotes, and value# text.
            String waveValue = wave.getValue().trim();
            int thirdQuoteIndex = StringUtils.ordinalIndexOf(waveValue, "\"", 3);
            waveValue = (waveValue.substring(thirdQuoteIndex + 1, waveValue.length() - 1));
            sound.setValue(waveValue);
            localWaveStrings.add(sound);
        }
        TreeItem<String> localChild = new TreeItem<>(child.getValue());
        localChild.getChildren().setAll(localWaveStrings);
        local.getChildren().add(localChild);
    }
    _simpleRootNode = local;
    return _simpleRootNode;
}

From source file:sonicScream.controllers.CategoryTabController.java

/**
 * See replaceSound(). This method is used for testing, so we can avoid needing to invoke a FileChooser.
 * @param newSoundFile The sound file to use for replacement.
 * @throws IOException//from   w  ww.ja va 2  s  .  co m
 */
public void replaceSound(Path newSoundFile) throws IOException {
    TreeItem<String> selectedNode = (TreeItem<String>) CategoryTabTreeView.getSelectionModel()
            .getSelectedItem();

    SettingsService settings = (SettingsService) ServiceLocator.getService(SettingsService.class);
    Script activeScript = (Script) CategoryTabComboBox.getValue();
    activeScript.getVPKPath();

    String trimmedFileName = newSoundFile.getFileName().toString().toLowerCase().replace(" ", "_");
    String profileDir = SettingsUtils.getProfileDirectory(activeScript.getParentCategoryName()).toString();
    Path destPath = Paths.get(profileDir, "/sonic-scream/sounds", trimmedFileName);

    if (!Files.exists(destPath)) {
        Files.createDirectories(destPath.getParent());
    }
    Files.copy(newSoundFile, destPath, StandardCopyOption.REPLACE_EXISTING);
    selectedNode.setValue("sounds/" + trimmedFileName.replace(".mp3", ".vsnd").replace(".wav", ".vsnd"));

    activeScript.convertToLocalScript();
}

From source file:com.cdd.bao.editor.EditSchema.java

public void updateBranchAssay(Schema.Assay modAssay) {
    if (modAssay == null)
        return;//from w w w  .j a v a2 s.c  om
    TreeItem<Branch> item = currentBranch();
    if (item == null)
        return;
    Branch branch = item.getValue();
    if (branch == null)
        return;
    updateBranchAssay(branch, modAssay);

    item.setValue(new Branch(this));
    item.setValue(branch); // triggers redraw
}

From source file:com.cdd.bao.editor.EditSchema.java

private void pullDetail(TreeItem<Branch> item) {
    if (currentlyRebuilding || item == null)
        return;//from  w w  w  . j  a  v  a2s.c  o  m
    Branch branch = item.getValue();

    if (branch.group != null) {
        // if root, check prefix first
        String prefix = detail.extractPrefix();
        if (prefix != null) {
            prefix = prefix.trim();
            if (!prefix.endsWith("#"))
                prefix += "#";
            if (!stack.peekSchema().getSchemaPrefix().equals(prefix)) {
                try {
                    new URI(prefix);
                } catch (Exception ex) {
                    //informMessage("Invalid URI", "Prefix is not a valid URI: " + prefix);
                    return;
                }
                Schema schema = stack.getSchema();
                schema.setSchemaPrefix(prefix);
                stack.setSchema(schema);
            }
        }

        // then handle the group content
        Schema.Group modGroup = detail.extractGroup();
        if (modGroup == null)
            return;

        updateBranchGroup(branch, modGroup);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    } else if (branch.assignment != null) {
        Schema.Assignment modAssn = detail.extractAssignment();
        if (modAssn == null)
            return;

        updateBranchAssignment(branch, modAssn);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    } else if (branch.assay != null) {
        Schema.Assay modAssay = detail.extractAssay();
        if (modAssay == null)
            return;

        updateBranchAssay(branch, modAssay);

        item.setValue(new Branch(this));
        item.setValue(branch); // triggers redraw
    }
}