Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode.

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:org.apache.directory.fortress.web.panel.ObjectListPanel.java

public ObjectListPanel(String id, final boolean isAdmin) {
    super(id);// w  ww. j  ava2  s.c  o m
    ObjectListModel objectListModel = new ObjectListModel(new PermObj(""), isAdmin, SecUtils.getSession(this));
    setDefaultModel(objectListModel);
    addGrid();
    radioGroup = new RadioGroup("searchOptions", new PropertyModel(this, "selectedRadioButton"));
    add(radioGroup);
    Radio objectRb = new Radio("objectRb", new Model(Character.valueOf(NAMES)));
    radioGroup.add(objectRb);
    Radio ouRb = new Radio("ouRb", new Model(Character.valueOf(OUS)));
    radioGroup.add(ouRb);
    addOUSearchModal(ouRb);
    radioGroup.setOutputMarkupId(true);
    radioGroup.setRenderBodyOnly(false);
    searchValFld = new TextField(GlobalIds.SEARCH_VAL, new PropertyModel<String>(this, GlobalIds.SEARCH_VAL));
    searchValFld.setOutputMarkupId(true);
    AjaxFormComponentUpdatingBehavior ajaxUpdater = new AjaxFormComponentUpdatingBehavior(GlobalIds.ONBLUR) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            target.add(searchValFld);
        }
    };
    searchValFld.add(ajaxUpdater);
    radioGroup.add(searchValFld);

    this.listForm.add(radioGroup);
    selectedRadioButton = NAMES;

    this.listForm.add(new SecureIndicatingAjaxButton(GlobalIds.SEARCH, GlobalIds.REVIEW_MGR, "findPermObjs") {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            log.debug(".search.onSubmit selected radio button: " + selectedRadioButton);
            info("Searching Permission Objects...");
            if (!StringUtils.isNotEmpty(searchVal)) {
                searchVal = "";
            }
            PermObj srchObject = new PermObj();
            switch (selectedRadioButton) {
            case NAMES:
                log.debug(".onSubmit OBJECT RB selected");
                srchObject.setObjName(searchVal);
                break;
            case OUS:
                log.debug(".onSubmit OUS RB selected");
                srchObject.setOu(searchVal);
                break;
            }
            setDefaultModel(new ObjectListModel(srchObject, isAdmin, SecUtils.getSession(this)));
            treeModel.reload();
            rootNode.removeAllChildren();
            List<PermObj> permObjs = (List<PermObj>) getDefaultModelObject();
            if (CollectionUtils.isNotEmpty(permObjs)) {
                for (PermObj permObj : permObjs)
                    rootNode.add(new DefaultMutableTreeNode(permObj));
                info("Search returned " + permObjs.size() + " matching objects");
            } else {
                info("No matching objects found");
            }
            target.add(grid);
        }

        @Override
        public void onError(AjaxRequestTarget target, Form form) {
            log.warn(".search.onError");
            target.add();
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            AjaxCallListener ajaxCallListener = new AjaxCallListener() {
                /** Default serialVersionUID */
                private static final long serialVersionUID = 1L;

                @Override
                public CharSequence getFailureHandler(Component component) {
                    return GlobalIds.WINDOW_LOCATION_REPLACE_COMMANDER_HOME_HTML;
                }
            };
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
}

From source file:org.apache.directory.fortress.web.panel.ObjectListPanel.java

private DefaultTreeModel createTreeModel(List<PermObj> permObjs) {
    DefaultTreeModel model;// w ww .  j a  v  a2 s  .co  m
    rootNode = new DefaultMutableTreeNode(null);
    model = new DefaultTreeModel(rootNode);
    if (permObjs == null)
        log.debug("no Permission Objects found");
    else {
        log.debug(".createTreeModel Permission Objects found:" + permObjs.size());
        for (PermObj permObj : permObjs)
            rootNode.add(new DefaultMutableTreeNode(permObj));
    }
    return model;
}

From source file:org.apache.directory.fortress.web.panel.ObjectListPanel.java

public void add(FortEntity entity) {
    if (getDefaultModelObject() != null) {
        List<PermObj> permObjs = ((List<PermObj>) getDefaultModelObject());
        permObjs.add((PermObj) entity);//from  www .  j a v  a2 s.  co  m
        treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, 0);
        //treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, permObjs.size());
    }
}

From source file:org.apache.directory.fortress.web.panel.OUListPanel.java

public OUListPanel(String id, final boolean isUser) {
    super(id);//from w  w w . j  a  v  a  2s.com
    OrgUnit orgUnit = new OrgUnit();
    orgUnit.setName("");
    String searchLabel;
    if (isUser) {
        orgUnit.setType(OrgUnit.Type.USER);
        searchLabel = "User OU Name";
    } else {
        orgUnit.setType(OrgUnit.Type.PERM);
        searchLabel = "Perm OU Name";
    }

    OUListModel ouListModel = new OUListModel(orgUnit, SecUtils.getSession(this));
    setDefaultModel(ouListModel);
    List<IGridColumn<DefaultTreeModel, DefaultMutableTreeNode, String>> columns = new ArrayList<>();
    PropertyColumn name = new PropertyColumn<>(Model.of(searchLabel), "userObject.name");
    name.setInitialSize(400);
    columns.add(name);

    PropertyColumn description = new PropertyColumn<>(Model.of("Description"), "userObject.Description");

    description.setInitialSize(400);
    columns.add(description);

    PropertyColumn parents = new PropertyColumn<>(Model.of("Parents"), "userObject.parents");
    parents.setInitialSize(400);
    columns.add(parents);

    List<OrgUnit> orgUnits = (List<OrgUnit>) getDefaultModel().getObject();
    treeModel = createTreeModel(orgUnits);
    grid = new TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String>("outreegrid", treeModel, columns) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public void selectItem(IModel itemModel, boolean selected) {
            node = (DefaultMutableTreeNode) itemModel.getObject();
            if (!node.isRoot()) {
                OrgUnit orgUnit1 = (OrgUnit) node.getUserObject();
                log.debug("TreeGrid.addGrid.selectItem selected sdSet =" + orgUnit1.getName());
                if (super.isItemSelected(itemModel)) {
                    log.debug("TreeGrid.addGrid.selectItem item is selected");
                    super.selectItem(itemModel, false);
                } else {
                    super.selectItem(itemModel, true);
                    SelectModelEvent.send(getPage(), this, orgUnit1);
                }
            }
        }
    };
    //grid.setContentHeight( 50, SizeUnit.EM );
    grid.setAllowSelectMultiple(false);
    grid.setClickRowToSelect(true);
    grid.setClickRowToDeselect(false);
    grid.setSelectToEdit(false);
    // expand the root node
    grid.getTreeState().expandAll();
    Form listForm = new Form("form");
    listForm.add(grid);
    grid.setOutputMarkupId(true);
    TextField searchValFld = new TextField(GlobalIds.SEARCH_VAL,
            new PropertyModel<String>(this, GlobalIds.SEARCH_VAL));
    listForm.add(searchValFld);

    //this.listForm.add( new AjaxSubmitLink( "search" )
    listForm.add(new SecureIndicatingAjaxButton(GlobalIds.SEARCH, GlobalIds.DEL_REVIEW_MGR, "searchOU") {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            log.debug(".search onSubmit");
            info("Searching OrgUnits...");
            if (!StringUtils.isNotEmpty(searchVal)) {
                searchVal = "";
            }
            final OrgUnit srchOu = new OrgUnit();
            if (isUser) {
                srchOu.setType(OrgUnit.Type.USER);
            } else {
                srchOu.setType(OrgUnit.Type.PERM);
            }
            srchOu.setName(searchVal);
            setDefaultModel(new OUListModel(srchOu, SecUtils.getSession(this)));
            treeModel.reload();
            rootNode.removeAllChildren();
            List<OrgUnit> orgUnits1 = (List<OrgUnit>) getDefaultModelObject();
            if (CollectionUtils.isNotEmpty(orgUnits1)) {
                for (OrgUnit ou : orgUnits1) {
                    rootNode.add(new DefaultMutableTreeNode(ou));
                }
                info("Search returned " + orgUnits1.size() + " matching objects");
            } else {
                info("No matching objects found");
            }
            target.add(grid);
        }

        @Override
        public void onError(AjaxRequestTarget target, Form form) {
            log.warn(".search.onError");
            target.add();
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            AjaxCallListener ajaxCallListener = new AjaxCallListener() {
                /** Default serialVersionUID */
                private static final long serialVersionUID = 1L;

                @Override
                public CharSequence getFailureHandler(Component component) {
                    return GlobalIds.WINDOW_LOCATION_REPLACE_COMMANDER_HOME_HTML;
                }
            };
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
    add(listForm);
}

From source file:org.apache.directory.fortress.web.panel.OUListPanel.java

private DefaultTreeModel createTreeModel(List<OrgUnit> orgUnits) {
    DefaultTreeModel model;//  w w  w.j  a va2  s.c  o  m
    rootNode = new DefaultMutableTreeNode(null);
    model = new DefaultTreeModel(rootNode);
    if (orgUnits == null) {
        log.debug("no OrgUnits found");
    } else {
        log.debug("OrgUnits found:" + orgUnits.size());
        for (OrgUnit orgUnit : orgUnits) {
            rootNode.add(new DefaultMutableTreeNode(orgUnit));
        }
    }
    return model;
}

From source file:org.apache.directory.fortress.web.panel.OUListPanel.java

public void add(FortEntity entity) {
    if (getDefaultModelObject() != null) {
        List<OrgUnit> orgUnits = ((List<OrgUnit>) getDefaultModelObject());
        orgUnits.add((OrgUnit) entity);/* w  w w  . j  a  va  2 s  .c o m*/
        treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, orgUnits.size());
    }
}

From source file:org.apache.directory.fortress.web.panel.PermListPanel.java

public PermListPanel(String id, final boolean isAdmin) {
    super(id);/*  www .j  av a  2s.com*/

    this.isAdmin = isAdmin;
    PermListModel permListModel = new PermListModel(new Permission("", ""), isAdmin, SecUtils.getSession(this));
    setDefaultModel(permListModel);
    List<IGridColumn<DefaultTreeModel, DefaultMutableTreeNode, String>> columns = new ArrayList<>();
    PropertyColumn objName = new PropertyColumn(new Model("Object Name"), "userObject.ObjName");
    objName.setInitialSize(350);
    columns.add(objName);
    columns.add(new PropertyColumn(new Model("Object Id"), "userObject.ObjId"));
    columns.add(new PropertyColumn(new Model("Operation Name"), "userObject.OpName"));

    PropertyColumn description = new PropertyColumn(new Model("Description"), "userObject.Description");
    description.setInitialSize(300);
    columns.add(description);

    String roleAssignLabel;
    if (isAdmin) {
        roleAssignLabel = "Admin Role Assignments";
    } else {
        roleAssignLabel = "RBAC Role Assignments";
    }
    PropertyColumn roles = new PropertyColumn(new Model(roleAssignLabel), "userObject.Roles");
    roles.setInitialSize(500);
    columns.add(roles);

    List<Permission> perms = (List<Permission>) getDefaultModel().getObject();
    treeModel = createTreeModel(perms);

    grid = new TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String>("permtreegrid", treeModel, columns) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        public void selectItem(IModel itemModel, boolean selected) {
            node = (DefaultMutableTreeNode) itemModel.getObject();

            if (!node.isRoot()) {
                Permission perm = (Permission) node.getUserObject();
                log.debug("TreeGrid.addGrid.selectItem selected perm objNm: " + perm.getObjName() + " opNm: "
                        + perm.getOpName());

                if (super.isItemSelected(itemModel)) {
                    log.debug("TreeGrid.addGrid.selectItem item is selected");
                    super.selectItem(itemModel, false);
                } else {
                    super.selectItem(itemModel, true);
                    SelectModelEvent.send(getPage(), this, perm);
                }
            }
        }
    };

    //grid.setContentHeight( 50, SizeUnit.EM );
    grid.setAllowSelectMultiple(false);
    grid.setClickRowToSelect(true);
    grid.setClickRowToDeselect(false);
    grid.setSelectToEdit(false);
    // expand the root node
    grid.getTreeState().expandAll();
    listForm = new Form("form");
    listForm.add(grid);
    grid.setOutputMarkupId(true);
    add(listForm);
    permObjectFld = new TextField("permObject", new PropertyModel<String>(this, "permObject"));
    permObjectFld.setOutputMarkupId(true);

    AjaxFormComponentUpdatingBehavior ajaxUpdater = new AjaxFormComponentUpdatingBehavior(GlobalIds.ONBLUR) {
        /** Default serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            target.add(permObjectFld);
        }
    };

    permObjectFld.add(ajaxUpdater);
    this.listForm.add(permObjectFld);
    TextField permOperationFld = new TextField("permOperation",
            new PropertyModel<String>(this, "permOperation"));
    this.listForm.add(permOperationFld);
    addObjectSearchModal();

    this.listForm.add(
            new SecureIndicatingAjaxButton(GlobalIds.SEARCH, GlobalIds.REVIEW_MGR, GlobalIds.FIND_PERMISSIONS) {
                /** Default serialVersionUID */
                private static final long serialVersionUID = 1L;

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    log.debug(".search onSubmit");
                    info("Searching Perms...");

                    if (!StringUtils.isNotEmpty(permObject)) {
                        permObject = "";
                    }

                    if (!StringUtils.isNotEmpty(permOperation)) {
                        permOperation = "";
                    }

                    Permission srchPerm = new Permission(permObject, permOperation);
                    setDefaultModel(new PermListModel(srchPerm, isAdmin, SecUtils.getSession(this)));
                    treeModel.reload();
                    rootNode.removeAllChildren();
                    List<Permission> perms = (List<Permission>) getDefaultModelObject();

                    if (CollectionUtils.isNotEmpty(perms)) {
                        for (Permission perm : perms) {
                            rootNode.add(new DefaultMutableTreeNode(perm));
                        }

                        info("Search returned " + perms.size() + " matching objects");
                    } else {
                        info("No matching objects found");
                    }

                    target.add(grid);
                }

                @Override
                public void onError(AjaxRequestTarget target, Form<?> form) {
                    log.warn(".search.onError");
                    target.add();
                }

                @Override
                protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);

                    AjaxCallListener ajaxCallListener = new AjaxCallListener() {
                        /** Default serialVersionUID */
                        private static final long serialVersionUID = 1L;

                        @Override
                        public CharSequence getFailureHandler(Component component) {
                            return GlobalIds.WINDOW_LOCATION_REPLACE_COMMANDER_HOME_HTML;
                        }
                    };

                    attributes.getAjaxCallListeners().add(ajaxCallListener);
                }
            });
}

From source file:org.apache.directory.fortress.web.panel.PermListPanel.java

@Override
public void onEvent(IEvent event) {
    if (event.getPayload() instanceof SaveModelEvent) {
        SaveModelEvent modelEvent = (SaveModelEvent) event.getPayload();

        switch (modelEvent.getOperation()) {
        case ADD:
            add(modelEvent.getEntity());
            break;

        case UPDATE:
            /*//from  ww  w . ja va 2 s  .  c  o m
            grid.markItemDirty(itemThatHasChanged);
            grid.update();
             */
            modelChanged();
            break;

        case DELETE:
            prune();
            break;

        case SEARCH:
            setDefaultModel(
                    new PermListModel((Permission) modelEvent.getEntity(), isAdmin, SecUtils.getSession(this)));
            treeModel.reload();
            rootNode.removeAllChildren();

            for (Permission perm : (List<Permission>) getDefaultModelObject()) {
                rootNode.add(new DefaultMutableTreeNode(perm));
            }

            break;

        default:
            break;
        }

        AjaxRequestTarget target = ((SaveModelEvent) event.getPayload()).getAjaxRequestTarget();
        target.add(grid);
        log.debug(".onEvent SaveModelEvent: " + target.toString());
    }
}

From source file:org.apache.directory.fortress.web.panel.PermListPanel.java

private DefaultTreeModel createTreeModel(List<Permission> perms) {
    DefaultTreeModel model;// ww  w.jav  a  2s.  c  om
    rootNode = new DefaultMutableTreeNode(null);
    model = new DefaultTreeModel(rootNode);

    if (perms == null) {
        log.debug(".createTreeModel no Perms found");
    } else {
        log.debug(".createTreeModel Perms found:" + perms.size());

        for (Permission perm : perms) {
            rootNode.add(new DefaultMutableTreeNode(perm));
        }
    }

    return model;
}

From source file:org.apache.directory.fortress.web.panel.PermListPanel.java

public void add(FortEntity entity) {
    if (getDefaultModelObject() != null) {
        List<Permission> perms = ((List<Permission>) getDefaultModelObject());
        perms.add((Permission) entity);
        treeModel.insertNodeInto(new DefaultMutableTreeNode(entity), rootNode, 0);
    }/*w  ww.  j  av  a  2 s .c o m*/
}