Search in sources :

Example 1 with CCOrderedListModel

use of com.sun.identity.console.ui.model.CCOrderedListModel in project OpenAM by OpenRock.

the class AMPropertySheet method getAttributeValues.

/**
     * Returns a map of attribute name to values.
     *
     * @param attrNames Set of attribute names to retrieve.
     * @return map of attribute name to values.
     * @throws ModelControlException if cannot get model of property sheet.
     * @throws AMConsoleException if password and confirm password values do
     *         not match.
     */
public Map getAttributeValues(Collection attrNames) throws ModelControlException, AMConsoleException {
    restoreStateData(attrNames);
    AMPropertySheetModel model = (AMPropertySheetModel) getModel();
    Map attrValues = new HashMap(attrNames.size() * 2);
    Map multipleChoiceValues = getMultipleChoiceValues(model);
    for (Iterator iter = attrNames.iterator(); iter.hasNext(); ) {
        String name = (String) iter.next();
        Object childModel = model.getModel(name);
        Set values = null;
        if (CCAddRemoveModel.class.isInstance(childModel)) {
            values = getValues(((CCAddRemoveModel) childModel).getSelectedOptionList());
        } else if (CCUnOrderedListModel.class.isInstance(childModel)) {
            values = getListValues(((CCUnOrderedListModel) childModel).getOptionList());
            if ((values == null) || values.isEmpty()) {
                values = new HashSet(2);
                values.add("[0]=");
            }
        } else if (CCMapListModel.class.isInstance(childModel)) {
            values = getValues(((CCMapListModel) childModel).getOptionList());
            if ((values == null) || values.isEmpty()) {
                values = new HashSet(2);
                values.add("[]=");
            }
        } else if (CCEditableListModel.class.isInstance(childModel)) {
            values = getValues(((CCEditableListModel) childModel).getOptionList());
        } else if (CCOrderedListModel.class.isInstance(childModel)) {
            values = getListValues(((CCOrderedListModel) childModel).getSelectedOptionList());
            if ((values == null) || values.isEmpty()) {
                values = new HashSet(2);
                values.add("[0]=");
            }
        } else if (model.isChildSupported(name + PropertyTemplate.PWD_CONFIRM_SUFFIX)) {
            String pwd = (String) model.getValue(name);
            String confirmPwd = (String) model.getValue(name + PropertyTemplate.PWD_CONFIRM_SUFFIX);
            if (pwd.equals(confirmPwd)) {
                if (!pwd.equals(AMPropertySheetModel.passwordRandom)) {
                    values = new HashSet(2);
                    values.add(pwd);
                }
            } else {
                throw new AMConsoleException("password-mismatched");
            }
        } else {
            values = (Set) multipleChoiceValues.get(name);
            if (values == null) {
                values = AMAdminUtils.toSetIgnoreEmpty(model.getValues(name));
            }
        }
        if (values != null) {
            attrValues.put(name, values);
        }
    }
    return attrValues;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CCAddRemoveModel(com.sun.web.ui.model.CCAddRemoveModel) HashMap(java.util.HashMap) CCMapListModel(com.sun.identity.console.ui.model.CCMapListModel) AMPropertySheetModel(com.sun.identity.console.base.model.AMPropertySheetModel) CCOrderedListModel(com.sun.identity.console.ui.model.CCOrderedListModel) Iterator(java.util.Iterator) CCUnOrderedListModel(com.sun.identity.console.ui.model.CCUnOrderedListModel) CCEditableListModel(com.sun.web.ui.model.CCEditableListModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with CCOrderedListModel

use of com.sun.identity.console.ui.model.CCOrderedListModel in project OpenAM by OpenRock.

the class CCOrderedListTag method initButtons.

protected void initButtons() {
    super.initButtons();
    CCOrderedListModel m = (CCOrderedListModel) model;
    addButton.setDisplayLabel(m.getAddButtonLabel());
    deleteButton.setDisplayLabel(m.getDeleteButtonLabel());
}
Also used : CCOrderedListModel(com.sun.identity.console.ui.model.CCOrderedListModel)

Example 3 with CCOrderedListModel

use of com.sun.identity.console.ui.model.CCOrderedListModel in project OpenAM by OpenRock.

the class AMPropertySheetModel method createChild.

public View createChild(View parent, String name, AMModel model) {
    String tagName = (String) childMap.get(name);
    View view = null;
    if (tagName != null) {
        if (tagName.equals(ORDERED_LIST)) {
            CCOrderedListModel m = new CCOrderedListModel();
            view = new CCOrderedList((ContainerView) parent, m, name);
            m.setAddButtonLabel(model.getLocalizedString("addremove.orderable.list.add.button"));
            m.setDeleteButtonLabel(model.getLocalizedString("addremove.orderable.list.delete.button"));
            setModel(name, m);
        } else if (tagName.equals(UNORDERED_LIST)) {
            CCUnOrderedListModel m = new CCUnOrderedListModel();
            view = new CCUnOrderedList((ContainerView) parent, m, name);
            setModel(name, m);
        } else if (tagName.equals(MAP_LIST) || tagName.equals(GLOBAL_MAP_LIST)) {
            CCMapListModel m = new CCMapListModel();
            view = new CCMapList((ContainerView) parent, m, name);
            m.setValueOptionList(mapOptionList.get(name));
            m.setKeyLabel(model.getLocalizedString("maplist.key.label"));
            m.setValueLabel(model.getLocalizedString("maplist.value.label"));
            m.setMsgInvalidEntry(model.getLocalizedString("maplist.msg.invalid.entry"));
            m.setMsgInvalidKey(model.getLocalizedString("maplist.msg.invalid.key"));
            m.setMsgInvalidValue(model.getLocalizedString("maplist.msg.invalid.value"));
            m.setMsgInvalidNoKey(model.getLocalizedString("maplist.msg.invalid.nokey"));
            setModel(name, m);
        } else if (tagName.equals(ADDREMOVE_LIST)) {
            CCAddRemoveModel m = (CCAddRemoveModel) getModel(name);
            if (m == null) {
                setModel(name, new CCAddRemoveModel());
            }
        }
    }
    if (view == null) {
        view = super.createChild(parent, name);
    }
    if (CCEditableList.class.isInstance(view)) {
        CCEditableList editable = (CCEditableList) view;
        CCEditableListModel m = (CCEditableListModel) editable.getModel();
        m.setAddBtnLabel(model.getLocalizedString("editableList.addButtonLabel"));
        m.setRemoveBtnLabel(model.getLocalizedString("editableList.deleteButtonLabel"));
    }
    children.add(view);
    return view;
}
Also used : CCEditableList(com.sun.web.ui.view.editablelist.CCEditableList) CCAddRemoveModel(com.sun.web.ui.model.CCAddRemoveModel) CCMapListModel(com.sun.identity.console.ui.model.CCMapListModel) CCMapList(com.sun.identity.console.ui.view.CCMapList) CCUnOrderedListModel(com.sun.identity.console.ui.model.CCUnOrderedListModel) CCEditableListModel(com.sun.web.ui.model.CCEditableListModel) ContainerView(com.iplanet.jato.view.ContainerView) CCOrderedListModel(com.sun.identity.console.ui.model.CCOrderedListModel) CCOrderedList(com.sun.identity.console.ui.view.CCOrderedList) View(com.iplanet.jato.view.View) ContainerView(com.iplanet.jato.view.ContainerView) CCUnOrderedList(com.sun.identity.console.ui.view.CCUnOrderedList)

Example 4 with CCOrderedListModel

use of com.sun.identity.console.ui.model.CCOrderedListModel in project OpenAM by OpenRock.

the class AMPropertySheet method getAttributeValues.

/**
     * Returns a map of attribute name to values which have different values 
     * from the original values.
     *
     * @param orig Map of attribute to original values.
     * @param modified true to return map of attribute name to values that
     *        have values that is different from values in <code>orig</code>.
     * @param matchPwd true to match password with confirm password value.
     * @param amModel <code>AMModel</code> object.
     * @return a map of attribute name to values.
     * @throws ModelControlException if cannot get model of property sheet.
     * @throws AMConsoleException if password and confirm password values do
     *         not match.
     */
public Map getAttributeValues(Map orig, boolean modified, boolean matchPwd, AMModel amModel) throws ModelControlException, AMConsoleException {
    restoreStateData(orig.keySet());
    AMPropertySheetModel model = (AMPropertySheetModel) getModel();
    Map attrValues = new HashMap(orig.size() * 2);
    Map multipleChoiceValues = getMultipleChoiceValues(model);
    for (Iterator iter = orig.keySet().iterator(); iter.hasNext(); ) {
        String name = (String) iter.next();
        if (model.isChildSupported(name)) {
            Object tmpValue = orig.get(name);
            Set origValue = null;
            // the element type used in the display
            if (Set.class.isInstance(tmpValue)) {
                origValue = (Set) tmpValue;
            } else {
                // assuming this child is a list
                Map tmp = (Map) tmpValue;
                origValue = (Set) tmp.get("values");
            }
            Object childModel = model.getModel(name);
            Set values = null;
            if (CCAddRemoveModel.class.isInstance(childModel)) {
                values = getValues(((CCAddRemoveModel) childModel).getSelectedOptionList());
            } else if (CCEditableListModel.class.isInstance(childModel)) {
                values = getValues(((CCEditableListModel) childModel).getOptionList());
            } else if (CCOrderedListModel.class.isInstance(childModel)) {
                values = getListValues(((CCOrderedListModel) childModel).getSelectedOptionList());
                if (values == null || values.isEmpty()) {
                    values = new HashSet(1);
                    values.add("[0]=");
                }
            } else if (model.isChildSupported(name + PropertyTemplate.PWD_CONFIRM_SUFFIX)) {
                String pwd = (String) model.getValue(name);
                String confirmPwd = (String) model.getValue(name + PropertyTemplate.PWD_CONFIRM_SUFFIX);
                if (!matchPwd || pwd.equals(confirmPwd)) {
                    if (!pwd.equals(AMPropertySheetModel.passwordRandom)) {
                        values = new HashSet(2);
                        values.add(pwd);
                    } else {
                        values = (Set) orig.get(name);
                    }
                } else {
                    throw new AMConsoleException("password-mismatched");
                }
            } else if (model.isChildSupported(PropertyTemplate.DATE_MARKER_NAME + name)) {
                String date = (String) model.getValue(name);
                values = getDateInUserLocale(date, amModel);
            } else {
                values = (Set) multipleChoiceValues.get(name);
                if (values == null) {
                    // Convert to a set of values, excluding any empty strings
                    values = AMAdminUtils.toSetIgnoreEmpty(model.getValues(name));
                }
            }
            if (!modified || !equalsSet(values, origValue)) {
                attrValues.put(name, values);
            }
        }
    }
    return attrValues;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CCAddRemoveModel(com.sun.web.ui.model.CCAddRemoveModel) HashMap(java.util.HashMap) AMPropertySheetModel(com.sun.identity.console.base.model.AMPropertySheetModel) Iterator(java.util.Iterator) CCEditableListModel(com.sun.web.ui.model.CCEditableListModel) CCOrderedListModel(com.sun.identity.console.ui.model.CCOrderedListModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with CCOrderedListModel

use of com.sun.identity.console.ui.model.CCOrderedListModel in project OpenAM by OpenRock.

the class AMPropertySheet method setValuesToOrderedList.

private boolean setValuesToOrderedList(View view, String name, Object values, AMModel amModel, AMPropertySheetModel model) {
    boolean set = false;
    if (CCOrderedList.class.isInstance(view)) {
        ((CCOrderedList) view).resetStateData();
        CCOrderedListModel m = (CCOrderedListModel) model.getModel(name);
        if (Set.class.isInstance(values)) {
            Set sorted = new TreeSet(new OrderedListComparator());
            sorted.addAll((Set) values);
            if (sorted.size() == 1) {
                String tmp = (String) sorted.iterator().next();
                if (tmp.equals("[0]=")) {
                    sorted.clear();
                }
            }
            List list = new ArrayList();
            for (Iterator i = sorted.iterator(); i.hasNext(); ) {
                String val = (String) i.next();
                int idx = val.indexOf(']');
                idx = val.indexOf('=', idx);
                list.add(val.substring(idx + 1).trim());
            }
            m.setSelectedOptionList(AMViewBeanBase.createOptionList(list, amModel.getUserLocale(), false));
        }
        set = true;
    }
    return set;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CCOrderedList(com.sun.identity.console.ui.view.CCOrderedList) ArrayList(java.util.ArrayList) CCUnOrderedList(com.sun.identity.console.ui.view.CCUnOrderedList) CCMapList(com.sun.identity.console.ui.view.CCMapList) CCEditableList(com.sun.web.ui.view.editablelist.CCEditableList) OptionList(com.iplanet.jato.view.html.OptionList) List(java.util.List) CCOrderedList(com.sun.identity.console.ui.view.CCOrderedList) CCOrderedListModel(com.sun.identity.console.ui.model.CCOrderedListModel)

Aggregations

CCOrderedListModel (com.sun.identity.console.ui.model.CCOrderedListModel)6 CCAddRemoveModel (com.sun.web.ui.model.CCAddRemoveModel)4 CCEditableListModel (com.sun.web.ui.model.CCEditableListModel)4 Iterator (java.util.Iterator)4 CCMapListModel (com.sun.identity.console.ui.model.CCMapListModel)3 CCUnOrderedListModel (com.sun.identity.console.ui.model.CCUnOrderedListModel)3 CCMapList (com.sun.identity.console.ui.view.CCMapList)3 CCOrderedList (com.sun.identity.console.ui.view.CCOrderedList)3 CCUnOrderedList (com.sun.identity.console.ui.view.CCUnOrderedList)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)3 CCEditableList (com.sun.web.ui.view.editablelist.CCEditableList)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 ContainerView (com.iplanet.jato.view.ContainerView)2 View (com.iplanet.jato.view.View)2 OptionList (com.iplanet.jato.view.html.OptionList)2 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)2 AMPropertySheetModel (com.sun.identity.console.base.model.AMPropertySheetModel)2