001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * @ Author Bhavanishankar
014: */package com.sun.portal.netlet.admin;
015:
016: // JDK classes
017:
018: import java.util.ArrayList;
019: import java.util.List;
020: import java.util.Set;
021:
022: import javax.servlet.http.HttpServletRequest;
023:
024: import com.iplanet.am.console.components.view.html.DynamicGUI;
025: import com.iplanet.am.console.components.view.html.DynamicGUIComp;
026: import com.iplanet.jato.RequestHandler;
027: import com.iplanet.jato.model.DatasetModel;
028: import com.iplanet.jato.model.ModelControlException;
029: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
030: import com.iplanet.jato.view.TiledView;
031: import com.iplanet.jato.view.View;
032: import com.iplanet.jato.view.event.DisplayEvent;
033: import com.iplanet.jato.view.html.OptionList;
034: import com.sun.portal.netlet.admin.model.NetletAdminUserProfileModelImpl;
035:
036: public class NetletAdminUserProfileView extends
037: RequestHandlingTiledViewBase implements TiledView,
038: RequestHandler {
039: public static final String CC_ATTR_SET = "ccAttrSet";
040: public static final String ADD_BTN = "add.button";
041: public static final String REMOVE_BTN = "remove.button";
042: private NetletAdminUserProfileModelImpl model = null;
043: private NetletAdminModelManager modelManager = null;
044:
045: /*
046: * @param parent The reference of the parent container
047: * @param name The name of this view.
048: */
049: public NetletAdminUserProfileView(View parent, String name) {
050: super (parent, name);
051: setPrimaryModel((DatasetModel) getDefaultModel());
052: registerChild(CC_ATTR_SET, DynamicGUIComp.class);
053: }
054:
055: protected View createChild(String name) {
056: if (name.equals(CC_ATTR_SET)) {
057: return new DynamicGUIComp(this , CC_ATTR_SET, null);
058: } else {
059: throw new IllegalArgumentException("Invalid child name: "
060: + name);
061: }
062: }
063:
064: public void beginDisplay(DisplayEvent event)
065: throws ModelControlException {
066: getPrimaryModel().setSize(getModel().getSize());
067: }
068:
069: protected NetletAdminUserProfileModelImpl getModel() {
070: if (model == null) {
071: NetletAdminUserProfileViewBean viewBean = (NetletAdminUserProfileViewBean) getParentViewBean();
072: model = (NetletAdminUserProfileModelImpl) viewBean
073: .getModel();
074: model.initModel(viewBean.getUserDN());
075: }
076: return model;
077: }
078:
079: public NetletAdminModelManager getNetletModelMgr() {
080: if (modelManager == null) {
081: modelManager = (NetletAdminModelManager) getRequestContext()
082: .getModelManager();
083: }
084: return modelManager;
085: }
086:
087: public boolean nextTile() throws ModelControlException {
088: boolean movedToRow = super .nextTile();
089: getNetletModelMgr();
090: NetletAdminUserProfileModelImpl m = getModel();
091: boolean success = m.setCurrentRow(getTileIndex());
092: if (movedToRow && success) {
093: DynamicGUI dg = null;
094: DynamicGUIComp dgc = (DynamicGUIComp) getChild(CC_ATTR_SET);
095: String name = m.getAttrName();
096: String label = m.getAttrLabel();
097: boolean required = false;
098: int attrType = m.getAttrType();
099: int attrSyntax = m.getAttrSyntax();
100: Set values = m.getAttrValues();
101: /*
102: * Skip one tile if it is netlet rule
103: */
104: if (name.equals("sunPortalNetletRules")
105: || name.equals("sunPortalNetletPassword")) {
106: movedToRow = super .nextTile();
107: success = m.setCurrentRow(getTileIndex());
108: if (movedToRow && success) {
109: name = m.getAttrName();
110: label = m.getAttrLabel();
111: attrType = m.getAttrType();
112: attrSyntax = m.getAttrSyntax();
113: values = m.getAttrValues();
114: } else {
115: return movedToRow;
116: }
117: }
118:
119: if (attrType == DynamicGUI.TYPE_SINGLE) {
120: if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
121: String trueValue = m.getAttrTrueValue();
122: String falseValue = m.getAttrFalseValue();
123: String value = "";
124: if (values != null && values.iterator().hasNext()) {
125: value = (String) values.iterator().next();
126: }
127: dg = new DynamicGUI(name, label, required,
128: attrType, attrSyntax, trueValue,
129: falseValue, value);
130: } else {
131: dg = new DynamicGUI(name, label, required,
132: attrType, attrSyntax, values);
133: }
134: } else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE
135: || attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE) {
136: String[] choices = m.getAttrChoices();
137: OptionList optionList = new OptionList(choices, choices);
138: dg = new DynamicGUI(name, label, required, attrType,
139: attrSyntax, values, optionList);
140: } else if (attrType == DynamicGUI.TYPE_LIST) {
141: dg = new DynamicGUI(name, label, required, attrType,
142: attrSyntax, values);
143: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
144: dg.setRemoveButtonStr(modelManager
145: .getString(REMOVE_BTN));
146: }
147: if (dg != null) {
148: dg.setReadOnly(m.isReadOnly());
149: }
150: if (!m.isReadOnly()) {
151: String status = m.getAttributeStatus(name);
152: if (status != null && status.trim().length() != 0) {
153: dg.setStatusValue(status);
154: dg.setStatusOptions(getStatusMenu(m));
155: }
156: }
157: setDisplayFieldValue(CC_ATTR_SET, dg);
158: }
159: return movedToRow;
160: }
161:
162: /**
163: * re-creates dynamic gui components for saving purposes
164: * @return dynamic gui components for action value
165: */
166: public List getDynamicCompList(int netletrulesIndex) {
167: List dynamicGUIs = new ArrayList(10);
168: HttpServletRequest req = getRequestContext().getRequest();
169: int count = 0;
170: while (true) {
171: /*
172: * Skip if it is the index of Netlet rule
173: * Because it is not a DynamicGUI type.
174: */
175: if (count == netletrulesIndex)
176: // if(count == 0)
177: {
178: count++;
179: continue;
180: }
181: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
182: getQualifiedName(), CC_ATTR_SET, count++);
183:
184: if (dGUI != null) {
185: dynamicGUIs.add(dGUI);
186: } else {
187: break;
188: }
189: }
190: return dynamicGUIs;
191: }
192:
193: private OptionList getStatusMenu(
194: NetletAdminUserProfileModelImpl model) {
195: OptionList optionList = new OptionList();
196:
197: optionList.add(model.getCustomizeLabel(), model
198: .getCustomizeValue());
199: optionList
200: .add(model.getInheritLabel(), model.getInheritValue());
201: optionList.add(model.getSkipLabel(), model.getSkipValue());
202:
203: return optionList;
204: }
205:
206: }
|