public PwPolicyListPanel()

in src/main/java/org/apache/directory/fortress/web/panel/PwPolicyListPanel.java [75:263]


    public PwPolicyListPanel( String id )
    {
        super( id );
        PwPolicyListModel policyListModel = new PwPolicyListModel( new PwPolicy( "" ),
            SecUtils.getSession( this ) );
        setDefaultModel( policyListModel );
        List<IGridColumn<DefaultTreeModel, DefaultMutableTreeNode, String>> columns =
            new ArrayList<IGridColumn<DefaultTreeModel, DefaultMutableTreeNode, String>>();
        columns.add( new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Policy Name" ), "userObject.name" ) );

        PropertyColumn minAge = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Min Age" ), "userObject.minAge" );
        minAge.setInitialSize( 60 );
        columns.add( minAge );

        PropertyColumn maxAge = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Max Age" ), "userObject.maxAge" );
        maxAge.setInitialSize( 75 );
        columns.add( maxAge );

        PropertyColumn inHistory = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "History" ), "userObject.inHistory" );
        inHistory.setInitialSize( 50 );
        columns.add( inHistory );

        PropertyColumn minLength = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Min Len" ), "userObject.minLength" );
        minLength.setInitialSize( 60 );
        columns.add( minLength );

        PropertyColumn expireWarning = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Expire Warning" ), "userObject.expireWarning" );
        expireWarning.setInitialSize( 115 );
        columns.add( expireWarning );

        PropertyColumn graceLoginLimit = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Grace" ), "userObject.graceLoginLimit" );
        graceLoginLimit.setInitialSize( 50 );
        columns.add( graceLoginLimit );

        PropertyColumn lockout = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Lockout" ), "userObject.lockout" );
        lockout.setInitialSize( 60 );
        columns.add( lockout );

        PropertyColumn lockoutDuration = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Lockout Duration" ), "userObject.lockoutDuration" );
        lockoutDuration.setInitialSize( 125 );
        columns.add( lockoutDuration );

        PropertyColumn maxFailure = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Max Failure" ), "userObject.maxFailure" );
        maxFailure.setInitialSize( 80 );
        columns.add( maxFailure );

        PropertyColumn failureCountInterval = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Interval" ), "userObject.failureCountInterval" );
        failureCountInterval.setInitialSize( 60 );
        columns.add( failureCountInterval );

        PropertyColumn mustChange = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Must Change" ), "userObject.mustChange" );
        mustChange.setInitialSize( 90 );
        columns.add( mustChange );

        PropertyColumn allowUserChange = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Allow Change" ), "userObject.allowUserChange" );
        allowUserChange.setInitialSize( 95 );
        columns.add( allowUserChange );

        PropertyColumn safeModify = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
            Model.of( "Safe Modify" ), "userObject.safeModify" );
        safeModify.setInitialSize( 90 );
        columns.add( safeModify );

        /*
                PropertyColumn checkQuality = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, String, String>(
                            Model.of("Check Quality"), "userObject.checkQuality");
                checkQuality.setInitialSize(100);
                columns.add(checkQuality);
        */

        List<PwPolicy> policies = ( List<PwPolicy> ) getDefaultModel().getObject();
        treeModel = createTreeModel( policies );
        grid = new TreeGrid<DefaultTreeModel, DefaultMutableTreeNode, String>( "policytreegrid", 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() )
                {
                    PwPolicy policy = ( PwPolicy ) node.getUserObject();
                    LOG.debug( "TreeGrid.addGrid.selectItem selected policy =" + policy.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, policy );
                    }
                }
            }
        };
        //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 );

        listForm.add( new AjaxSubmitLink( GlobalIds.SEARCH )
        {
            /** Default serialVersionUID */
            private static final long serialVersionUID = 1L;


            @Override
            protected void onSubmit(AjaxRequestTarget target)
            {
                LOG.debug( ".search onSubmit" );
                info( "Searching Policies..." );
                if ( !StringUtils.isNotEmpty( searchVal ) )
                {
                    searchVal = "";
                }
                PwPolicy srchPolicy = new PwPolicy( searchVal );
                setDefaultModel( new PwPolicyListModel( srchPolicy, SecUtils.getSession( this ) ) );
                treeModel.reload();
                rootNode.removeAllChildren();
                List<PwPolicy> policies = ( List<PwPolicy> ) getDefaultModelObject();
                if ( CollectionUtils.isNotEmpty( policies ) )
                {
                    for ( PwPolicy policy : policies )
                        rootNode.add( new DefaultMutableTreeNode( policy ) );
                    info( "Search returned " + policies.size() + " matching objects" );
                }
                else
                {
                    info( "No matching objects found" );
                }
                target.add( grid );
            }


            @Override
            public void onError(AjaxRequestTarget target)
            {
                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 );
    }