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.View;
030: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
031: import com.iplanet.jato.view.TiledView;
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.NetFileModel;
041:
042: public class NetFileViewBase extends RequestHandlingTiledViewBase
043: implements TiledView, RequestHandler {
044:
045: public static final String CC_ATTR_SET = "ccAttrSet";
046: public static final String ADD_BTN = "add.button";
047: public static final String REMOVE_BTN = "remove.button";
048: protected NetFileModel model = null;
049: protected NetFileAdminModelManager modelManager = null;
050: protected int viewType = 0;
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 NetFileViewBase(View parent, String name, int type) {
062: super (parent, name);
063: viewType = type;
064: setPrimaryModel((DatasetModel) getDefaultModel());
065: registerChild(CC_ATTR_SET, DynamicGUIComp.class);
066: }
067:
068: protected View createChild(String name) {
069: if (name.equals(CC_ATTR_SET)) {
070: return new DynamicGUIComp(this , CC_ATTR_SET, null);
071: } else {
072: throw new IllegalArgumentException("Invalid child name: "
073: + name);
074: }
075: }
076:
077: public void beginDisplay(DisplayEvent event)
078: throws ModelControlException {
079: getPrimaryModel().setSize(getModel().getSize(viewType));
080: }
081:
082: protected NetFileModel getModel() {
083: if (model == null) {
084: NetFileAdminService viewBean = (NetFileAdminService) getParentViewBean();
085: model = viewBean.getModel();
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: NetFileModel 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(viewType, getTileIndex());
138: if (movedToRow && success) {
139: DynamicGUI dg = null;
140: //DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
141: // Put row specific logic here
142: String name = m.getAttrName();
143: //String label = dg.getLabel();
144: //None is a required attribute.
145: //boolean required = false;
146: //int attrType = dg.getType();
147: //int attrSyntax = m.getAttrSyntax();
148: //Set values = m.getAttrValues();
149:
150: while (!isAttributeInList(name)) {
151: movedToRow = super .nextTile();
152: success = m.setCurrentRow(viewType, getTileIndex());
153: if (movedToRow && success) {
154: name = m.getAttrName();
155: //label = m.getAttrLabel();
156: //attrType = m.getAttrType();
157: //attrSyntax = m.getAttrSyntax();
158: //values = m.getAttrValues();
159: } else {
160: return movedToRow;
161: }
162: }
163: dg = m.getDynamicGUI();
164: if (dg.getType() == DynamicGUI.TYPE_LIST) {
165: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
166: dg.setRemoveButtonStr(modelManager
167: .getString(REMOVE_BTN));
168: }
169: /*
170: //Depending on the type and syntax, get value
171: if (attrType == DynamicGUI.TYPE_SINGLE) {
172: if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
173: String trueValue = m.getAttrTrueValue();
174: String falseValue = m.getAttrFalseValue();
175: String value = "";
176: if (values != null) {
177: value = (String)values.iterator().next();
178: }
179: dg = new DynamicGUI(name, label, required, attrType,
180: attrSyntax, trueValue, falseValue, value);
181: }
182: else {
183: dg = new DynamicGUI(name, label,
184: required, attrType, attrSyntax, values);
185: }
186: }
187: else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE ||
188: attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE ) {
189: String[] choices = m.getAttrChoices();
190: OptionList optionList = new OptionList(choices, choices);
191: dg = new DynamicGUI(name, label, required, attrType,
192: attrSyntax, values, optionList);
193: }
194: else if (attrType == DynamicGUI.TYPE_LIST) {
195: dg = new DynamicGUI(name, label, required, attrType,
196: attrSyntax, values);
197: dgc.setAddButtonStr(modelManager.getString(ADD_BTN));
198: dgc.setRemoveButtonStr(modelManager.getString(REMOVE_BTN));
199: }
200: */
201: setDisplayFieldValue(CC_ATTR_SET, dg);
202: }
203:
204: return movedToRow;
205: }
206:
207: /**
208: * re-creates dynamic gui components for saving purposes
209: *
210: * @return dynamic gui components for action value
211: */
212: public List getDynamicCompList() {
213: List dynamicGUIs = new ArrayList(10);
214: HttpServletRequest req = getRequestContext().getRequest();
215:
216: NetFileModel m = getModel();
217: for (int i = 0; i < attributeListSize; i++) {
218: attributeIndicesList[i] = m
219: .getNetFileAttributeIndex(attributeNameList[i]);
220: }
221:
222: int count = 0;
223: int componentsAdded = 0;
224: while (componentsAdded < attributeListSize) {
225: /*
226: * Skip if it is the index of Attributes not in this Bean's list
227: */
228: if (!isAttributeInList(count)) {
229: count++;
230: continue;
231: }
232:
233: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
234: getQualifiedName(), CC_ATTR_SET, count++);
235:
236: if (dGUI != null) {
237: dynamicGUIs.add(dGUI);
238: componentsAdded++;
239: } else {
240: break;
241: }
242: }
243: return dynamicGUIs;
244: }
245:
246: }
|