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 NetFileUserProfileViewBase 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: protected NetFileUserProfileModelImpl model = null;
050: protected NetFileAdminModelManager modelManager = null;
051:
052: protected int attributeListSize;
053: protected String[] attributeNameList;
054: protected boolean attributeIndicesSet;
055: protected int[] attributeIndicesList;
056:
057: /*
058: * @param parent The reference of the parent container
059: * @param name The name of this view.
060: */
061: public NetFileUserProfileViewBase(View parent, String name) {
062: super (parent, name);
063: setPrimaryModel((DatasetModel) getDefaultModel());
064: registerChild(CC_ATTR_SET, DynamicGUIComp.class);
065: }
066:
067: protected View createChild(String name) {
068: if (name.equals(CC_ATTR_SET)) {
069: return new DynamicGUIComp(this , CC_ATTR_SET, null);
070: } else {
071: throw new IllegalArgumentException("Invalid child name: "
072: + name);
073: }
074: }
075:
076: public void beginDisplay(DisplayEvent event)
077: throws ModelControlException {
078: getPrimaryModel().setSize(getModel().getSize());
079: }
080:
081: protected NetFileUserProfileModelImpl getModel() {
082: if (model == null) {
083: NetFileUserProfileViewBeanBase viewBean = (NetFileUserProfileViewBeanBase) getParentViewBean();
084: model = (NetFileUserProfileModelImpl) viewBean.getModel();
085: model.initModel(viewBean.getUserDN());
086: }
087: return model;
088: }
089:
090: public NetFileAdminModelManager getNetFileModelMgr() {
091: if (modelManager == null) {
092: modelManager = (NetFileAdminModelManager) getRequestContext()
093: .getModelManager();
094: }
095: return modelManager;
096: }
097:
098: protected boolean isAttributeInList(int aIndex) {
099: boolean result = false;
100: int count;
101:
102: for (count = 0; count < attributeListSize; count++) {
103: if (aIndex == attributeIndicesList[count]) {
104: result = true;
105: break;
106: }
107: }
108: return result;
109: }
110:
111: protected boolean isAttributeInList(String aName) {
112: boolean result = false;
113: int count;
114:
115: for (count = 0; count < attributeListSize; count++) {
116: if (aName.equals(attributeNameList[count])) {
117: result = true;
118: break;
119: }
120: }
121: return result;
122: }
123:
124: public boolean nextTile() throws ModelControlException {
125: boolean movedToRow = super .nextTile();
126: NetFileUserProfileModelImpl m = getModel();
127: getNetFileModelMgr();
128:
129: if (!attributeIndicesSet) {
130: for (int i = 0; i < attributeListSize; i++) {
131: attributeIndicesList[i] = m
132: .getNetFileAttributeIndex(attributeNameList[i]);
133: }
134: attributeIndicesSet = true;
135: }
136:
137: boolean success = m.setCurrentRow(getTileIndex());
138: if (movedToRow && success) {
139: DynamicGUI dg = null;
140: //DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
141: String name = m.getAttrName();
142: String label = m.getAttrLabel();
143: boolean required = false;
144: int attrType = m.getAttrType();
145: int attrSyntax = m.getAttrSyntax();
146: Set values = m.getAttrValues();
147:
148: while (!isAttributeInList(name)) {
149: movedToRow = super .nextTile();
150: success = m.setCurrentRow(getTileIndex());
151: if (movedToRow && success) {
152: name = m.getAttrName();
153: label = m.getAttrLabel();
154: attrType = m.getAttrType();
155: attrSyntax = m.getAttrSyntax();
156: values = m.getAttrValues();
157: } else {
158: return movedToRow;
159: }
160: }
161: if (attrType == DynamicGUI.TYPE_SINGLE) {
162: if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
163: String trueValue = m.getAttrTrueValue();
164: String falseValue = m.getAttrFalseValue();
165: String value = "";
166: if (values != null && values.iterator().hasNext()) {
167: value = (String) values.iterator().next();
168: }
169: dg = new DynamicGUI(name, label, required,
170: attrType, attrSyntax, trueValue,
171: falseValue, value);
172: } else {
173: dg = new DynamicGUI(name, label, required,
174: attrType, attrSyntax, values);
175: }
176: } else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE
177: || attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE) {
178: String[] choices = m.getAttrChoices();
179: OptionList optionList = new OptionList(choices, choices);
180: dg = new DynamicGUI(name, label, required, attrType,
181: attrSyntax, values, optionList);
182: } else if (attrType == DynamicGUI.TYPE_LIST) {
183: dg = new DynamicGUI(name, label, required, attrType,
184: attrSyntax, values);
185: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
186: dg.setRemoveButtonStr(modelManager
187: .getString(REMOVE_BTN));
188: }
189: if (dg != null) {
190: dg.setReadOnly(m.isReadOnly());
191: }
192: if (!m.isReadOnly()) {
193: String status = m.getAttributeStatus(name);
194: if (status != null && status.trim().length() != 0) {
195: dg.setStatusValue(status);
196: dg.setStatusOptions(getStatusMenu(m));
197: }
198: }
199: setDisplayFieldValue(CC_ATTR_SET, dg);
200: }
201: return movedToRow;
202: }
203:
204: /**
205: * re-creates dynamic gui components for saving purposes
206: *
207: * @return dynamic gui components for action value
208: */
209: public List getDynamicCompList() {
210: List dynamicGUIs = new ArrayList(10);
211: HttpServletRequest req = getRequestContext().getRequest();
212:
213: NetFileUserProfileModelImpl m = getModel();
214: for (int i = 0; i < attributeListSize; i++) {
215: attributeIndicesList[i] = m
216: .getNetFileAttributeIndex(attributeNameList[i]);
217: }
218:
219: int count = 0;
220: int componentsAdded = 0;
221: while (componentsAdded < attributeListSize) {
222: /*
223: * Skip if it is the index of Attributes not in this Bean's list
224: */
225: if (!isAttributeInList(count)) {
226: count++;
227: continue;
228: }
229:
230: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
231: getQualifiedName(), CC_ATTR_SET, count++);
232:
233: if (dGUI != null) {
234: dynamicGUIs.add(dGUI);
235: componentsAdded++;
236: } else {
237: break;
238: }
239: }
240:
241: return dynamicGUIs;
242: }
243:
244: protected OptionList getStatusMenu(NetFileUserProfileModelImpl model) {
245: OptionList optionList = new OptionList();
246:
247: optionList.add(model.getCustomizeLabel(), model
248: .getCustomizeValue());
249: optionList
250: .add(model.getInheritLabel(), model.getInheritValue());
251: optionList.add(model.getSkipLabel(), model.getSkipValue());
252:
253: return optionList;
254: }
255:
256: }
|