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.sun.portal.netlet.admin.model.NetletAdminServiceModel;
034:
035: public class NetletAdminServiceView extends
036: RequestHandlingTiledViewBase implements TiledView,
037: RequestHandler {
038:
039: public static final String CC_ATTR_SET = "ccAttrSet";
040:
041: public static final String ADD_BTN = "add.button";
042:
043: public static final String REMOVE_BTN = "remove.button";
044:
045: private NetletAdminServiceModel model = null;
046:
047: private NetletAdminModelManager modelManager = null;
048:
049: private int viewType = 0;
050:
051: /*
052: * @param parent The reference of the parent container @param name The name
053: * of this view.
054: */
055: public NetletAdminServiceView(View parent, String name, int type) {
056: super (parent, name);
057: viewType = type;
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(viewType));
074: }
075:
076: protected NetletAdminServiceModel getModel() {
077: if (model == null) {
078: NetletAdminService viewBean = (NetletAdminService) getParentViewBean();
079: model = viewBean.getModel();
080: }
081: return model;
082: }
083:
084: public NetletAdminModelManager getNetletModelMgr() {
085: if (modelManager == null) {
086: modelManager = (NetletAdminModelManager) getRequestContext()
087: .getModelManager();
088: }
089: return modelManager;
090: }
091:
092: public boolean nextTile() throws ModelControlException {
093: boolean movedToRow = super .nextTile();
094: NetletAdminServiceModel m = getModel();
095: getNetletModelMgr();
096: boolean success = m.setCurrentRow(viewType, getTileIndex());
097: if (movedToRow && success) {
098: DynamicGUI dg = null;
099: // DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
100: String name = m.getAttrName();
101: // String label = m.getDynamicGUI().getLabel();
102: // boolean required = false;
103: // int attrType = m.getDynamicGUI().getType();
104: // int attrSyntax = m.getAttrSyntax();
105: // Set values = m.getAttrValues();
106:
107: /*
108: * Skip one tile if it is netlet rule
109: */
110: if (name.equals("sunPortalNetletRules")) {
111: movedToRow = super .nextTile();
112: success = m.setCurrentRow(viewType, getTileIndex());
113: if (movedToRow && success) {
114: name = m.getAttrName();
115: // label = m.getDynamicGUI().getLabel();
116: // attrType = m.getDynamicGUI().getType();
117: // attrSyntax = m.getAttrSyntax();
118: // values = m.getAttrValues();
119: } else {
120: return movedToRow;
121: }
122: }
123: //
124: dg = m.getDynamicGUI();
125: if (dg.getType() == DynamicGUI.TYPE_LIST) {
126: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
127: dg.setRemoveButtonStr(modelManager
128: .getString(REMOVE_BTN));
129: }
130:
131: /*
132: * if (attrType == DynamicGUI.TYPE_SINGLE) { if (attrSyntax ==
133: * DynamicGUI.SYNTAX_BOOLEAN) { String trueValue =
134: * m.getDynamicGUI().getTrueValue(); String falseValue =
135: * m.getDynamicGUI().getFalseValue(); String value = ""; if (values !=
136: * null) { value = (String)values.iterator().next(); } dg = new
137: * DynamicGUI(name, label, required, attrType, attrSyntax,
138: * trueValue, falseValue, value); } else { dg = new DynamicGUI(name,
139: * label, required, attrType, attrSyntax, values); } } else if
140: * (attrType == DynamicGUI.TYPE_SINGLE_CHOICE || attrType ==
141: * DynamicGUI.TYPE_MULTIPLE_CHOICE ) { //String[] choices =
142: * m.getDynamicGUI().getAttrChoices(); //OptionList optionList = new
143: * OptionList(choices, choices); OptionList optionList =
144: * m.getDynamicGUI().getOptions(); dg = new DynamicGUI(name, label,
145: * required, attrType, attrSyntax, values, optionList); } else if
146: * (attrType == DynamicGUI.TYPE_LIST) { dg = new DynamicGUI(name,
147: * label, required, attrType, attrSyntax, values);
148: * dg.setAddButtonStr(modelManager.getString(ADD_BTN));
149: * dg.setRemoveButtonStr(modelManager.getString(REMOVE_BTN)); }
150: */
151: setDisplayFieldValue(CC_ATTR_SET, dg);
152: }
153: return movedToRow;
154: }
155:
156: /**
157: * re-creates dynamic gui components for saving purposes
158: *
159: * @return dynamic gui components for action value
160: */
161:
162: public List getDynamicCompList(int netletrulesIndex) {
163: List dynamicGUIs = new ArrayList(10);
164: HttpServletRequest req = getRequestContext().getRequest();
165:
166: int count = 0;
167: while (true) {
168:
169: /*
170: * Skip if it is the index of Netlet rule Because it is not a
171: * DynamicGUI type.
172: */
173: if (count == netletrulesIndex) {
174: count++;
175: continue;
176: }
177: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
178: getQualifiedName(), CC_ATTR_SET, count++);
179:
180: if (dGUI != null) {
181: dynamicGUIs.add(dGUI);
182: } else {
183: break;
184: }
185: }
186: return dynamicGUIs;
187: }
188:
189: }
|