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: Anurag Gupta
014: */package com.sun.portal.netfile.admin;
015:
016: // JDK classes
017: import java.util.ArrayList;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.List;
020: import java.util.Set;
021:
022: // Servlet classes
023: import javax.servlet.http.HttpServletRequest;
024:
025: // iPlanet JATO classes
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:
035: // iDS/AME classes
036: import com.iplanet.am.console.components.view.html.DynamicGUI;
037: import com.iplanet.am.console.components.view.html.DynamicGUIComp;
038:
039: // NetFile admin console classes
040: import com.sun.portal.netfile.admin.model.NetFileUserProfileModelImpl;
041:
042: public class NetFileDataUserProfileView extends
043: RequestHandlingTiledViewBase implements TiledView,
044: RequestHandler {
045:
046: public static final String CC_ATTR_SET = "ccAttrSet";
047: public static final String ADD_BTN = "add.button";
048: public static final String REMOVE_BTN = "remove.button";
049: private NetFileUserProfileModelImpl model = null;
050: private NetFileAdminModelManager modelManager = null;
051:
052: /*
053: * @param parent The reference of the parent container
054: * @param name The name of this view.
055: */
056: public NetFileDataUserProfileView(View parent, String name) {
057: super (parent, name);
058: setPrimaryModel((DatasetModel) getDefaultModel());
059: registerChild(CC_ATTR_SET, DynamicGUIComp.class);
060: }
061:
062: protected View createChild(String name) {
063: if (name.equals(CC_ATTR_SET)) {
064: return new DynamicGUIComp(this , CC_ATTR_SET, null);
065: } else {
066: throw new IllegalArgumentException("Invalid child name: "
067: + name);
068: }
069: }
070:
071: public void beginDisplay(DisplayEvent event)
072: throws ModelControlException {
073: getPrimaryModel().setSize(getModel().getSize());
074: }
075:
076: protected NetFileUserProfileModelImpl getModel() {
077: if (model == null) {
078: NetFileDataUserProfileViewBean viewBean = (NetFileDataUserProfileViewBean) getParentViewBean();
079: model = (NetFileUserProfileModelImpl) viewBean.getModel();
080: model.initModel(viewBean.getUserDN());
081: }
082: return model;
083: }
084:
085: public NetFileAdminModelManager getNetFileModelMgr() {
086: if (modelManager == null) {
087: modelManager = (NetFileAdminModelManager) getRequestContext()
088: .getModelManager();
089: }
090: return modelManager;
091: }
092:
093: public boolean nextTile() throws ModelControlException {
094: boolean movedToRow = super .nextTile();
095: getNetFileModelMgr();
096: NetFileUserProfileModelImpl m = getModel();
097: boolean success = m.setCurrentRow(getTileIndex());
098:
099: if (movedToRow && success) {
100: DynamicGUI dg = null;
101: //DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
102: String name = m.getAttrName();
103: String label = m.getAttrLabel();
104: boolean required = false;
105: int attrType = m.getAttrType();
106: int attrSyntax = m.getAttrSyntax();
107: Set values = m.getAttrValues();
108:
109: /*
110: * Skip one tile if it is netfile host
111: */
112: if (name.equals("sunPortalNetFileCommonHostData")) {
113: movedToRow = super .nextTile();
114: success = m.setCurrentRow(getTileIndex());
115: if (movedToRow && success) {
116: name = m.getAttrName();
117: label = m.getAttrLabel();
118: attrType = m.getAttrType();
119: attrSyntax = m.getAttrSyntax();
120: values = m.getAttrValues();
121: } else {
122: return movedToRow;
123: }
124: }
125: if (attrType == DynamicGUI.TYPE_SINGLE) {
126: if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
127: String trueValue = m.getAttrTrueValue();
128: String falseValue = m.getAttrFalseValue();
129: String value = "";
130: if (values != null && values.iterator().hasNext()) {
131: value = (String) values.iterator().next();
132: }
133: dg = new DynamicGUI(name, label, required,
134: attrType, attrSyntax, trueValue,
135: falseValue, value);
136:
137: } else {
138: dg = new DynamicGUI(name, label, required,
139: attrType, attrSyntax, values);
140: }
141: } else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE
142: || attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE) {
143: String[] choices = m.getAttrChoices();
144: OptionList optionList = new OptionList(choices, choices);
145: dg = new DynamicGUI(name, label, required, attrType,
146: attrSyntax, values, optionList);
147: } else if (attrType == DynamicGUI.TYPE_LIST) {
148: dg = new DynamicGUI(name, label, required, attrType,
149: attrSyntax, values);
150: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
151: dg.setRemoveButtonStr(modelManager
152: .getString(REMOVE_BTN));
153: }
154: if (dg != null) {
155: dg.setReadOnly(m.isReadOnly());
156: }
157: if (!m.isReadOnly()) {
158: String status = m.getAttributeStatus(name);
159: if (status != null && status.trim().length() != 0) {
160: dg.setStatusValue(status);
161: dg.setStatusOptions(getStatusMenu(m));
162: }
163: }
164: setDisplayFieldValue(CC_ATTR_SET, dg);
165: }
166: return movedToRow;
167: }
168:
169: /**
170: * re-creates dynamic gui components for saving purposes
171: * @return dynamic gui components for action value
172: */
173: public List getDynamicCompList(int netfilehostsIndex) {
174: List dynamicGUIs = new ArrayList(10);
175: HttpServletRequest req = getRequestContext().getRequest();
176: int count = 0;
177: while (true) {
178: /**
179: * Skip if it is the index of NetFile host
180: * Because it is not a DynamicGUI type.
181: */
182: if (count == netfilehostsIndex) {
183: count++;
184: continue;
185: }
186: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
187: getQualifiedName(), CC_ATTR_SET, count++);
188:
189: if (dGUI != null) {
190: dynamicGUIs.add(dGUI);
191: } else {
192: break;
193: }
194: }
195: return dynamicGUIs;
196: }
197:
198: private OptionList getStatusMenu(NetFileUserProfileModelImpl model) {
199: OptionList optionList = new OptionList();
200:
201: optionList.add(model.getCustomizeLabel(), model
202: .getCustomizeValue());
203: optionList
204: .add(model.getInheritLabel(), model.getInheritValue());
205: optionList.add(model.getSkipLabel(), model.getSkipValue());
206:
207: return optionList;
208: }
209:
210: }
|