NetletAdminUserProfileView.java :  » Portal » Open-Portal » com » sun » portal » netlet » admin » Java Open Source

Java Open Source » Portal » Open Portal 
Open Portal » com » sun » portal » netlet » admin » NetletAdminUserProfileView.java
/** 
 * Copyright 2002 Sun Microsystems, Inc. All 
 * rights reserved. Use of this product is subject 
 * to license terms. Federal Acquisitions: 
 * Commercial Software -- Government Users 
 * Subject to Standard License Terms and 
 * Conditions. 
 * 
 * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
 * are trademarks or registered trademarks of Sun Microsystems, 
 * Inc. in the United States and other countries. 
 *
 * @ Author Bhavanishankar
 */

package com.sun.portal.netlet.admin;

// JDK classes

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.iplanet.am.console.components.view.html.DynamicGUI;
import com.iplanet.am.console.components.view.html.DynamicGUIComp;
import com.iplanet.jato.RequestHandler;
import com.iplanet.jato.model.DatasetModel;
import com.iplanet.jato.model.ModelControlException;
import com.iplanet.jato.view.RequestHandlingTiledViewBase;
import com.iplanet.jato.view.TiledView;
import com.iplanet.jato.view.View;
import com.iplanet.jato.view.event.DisplayEvent;
import com.iplanet.jato.view.html.OptionList;
import com.sun.portal.netlet.admin.model.NetletAdminUserProfileModelImpl;

public class NetletAdminUserProfileView extends RequestHandlingTiledViewBase
    implements
        TiledView,
        RequestHandler {
    public static final String CC_ATTR_SET = "ccAttrSet";
    public static final String ADD_BTN = "add.button";
    public static final String REMOVE_BTN = "remove.button";
    private NetletAdminUserProfileModelImpl model = null;
    private NetletAdminModelManager modelManager = null;

    /*
     * @param parent The reference of the parent container
     * @param name The name of this view.
     */
    public NetletAdminUserProfileView(View parent, String name) {
        super(parent, name);
        setPrimaryModel((DatasetModel) getDefaultModel());
        registerChild(CC_ATTR_SET, DynamicGUIComp.class);
    }

    protected View createChild(String name) {
        if (name.equals(CC_ATTR_SET)) {
            return new DynamicGUIComp(this, CC_ATTR_SET, null);
        } else {
            throw new IllegalArgumentException("Invalid child name: " + name);
        }
    }

    public void beginDisplay(DisplayEvent event) throws ModelControlException {
        getPrimaryModel().setSize(getModel().getSize());
    }

    protected NetletAdminUserProfileModelImpl getModel() {
        if (model == null) {
            NetletAdminUserProfileViewBean viewBean = (NetletAdminUserProfileViewBean) getParentViewBean();
            model = (NetletAdminUserProfileModelImpl) viewBean.getModel();
            model.initModel(viewBean.getUserDN());
        }
        return model;
    }

    public NetletAdminModelManager getNetletModelMgr() {
        if (modelManager == null) {
            modelManager = (NetletAdminModelManager) getRequestContext()
                .getModelManager();
        }
        return modelManager;
    }

    public boolean nextTile() throws ModelControlException {
        boolean movedToRow = super.nextTile();
        getNetletModelMgr();
        NetletAdminUserProfileModelImpl m = getModel();
        boolean success = m.setCurrentRow(getTileIndex());
        if (movedToRow && success) {
            DynamicGUI dg = null;
            DynamicGUIComp dgc = (DynamicGUIComp) getChild(CC_ATTR_SET);
            String name = m.getAttrName();
            String label = m.getAttrLabel();
            boolean required = false;
            int attrType = m.getAttrType();
            int attrSyntax = m.getAttrSyntax();
            Set values = m.getAttrValues();
            /*
             *  Skip one tile if it is netlet rule
             */
            if (name.equals("sunPortalNetletRules")
                || name.equals("sunPortalNetletPassword")) {
                movedToRow = super.nextTile();
                success = m.setCurrentRow(getTileIndex());
                if (movedToRow && success) {
                    name = m.getAttrName();
                    label = m.getAttrLabel();
                    attrType = m.getAttrType();
                    attrSyntax = m.getAttrSyntax();
                    values = m.getAttrValues();
                } else {
                    return movedToRow;
                }
            }

            if (attrType == DynamicGUI.TYPE_SINGLE) {
                if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
                    String trueValue = m.getAttrTrueValue();
                    String falseValue = m.getAttrFalseValue();
                    String value = "";
                    if (values != null && values.iterator().hasNext()) {
                        value = (String) values.iterator().next();
                    }
                    dg = new DynamicGUI(
                        name,
                        label,
                        required,
                        attrType,
                        attrSyntax,
                        trueValue,
                        falseValue,
                        value);
                } else {
                    dg = new DynamicGUI(
                        name,
                        label,
                        required,
                        attrType,
                        attrSyntax,
                        values);
                }
            } else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE
                || attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE) {
                String[] choices = m.getAttrChoices();
                OptionList optionList = new OptionList(choices, choices);
                dg = new DynamicGUI(
                    name,
                    label,
                    required,
                    attrType,
                    attrSyntax,
                    values,
                    optionList);
            } else if (attrType == DynamicGUI.TYPE_LIST) {
                dg = new DynamicGUI(
                    name,
                    label,
                    required,
                    attrType,
                    attrSyntax,
                    values);
                dg.setAddButtonStr(modelManager.getString(ADD_BTN));
                dg.setRemoveButtonStr(modelManager.getString(REMOVE_BTN));
            }
            if (dg != null) {
                dg.setReadOnly(m.isReadOnly());
            }
            if (!m.isReadOnly()) {
                String status = m.getAttributeStatus(name);
                if (status != null && status.trim().length() != 0) {
                    dg.setStatusValue(status);
                    dg.setStatusOptions(getStatusMenu(m));
                }
            }
            setDisplayFieldValue(CC_ATTR_SET, dg);
        }
        return movedToRow;
    }

    /**
     * re-creates dynamic gui components for saving purposes
     * @return dynamic gui components for action value
     */
    public List getDynamicCompList(int netletrulesIndex) {
        List dynamicGUIs = new ArrayList(10);
        HttpServletRequest req = getRequestContext().getRequest();
        int count = 0;
        while (true) {
            /*
             *  Skip if it is the index of Netlet rule
             *  Because it is not a DynamicGUI type.
             */
            if (count == netletrulesIndex)
            //            if(count == 0)            
            {
                count++;
                continue;
            }
            DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(
                req,
                getQualifiedName(),
                CC_ATTR_SET,
                count++);

            if (dGUI != null) {
                dynamicGUIs.add(dGUI);
            } else {
                break;
            }
        }
        return dynamicGUIs;
    }

    private OptionList getStatusMenu(NetletAdminUserProfileModelImpl model) {
        OptionList optionList = new OptionList();

        optionList.add(model.getCustomizeLabel(), model.getCustomizeValue());
        optionList.add(model.getInheritLabel(), model.getInheritValue());
        optionList.add(model.getSkipLabel(), model.getSkipValue());

        return optionList;
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.