001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rproxy.admin;
006:
007: import java.util.List;
008: import java.util.Vector;
009:
010: import javax.servlet.http.HttpServletRequest;
011:
012: import com.iplanet.jato.RequestHandler;
013: import com.iplanet.jato.model.DatasetModel;
014: import com.iplanet.jato.model.ModelControlException;
015: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
016: import com.iplanet.jato.view.TiledView;
017: import com.iplanet.jato.view.View;
018: import com.iplanet.jato.view.event.DisplayEvent;
019: import com.iplanet.jato.view.event.RequestInvocationEvent;
020: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
021: import com.iplanet.jato.view.html.CheckBox;
022: import com.iplanet.jato.view.html.HREF;
023: import com.iplanet.jato.view.html.HiddenField;
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.sun.portal.rproxy.admin.model.GatewayModel;
026: import com.sun.portal.rproxy.admin.model.GatewayModelImpl;
027:
028: /**
029: * The tileview that lists each gateway instance profile in the select gateway
030: * admin UI. The GatewaySelectViewBean is the parent of this tileview where all
031: * the tile(s)/gateway instance profile(s) are displayed.
032: */
033: public class GatewaySelectTiledView extends
034: RequestHandlingTiledViewBase implements TiledView,
035: RequestHandler {
036: public static final String CHILD_CB_SELECT_GATEWAY = "cbGatewaySelect";
037:
038: public static final String CHILD_HREF_TEXT = "hrefText";
039:
040: public static final String CHILD_HREF_GATEWAY_EDIT = "hrefGatewayEdit";
041:
042: public static final String CHILD_GATEWAY_PROFILE_NAME = "profileName";
043:
044: public static final String CHILD_EDIT_LABEL = "editLabel";
045:
046: /* the maximum number of tiles per page */
047: private static final int MAX_DISPLAY_TILES = 100;
048:
049: private GatewayModel model = null;
050:
051: private GatewayAdminModelManager modelManager = null;
052:
053: private List configNames = null;
054:
055: /**
056: * Default constructor.
057: *
058: * @param parent
059: * the parent view of this tileview.
060: * @param name
061: * the name of this tileview.
062: */
063: public GatewaySelectTiledView(View parent, String name) {
064: super (parent, name);
065: setMaxDisplayTiles(MAX_DISPLAY_TILES);
066: setPrimaryModel((DatasetModel) getDefaultModel());
067: // setPrimaryModelClass(GatewayModel.class);
068: registerChildren();
069: }
070:
071: /**
072: * Register the child objects of the tileview.
073: */
074: protected void registerChildren() {
075: registerChild(CHILD_CB_SELECT_GATEWAY, CheckBox.class);
076: registerChild(CHILD_HREF_TEXT, StaticTextField.class);
077: registerChild(CHILD_HREF_GATEWAY_EDIT, HREF.class);
078: registerChild(CHILD_EDIT_LABEL, StaticTextField.class);
079: registerChild(CHILD_GATEWAY_PROFILE_NAME, HiddenField.class);
080: }
081:
082: /**
083: * Creates and return the child view objects for the specified name.
084: *
085: * @param name
086: * the child view name.
087: * @return the child view object that corresponds to the given name.
088: */
089: protected View createChild(String name) {
090: getGWModelMgr();
091: if (name.equals(CHILD_CB_SELECT_GATEWAY)) {
092: return new CheckBox(this , CHILD_CB_SELECT_GATEWAY, "true",
093: "false", false);
094: } else if (name.equals(CHILD_HREF_TEXT)) {
095: return new StaticTextField(this , CHILD_HREF_TEXT, "");
096: } else if (name.equals(CHILD_HREF_GATEWAY_EDIT)) {
097: return new HREF(this , CHILD_HREF_GATEWAY_EDIT, "");
098: } else if (name.equals(CHILD_GATEWAY_PROFILE_NAME)) {
099: return new HiddenField(this , CHILD_GATEWAY_PROFILE_NAME, "");
100: } else if (name.equals(CHILD_EDIT_LABEL)) {
101: return new StaticTextField(this , CHILD_EDIT_LABEL,
102: modelManager.getString("edit.label"));
103: } else {
104: throw new IllegalArgumentException(name);
105: }
106: }
107:
108: /**
109: * begins displaying page. we set the required information
110: *
111: * @param event
112: * display event
113: * @throws ModelControlException
114: * if problem access value of component
115: */
116: public void beginDisplay(DisplayEvent event)
117: throws ModelControlException {
118: if (getPrimaryModel() == null) {
119: throw new ModelControlException("Primary model is null");
120: }
121: getGWModelMgr();
122: getModel();
123: configNames = new Vector(model.getConfigNames());
124: // ruleNames = rwm.getRuleSetNames();
125:
126: if (model != null) {
127: getPrimaryModel().setSize(model.getGatewayProfileCount());
128: } else {
129: getPrimaryModel().setSize(0);
130: }
131: super .beginDisplay(event);
132: resetTileIndex();
133: }
134:
135: /**
136: * Returns the model object for the select gateway UI.
137: *
138: * @return the model object for the select gateway UI.
139: */
140: public GatewayModel getModel() {
141: if (model == null) {
142: HttpServletRequest req = getRequestContext().getRequest();
143: model = new GatewayModelImpl(req);
144: }
145: /*
146: * GatewayModel model = (GatewayModel) getRequestContext()
147: * .getModelManager().getModel(GatewaySelectModel.class);
148: * model.setValue(GatewaySelectModel.SRAP_GATEWAY_ADMIN_REQ_OBJ_KEY,
149: * getRequestContext().getRequest());
150: *
151: */return model;
152: }
153:
154: public void handleHrefGatewayEditRequest(
155: RequestInvocationEvent event) throws ModelControlException {
156:
157: getPrimaryModel().setLocation(
158: ((TiledViewRequestInvocationEvent) event)
159: .getTileNumber());
160:
161: GatewayAdminModelManager gwMgr = getGWModelMgr();
162: gwMgr
163: .storeToSession(
164: GatewaySelectViewBean.SELECT_GATEWAY_SESSION_INFO,
165: new String[] { (String) getDisplayFieldValue(CHILD_HREF_GATEWAY_EDIT) });
166:
167: /* Forward to the gateway data viewbean. */
168: Gateway1ViewBean vb = (Gateway1ViewBean) getViewBean(Gateway1ViewBean.class);
169: vb.forwardTo(getRequestContext());
170: }
171:
172: public GatewayAdminModelManager getGWModelMgr() {
173: if (modelManager == null) {
174: GatewaySelectViewBean viewBean = (GatewaySelectViewBean) getParentViewBean();
175: modelManager = viewBean.getGWModelMgr();
176: }
177: return modelManager;
178: }
179:
180: public boolean nextTile() throws ModelControlException {
181: boolean movedToRow = super .nextTile();
182: if (movedToRow) {
183: String configName = (String) configNames
184: .get(getTileIndex());
185: setDisplayFieldValue(CHILD_GATEWAY_PROFILE_NAME, configName);
186: setDisplayFieldValue(CHILD_HREF_GATEWAY_EDIT, configName);
187: setDisplayFieldValue(CHILD_HREF_TEXT, configName);
188: setDisplayFieldValue(CHILD_EDIT_LABEL, modelManager
189: .getString("edit.label"));
190: }
191: return movedToRow;
192: }
193:
194: }
|