Search in sources :

Example 1 with CheckboxTreeNode

use of org.primefaces.model.CheckboxTreeNode in project primefaces by primefaces.

the class DocumentService method createCheckboxDocuments.

public TreeNode createCheckboxDocuments() {
    TreeNode root = new CheckboxTreeNode(new Document("Files", "-", "Folder"), null);
    TreeNode applications = new CheckboxTreeNode(new Document("Applications", "100kb", "Folder"), root);
    TreeNode cloud = new CheckboxTreeNode(new Document("Cloud", "20kb", "Folder"), root);
    TreeNode desktop = new CheckboxTreeNode(new Document("Desktop", "150kb", "Folder"), root);
    TreeNode documents = new CheckboxTreeNode(new Document("Documents", "75kb", "Folder"), root);
    TreeNode downloads = new CheckboxTreeNode(new Document("Downloads", "25kb", "Folder"), root);
    TreeNode main = new CheckboxTreeNode(new Document("Main", "50kb", "Folder"), root);
    TreeNode other = new CheckboxTreeNode(new Document("Other", "5kb", "Folder"), root);
    TreeNode pictures = new CheckboxTreeNode(new Document("Pictures", "150kb", "Folder"), root);
    TreeNode videos = new CheckboxTreeNode(new Document("Videos", "1500kb", "Folder"), root);
    // Applications
    TreeNode primeface = new CheckboxTreeNode(new Document("Primefaces", "25kb", "Folder"), applications);
    TreeNode primefacesapp = new CheckboxTreeNode("app", new Document("primefaces.app", "10kb", "Application"), primeface);
    TreeNode nativeapp = new CheckboxTreeNode("app", new Document("native.app", "10kb", "Application"), primeface);
    TreeNode mobileapp = new CheckboxTreeNode("app", new Document("mobile.app", "5kb", "Application"), primeface);
    TreeNode editorapp = new CheckboxTreeNode("app", new Document("editor.app", "25kb", "Application"), applications);
    TreeNode settingsapp = new CheckboxTreeNode("app", new Document("settings.app", "50kb", "Application"), applications);
    // Cloud
    TreeNode backup1 = new CheckboxTreeNode("document", new Document("backup-1.zip", "10kb", "Zip"), cloud);
    TreeNode backup2 = new CheckboxTreeNode("document", new Document("backup-2.zip", "10kb", "Zip"), cloud);
    // Desktop
    TreeNode note1 = new CheckboxTreeNode("document", new Document("note-meeting.txt", "50kb", "Text"), desktop);
    TreeNode note2 = new CheckboxTreeNode("document", new Document("note-todo.txt", "100kb", "Text"), desktop);
    // Documents
    TreeNode work = new CheckboxTreeNode(new Document("Work", "55kb", "Folder"), documents);
    TreeNode expenses = new CheckboxTreeNode("document", new Document("Expenses.doc", "30kb", "Document"), work);
    TreeNode resume = new CheckboxTreeNode("document", new Document("Resume.doc", "25kb", "Resume"), work);
    TreeNode home = new CheckboxTreeNode(new Document("Home", "20kb", "Folder"), documents);
    TreeNode invoices = new CheckboxTreeNode("excel", new Document("Invoice.xsl", "20kb", "Excel"), home);
    // Downloads
    TreeNode spanish = new CheckboxTreeNode(new Document("Spanish", "10kb", "Folder"), downloads);
    TreeNode tutorial1 = new CheckboxTreeNode("document", new Document("tutorial-a1.txt", "5kb", "Text"), spanish);
    TreeNode tutorial2 = new CheckboxTreeNode("document", new Document("tutorial-a2.txt", "5kb", "Text"), spanish);
    TreeNode travel = new CheckboxTreeNode(new Document("Travel", "15kb", "Folder"), downloads);
    TreeNode hotelpdf = new CheckboxTreeNode("travel", new Document("Hotel.pdf", "10kb", "PDF"), travel);
    TreeNode flightpdf = new CheckboxTreeNode("travel", new Document("Flight.pdf", "5kb", "PDF"), travel);
    // Main
    TreeNode bin = new CheckboxTreeNode("document", new Document("bin", "50kb", "Link"), main);
    TreeNode etc = new CheckboxTreeNode("document", new Document("etc", "100kb", "Link"), main);
    TreeNode var = new CheckboxTreeNode("document", new Document("var", "100kb", "Link"), main);
    // Other
    TreeNode todotxt = new CheckboxTreeNode("document", new Document("todo.txt", "3kb", "Text"), other);
    TreeNode logopng = new CheckboxTreeNode("picture", new Document("logo.png", "2kb", "Picture"), other);
    // Pictures
    TreeNode barcelona = new CheckboxTreeNode("picture", new Document("barcelona.jpg", "90kb", "Picture"), pictures);
    TreeNode primeng = new CheckboxTreeNode("picture", new Document("primefaces.png", "30kb", "Picture"), pictures);
    TreeNode prime = new CheckboxTreeNode("picture", new Document("prime.jpg", "30kb", "Picture"), pictures);
    // Videos
    TreeNode primefacesmkv = new CheckboxTreeNode("video", new Document("primefaces.mkv", "1000kb", "Video"), videos);
    TreeNode introavi = new CheckboxTreeNode("video", new Document("intro.avi", "500kb", "Video"), videos);
    return root;
}
Also used : TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode)

Example 2 with CheckboxTreeNode

use of org.primefaces.model.CheckboxTreeNode in project primefaces by primefaces.

the class DocumentService method createCheckboxDocuments.

public TreeNode<Document> createCheckboxDocuments() {
    TreeNode<Document> root = new CheckboxTreeNode(new Document("Files", "-", "Folder"), null);
    TreeNode applications = new CheckboxTreeNode(new Document("Applications", "100kb", "Folder"), root);
    TreeNode cloud = new CheckboxTreeNode(new Document("Cloud", "20kb", "Folder"), root);
    TreeNode desktop = new CheckboxTreeNode(new Document("Desktop", "150kb", "Folder"), root);
    TreeNode documents = new CheckboxTreeNode(new Document("Documents", "75kb", "Folder"), root);
    TreeNode downloads = new CheckboxTreeNode(new Document("Downloads", "25kb", "Folder"), root);
    TreeNode main = new CheckboxTreeNode(new Document("Main", "50kb", "Folder"), root);
    TreeNode other = new CheckboxTreeNode(new Document("Other", "5kb", "Folder"), root);
    TreeNode pictures = new CheckboxTreeNode(new Document("Pictures", "150kb", "Folder"), root);
    TreeNode videos = new CheckboxTreeNode(new Document("Videos", "1500kb", "Folder"), root);
    // Applications
    TreeNode primeface = new CheckboxTreeNode(new Document("Primefaces", "25kb", "Folder"), applications);
    TreeNode primefacesapp = new CheckboxTreeNode("app", new Document("primefaces.app", "10kb", "Application"), primeface);
    TreeNode nativeapp = new CheckboxTreeNode("app", new Document("native.app", "10kb", "Application"), primeface);
    TreeNode mobileapp = new CheckboxTreeNode("app", new Document("mobile.app", "5kb", "Application"), primeface);
    TreeNode editorapp = new CheckboxTreeNode("app", new Document("editor.app", "25kb", "Application"), applications);
    TreeNode settingsapp = new CheckboxTreeNode("app", new Document("settings.app", "50kb", "Application"), applications);
    // Cloud
    TreeNode backup1 = new CheckboxTreeNode("document", new Document("backup-1.zip", "10kb", "Zip"), cloud);
    TreeNode backup2 = new CheckboxTreeNode("document", new Document("backup-2.zip", "10kb", "Zip"), cloud);
    // Desktop
    TreeNode note1 = new CheckboxTreeNode("document", new Document("note-meeting.txt", "50kb", "Text"), desktop);
    TreeNode note2 = new CheckboxTreeNode("document", new Document("note-todo.txt", "100kb", "Text"), desktop);
    // Documents
    TreeNode work = new CheckboxTreeNode(new Document("Work", "55kb", "Folder"), documents);
    TreeNode expenses = new CheckboxTreeNode("document", new Document("Expenses.doc", "30kb", "Document"), work);
    TreeNode resume = new CheckboxTreeNode("document", new Document("Resume.doc", "25kb", "Resume"), work);
    TreeNode home = new CheckboxTreeNode(new Document("Home", "20kb", "Folder"), documents);
    TreeNode invoices = new CheckboxTreeNode("excel", new Document("Invoice.xsl", "20kb", "Excel"), home);
    // Downloads
    TreeNode spanish = new CheckboxTreeNode(new Document("Spanish", "10kb", "Folder"), downloads);
    TreeNode tutorial1 = new CheckboxTreeNode("document", new Document("tutorial-a1.txt", "5kb", "Text"), spanish);
    TreeNode tutorial2 = new CheckboxTreeNode("document", new Document("tutorial-a2.txt", "5kb", "Text"), spanish);
    TreeNode travel = new CheckboxTreeNode(new Document("Travel", "15kb", "Folder"), downloads);
    TreeNode hotelpdf = new CheckboxTreeNode("travel", new Document("Hotel.pdf", "10kb", "PDF"), travel);
    TreeNode flightpdf = new CheckboxTreeNode("travel", new Document("Flight.pdf", "5kb", "PDF"), travel);
    // Main
    TreeNode bin = new CheckboxTreeNode("document", new Document("bin", "50kb", "Link"), main);
    TreeNode etc = new CheckboxTreeNode("document", new Document("etc", "100kb", "Link"), main);
    TreeNode var = new CheckboxTreeNode("document", new Document("var", "100kb", "Link"), main);
    // Other
    TreeNode todotxt = new CheckboxTreeNode("document", new Document("todo.txt", "3kb", "Text"), other);
    TreeNode logopng = new CheckboxTreeNode("picture", new Document("logo.png", "2kb", "Picture"), other);
    // Pictures
    TreeNode barcelona = new CheckboxTreeNode("picture", new Document("barcelona.jpg", "90kb", "Picture"), pictures);
    TreeNode primeng = new CheckboxTreeNode("picture", new Document("primefaces.png", "30kb", "Picture"), pictures);
    TreeNode prime = new CheckboxTreeNode("picture", new Document("prime.jpg", "30kb", "Picture"), pictures);
    // Videos
    TreeNode primefacesmkv = new CheckboxTreeNode("video", new Document("primefaces.mkv", "1000kb", "Video"), videos);
    TreeNode introavi = new CheckboxTreeNode("video", new Document("intro.avi", "500kb", "Video"), videos);
    return root;
}
Also used : TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) Document(org.primefaces.showcase.domain.Document)

Example 3 with CheckboxTreeNode

use of org.primefaces.model.CheckboxTreeNode in project primefaces by primefaces.

the class UITree method updateSelection.

public void updateSelection(FacesContext context) {
    boolean propagateSelectionDown = isPropagateSelectionDown();
    boolean propagateSelectionUp = isPropagateSelectionUp();
    ValueExpression selectionVE = getValueExpression(UITree.PropertyKeys.selection.toString());
    if (selectionVE != null) {
        Class<?> selectionType = getSelectionType();
        Object selection = getLocalSelectedNodes();
        Object previousSelection = selectionVE.getValue(context.getELContext());
        if (isMultipleSelectionMode()) {
            List<TreeNode> previousSelections = selectionType.isArray() ? (previousSelection == null ? null : Arrays.asList((TreeNode[]) previousSelection)) : (List<TreeNode>) previousSelection;
            List<TreeNode> selections = selectionType.isArray() ? (selection == null ? null : Arrays.asList((TreeNode[]) selection)) : (List<TreeNode>) selection;
            if (previousSelections != null) {
                for (TreeNode node : previousSelections) {
                    if (node instanceof CheckboxTreeNode) {
                        ((CheckboxTreeNode) node).setSelected(false, propagateSelectionDown, propagateSelectionUp);
                    } else {
                        node.setSelected(false);
                    }
                }
            }
            if (selections != null) {
                for (TreeNode node : selections) {
                    if (node instanceof CheckboxTreeNode) {
                        ((CheckboxTreeNode) node).setSelected(true, propagateSelectionDown, propagateSelectionUp);
                    } else {
                        node.setSelected(true);
                    }
                }
            }
        } else {
            if (previousSelection != null) {
                ((TreeNode) previousSelection).setSelected(false);
            }
            if (selection != null) {
                ((TreeNode) selection).setSelected(true);
            }
        }
        selectionVE.setValue(context.getELContext(), selection);
        setSelection(null);
    }
}
Also used : UITreeNode(org.primefaces.component.tree.UITreeNode) TreeNode(org.primefaces.model.TreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) ValueExpression(javax.el.ValueExpression) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode)

Example 4 with CheckboxTreeNode

use of org.primefaces.model.CheckboxTreeNode in project primefaces by primefaces.

the class FilterFeature method cloneTreeNode.

protected TreeNode cloneTreeNode(TreeTable tt, TreeNode<?> node, TreeNode<?> parent) {
    TreeNode clone = null;
    // equals check instead of instanceof to allow subclassing
    if (CheckboxTreeNode.class.equals(node.getClass())) {
        clone = new CheckboxTreeNode(node.getType(), node.getData(), parent);
    } else // equals check instead of instanceof to allow subclassing
    if (DefaultTreeNode.class.equals(node.getClass())) {
        clone = new DefaultTreeNode(node.getType(), node.getData(), parent);
    }
    if (clone == null && tt.isCloneOnFilter()) {
        if (node instanceof Cloneable) {
            try {
                Method cloneMethod = node.getClass().getMethod("clone");
                if (cloneMethod != null) {
                    cloneMethod.setAccessible(true);
                    clone = (TreeNode) cloneMethod.invoke(node);
                }
            } catch (NoSuchMethodException e) {
                LOGGER.warning(node.getClass().getName() + " declares Cloneable but no clone() method found!");
            } catch (InvocationTargetException | IllegalAccessException e) {
                LOGGER.warning(node.getClass().getName() + "#clone() not accessible!");
            }
        } else {
            try {
                Constructor<? extends TreeNode> ctor = node.getClass().getConstructor(node.getClass());
                clone = ctor.newInstance(node);
            } catch (NoSuchMethodException e) {
            // ignore
            } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
                LOGGER.warning("Could not clone " + node.getClass().getName() + " via public " + node.getClass().getSimpleName() + "() constructor!");
            }
            if (clone == null) {
                try {
                    Constructor<? extends TreeNode> ctor = node.getClass().getConstructor(String.class, Object.class, TreeNode.class);
                    clone = ctor.newInstance(node.getType(), node.getData(), parent);
                } catch (NoSuchMethodException e) {
                // ignore
                } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
                    LOGGER.warning("Could not clone " + node.getClass().getName() + " via public " + node.getClass().getSimpleName() + "(String type, Object data, TreeNode parent) constructor!");
                }
            }
        }
    }
    if (clone == null) {
        if (node instanceof CheckboxTreeNode) {
            clone = new CheckboxTreeNode(node.getType(), node.getData(), parent);
        } else {
            clone = new DefaultTreeNode(node.getType(), node.getData(), parent);
        }
    }
    clone.setSelectable(node.isSelectable());
    clone.setSelected(node.isSelected());
    clone.setExpanded(node.isExpanded());
    return clone;
}
Also used : TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with CheckboxTreeNode

use of org.primefaces.model.CheckboxTreeNode in project primefaces by primefaces.

the class Tree method createCopyOfTreeNode.

public TreeNode createCopyOfTreeNode(TreeNode<?> node) {
    TreeNode newNode;
    if (node instanceof CheckboxTreeNode) {
        newNode = new CheckboxTreeNode(node.getData());
    } else {
        newNode = new DefaultTreeNode(node.getData());
    }
    newNode.setType(node.getType());
    newNode.setSelectable(node.isSelectable());
    newNode.setExpanded(node.isExpanded());
    if (node.getChildCount() > 0) {
        for (TreeNode childNode : node.getChildren()) {
            newNode.getChildren().add(createCopyOfTreeNode(childNode));
        }
    }
    return newNode;
}
Also used : TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) CheckboxTreeNode(org.primefaces.model.CheckboxTreeNode)

Aggregations

CheckboxTreeNode (org.primefaces.model.CheckboxTreeNode)5 TreeNode (org.primefaces.model.TreeNode)5 DefaultTreeNode (org.primefaces.model.DefaultTreeNode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ValueExpression (javax.el.ValueExpression)1 UITreeNode (org.primefaces.component.tree.UITreeNode)1 Document (org.primefaces.showcase.domain.Document)1