/**
* Copyright 2002 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*
* @ Author Bhavanishankar
*/
package com.sun.portal.netlet.admin;
// JDK classes
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import com.iplanet.am.console.components.view.html.DynamicGUI;
import com.iplanet.am.console.components.view.html.DynamicGUIComp;
import com.iplanet.jato.RequestHandler;
import com.iplanet.jato.model.DatasetModel;
import com.iplanet.jato.model.ModelControlException;
import com.iplanet.jato.view.RequestHandlingTiledViewBase;
import com.iplanet.jato.view.TiledView;
import com.iplanet.jato.view.View;
import com.iplanet.jato.view.event.DisplayEvent;
import com.sun.portal.netlet.admin.model.NetletAdminServiceModel;
public class NetletAdminServiceView extends RequestHandlingTiledViewBase implements TiledView, RequestHandler {
public static final String CC_ATTR_SET = "ccAttrSet";
public static final String ADD_BTN = "add.button";
public static final String REMOVE_BTN = "remove.button";
private NetletAdminServiceModel model = null;
private NetletAdminModelManager modelManager = null;
private int viewType = 0;
/*
* @param parent The reference of the parent container @param name The name
* of this view.
*/
public NetletAdminServiceView(View parent, String name, int type) {
super(parent, name);
viewType = type;
setPrimaryModel((DatasetModel) getDefaultModel());
registerChild(CC_ATTR_SET, DynamicGUIComp.class);
}
protected View createChild(String name) {
if (name.equals(CC_ATTR_SET)) {
return new DynamicGUIComp(this, CC_ATTR_SET, null);
} else {
throw new IllegalArgumentException("Invalid child name: " + name);
}
}
public void beginDisplay(DisplayEvent event) throws ModelControlException {
getPrimaryModel().setSize(getModel().getSize(viewType));
}
protected NetletAdminServiceModel getModel() {
if (model == null) {
NetletAdminService viewBean = (NetletAdminService) getParentViewBean();
model = viewBean.getModel();
}
return model;
}
public NetletAdminModelManager getNetletModelMgr() {
if (modelManager == null) {
modelManager = (NetletAdminModelManager) getRequestContext().getModelManager();
}
return modelManager;
}
public boolean nextTile() throws ModelControlException {
boolean movedToRow = super.nextTile();
NetletAdminServiceModel m = getModel();
getNetletModelMgr();
boolean success = m.setCurrentRow(viewType, getTileIndex());
if (movedToRow && success) {
DynamicGUI dg = null;
// DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
String name = m.getAttrName();
// String label = m.getDynamicGUI().getLabel();
// boolean required = false;
// int attrType = m.getDynamicGUI().getType();
// int attrSyntax = m.getAttrSyntax();
// Set values = m.getAttrValues();
/*
* Skip one tile if it is netlet rule
*/
if (name.equals("sunPortalNetletRules")) {
movedToRow = super.nextTile();
success = m.setCurrentRow(viewType, getTileIndex());
if (movedToRow && success) {
name = m.getAttrName();
// label = m.getDynamicGUI().getLabel();
// attrType = m.getDynamicGUI().getType();
// attrSyntax = m.getAttrSyntax();
// values = m.getAttrValues();
} else {
return movedToRow;
}
}
//
dg = m.getDynamicGUI();
if (dg.getType() == DynamicGUI.TYPE_LIST) {
dg.setAddButtonStr(modelManager.getString(ADD_BTN));
dg.setRemoveButtonStr(modelManager.getString(REMOVE_BTN));
}
/*
* if (attrType == DynamicGUI.TYPE_SINGLE) { if (attrSyntax ==
* DynamicGUI.SYNTAX_BOOLEAN) { String trueValue =
* m.getDynamicGUI().getTrueValue(); String falseValue =
* m.getDynamicGUI().getFalseValue(); String value = ""; if (values !=
* null) { value = (String)values.iterator().next(); } dg = new
* DynamicGUI(name, label, required, attrType, attrSyntax,
* trueValue, falseValue, value); } else { dg = new DynamicGUI(name,
* label, required, attrType, attrSyntax, values); } } else if
* (attrType == DynamicGUI.TYPE_SINGLE_CHOICE || attrType ==
* DynamicGUI.TYPE_MULTIPLE_CHOICE ) { //String[] choices =
* m.getDynamicGUI().getAttrChoices(); //OptionList optionList = new
* OptionList(choices, choices); OptionList optionList =
* m.getDynamicGUI().getOptions(); dg = new DynamicGUI(name, label,
* required, attrType, attrSyntax, values, optionList); } else if
* (attrType == DynamicGUI.TYPE_LIST) { dg = new DynamicGUI(name,
* label, required, attrType, attrSyntax, values);
* dg.setAddButtonStr(modelManager.getString(ADD_BTN));
* dg.setRemoveButtonStr(modelManager.getString(REMOVE_BTN)); }
*/
setDisplayFieldValue(CC_ATTR_SET, dg);
}
return movedToRow;
}
/**
* re-creates dynamic gui components for saving purposes
*
* @return dynamic gui components for action value
*/
public List getDynamicCompList(int netletrulesIndex) {
List dynamicGUIs = new ArrayList(10);
HttpServletRequest req = getRequestContext().getRequest();
int count = 0;
while (true) {
/*
* Skip if it is the index of Netlet rule Because it is not a
* DynamicGUI type.
*/
if (count == netletrulesIndex) {
count++;
continue;
}
DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req, getQualifiedName(), CC_ATTR_SET, count++);
if (dGUI != null) {
dynamicGUIs.add(dGUI);
} else {
break;
}
}
return dynamicGUIs;
}
}
|