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.Iterator;
008: import java.util.Set;
009:
010: import javax.servlet.http.HttpServletRequest;
011:
012: import com.iplanet.am.console.base.AMViewBeanBase;
013: import com.iplanet.am.console.components.view.html.IPlanetButton;
014: import com.iplanet.am.console.components.view.html.MessageBox;
015: import com.iplanet.jato.model.ModelControlException;
016: import com.iplanet.jato.view.View;
017: import com.iplanet.jato.view.ViewBean;
018: import com.iplanet.jato.view.event.DisplayEvent;
019: import com.iplanet.jato.view.event.RequestInvocationEvent;
020: import com.iplanet.jato.view.html.ComboBox;
021: import com.iplanet.jato.view.html.HREF;
022: import com.iplanet.jato.view.html.OptionList;
023: import com.iplanet.jato.view.html.StaticTextField;
024: import com.iplanet.jato.view.html.TextField;
025: import com.sun.portal.rproxy.admin.model.GatewayModel;
026: import com.sun.portal.rproxy.admin.model.GatewayModelImpl;
027:
028: /**
029: * The viewbean that provides the select Gateway admin UI. Lists all the
030: * available gateway instance profile(s) and allow the administrator to delete
031: * or modify them. Also allows the administrators to create new gateway instance
032: * profile. The viewbean works with other viewbeans to support the above
033: * functionality.
034: */
035: public class GatewayCreateViewBean extends AMViewBeanBase {
036:
037: public static final String PAGE_NAME = "GatewayCreate";
038:
039: public static final String DEFAULT_DISPLAY_URL = "/ps/gwadmin/GatewayCreate.jsp";
040:
041: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
042:
043: public static final String CHILD_TILEDVIEW = "GatewayInstanceTiledView";
044:
045: public static final String TITLE_HTML_PAGE = "titleHtmlPage";
046:
047: public static final String CHILD_SVCNAME_HREF = "serviceNameHref";
048:
049: public static final String CHILD_SVCNAME = "serviceName";
050:
051: public static final String CHILD_SVCNAME_ACTION = "serviceNameAction";
052:
053: public static final String LBL_NEW_NAME = "lblNewName";
054:
055: public static final String TXT_NEW_INSTANCE_NAME = "txtInstanceName";
056:
057: public static final String LBL_EXISTING = "lblExisting";
058:
059: public static final String SHOW_MENU_CB = "comboShowMenu";
060:
061: public static final String CREATE_BTN = "CreateButton";
062:
063: public static final String CANCEL_BTN = "CancelButton";
064:
065: public static final String CREATE_GATEWAY_SESSION_INFO = "newGatewayName";
066:
067: public static final String COPY_GATEWAY_SESSION_INFO = "copyGatewayName";
068:
069: /**
070: * Used by the getModel method.
071: */
072: private GatewayModel model = null;
073:
074: private GatewayAdminModelManager modelManager = null;
075:
076: /**
077: * Default constructor.
078: */
079: public GatewayCreateViewBean() {
080: super (PAGE_NAME);
081: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
082: registerChildren();
083: }
084:
085: /**
086: * Creates the child view objects for this viewbean.
087: *
088: * @param name
089: * the name of the child view object to be created.
090: * @return the child view object.
091: */
092: protected View createChild(String name) {
093: /* get the model manager */
094: getGWModelMgr();
095: if (name.equals(TITLE_HTML_PAGE)) {
096: return new StaticTextField(this , TITLE_HTML_PAGE,
097: modelManager.getString("HTMLPage.title"));
098: } else if (name.equals(CHILD_CC_MSGBOX)) {
099: return new MessageBox(this , CHILD_CC_MSGBOX, "");
100: } else if (name.equals(CHILD_SVCNAME_HREF)) {
101: return new HREF(this , CHILD_SVCNAME_HREF, "");
102: } else if (name.equals(CHILD_SVCNAME)) {
103: return new StaticTextField(this , CHILD_SVCNAME,
104: modelManager.getString("service.name"));
105: } else if (name.equals(CHILD_SVCNAME_ACTION)) {
106: return new StaticTextField(this , CHILD_SVCNAME_ACTION,
107: modelManager.getString("createprofile.title"));
108: } else if (name.equals(LBL_NEW_NAME)) {
109: return new StaticTextField(this , LBL_NEW_NAME, modelManager
110: .getString("new.profile.label"));
111: } else if (name.equals(LBL_EXISTING)) {
112: return new StaticTextField(this , LBL_EXISTING, modelManager
113: .getString("existing.profile.label"));
114: } else if (name.equals(SHOW_MENU_CB)) {
115: return new ComboBox(this , SHOW_MENU_CB, "");
116: } else if (name.equals(TXT_NEW_INSTANCE_NAME)) {
117: return new TextField(this , TXT_NEW_INSTANCE_NAME, "");
118: } else if (name.equals(CREATE_BTN)) {
119: return new IPlanetButton(this , CREATE_BTN, modelManager
120: .getString("create.button"));
121: } else if (name.equals(CANCEL_BTN)) {
122: return new IPlanetButton(this , CANCEL_BTN, modelManager
123: .getString("cancel.button"));
124: } else {
125: return super .createChild(name);
126: }
127: }
128:
129: /**
130: * To register all the child view objects and their classes.
131: */
132: protected void registerChildren() {
133: registerChild(TITLE_HTML_PAGE, StaticTextField.class);
134: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
135: registerChild(CHILD_SVCNAME_HREF, HREF.class);
136: registerChild(CHILD_SVCNAME, StaticTextField.class);
137: registerChild(CHILD_SVCNAME_ACTION, StaticTextField.class);
138: registerChild(LBL_NEW_NAME, StaticTextField.class);
139: registerChild(TXT_NEW_INSTANCE_NAME, TextField.class);
140: registerChild(LBL_EXISTING, StaticTextField.class);
141: registerChild(SHOW_MENU_CB, ComboBox.class);
142: registerChild(CREATE_BTN, IPlanetButton.class);
143: registerChild(CANCEL_BTN, IPlanetButton.class);
144: }
145:
146: public void beginDisplay(DisplayEvent event) {
147: GatewayModel m = getModel();
148: setChildValues(model);
149: getGWModelMgr();
150: setDisplayFieldValue(HELP_DOC_URL, modelManager
151: .getString(GatewayAdminService.SRA_BASE_HLP_URL));
152: setDisplayFieldValue(HELP_ANCHOR_TAG, model
153: .getHelpAnchorTag(GatewayAdminService.SRA_GW_HLP_URL));
154: Set names = m.getConfigNames();
155: OptionList opList = new OptionList();
156: Iterator i = names.iterator();
157: while (i.hasNext()) {
158: String name = (String) i.next();
159: opList.add(name, name);
160: }
161: ComboBox cb = (ComboBox) getChild(SHOW_MENU_CB);
162: cb.setOptions(opList);
163: setDisplayFieldValue(CREATE_BTN, modelManager
164: .getString("create.button"));
165: setDisplayFieldValue(CANCEL_BTN, modelManager
166: .getString("cancel.button"));
167: }
168:
169: /**
170: * Creates the model instance.
171: *
172: * @returns Instance of model
173: */
174: public GatewayModel getModel() {
175: if (model == null) {
176: HttpServletRequest req = getRequestContext().getRequest();
177: req
178: .setAttribute(
179: GatewayAdminModelManager.SRAP_GATEWAY_MODEL_MGR_KEY,
180: getGWModelMgr());
181: model = new GatewayModelImpl(req);
182: }
183: return model;
184: }
185:
186: /**
187: * Called when Create button is clicked.
188: */
189: public void handleCreateButtonRequest(RequestInvocationEvent event)
190: throws ModelControlException {
191:
192: String newInstance = (String) getDisplayFieldValue(TXT_NEW_INSTANCE_NAME);
193: GatewayModel m = getModel();
194: Set names = m.getConfigNames();
195:
196: /* Display a recoverable error if no ruleset is selected */
197: newInstance = newInstance.trim();
198: if (newInstance.equals("") || names.contains(newInstance)) {
199: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
200: if (newInstance.equals("")) {
201: msgBox.setTitle(modelManager
202: .getString("noprofilenamemsgbox.title"));
203: msgBox.setMessage(modelManager
204: .getString("noprofilenamemsgbox.msg"));
205: } else {
206: msgBox.setTitle(modelManager
207: .getString("duplicatenamemsgbox.title"));
208: msgBox.setMessage(modelManager
209: .getString("duplicatenamemsgbox.msg"));
210: }
211: msgBox.setType(MessageBox.TYPE_ERROR);
212: msgBox.setVisible(true);
213: /* Redisplay the page with the error */
214: forwardTo();
215: } else {
216: m.store(newInstance,
217: (String) getDisplayFieldValue(SHOW_MENU_CB));
218:
219: ViewBean vb = getViewBean(GatewaySelectViewBean.class);
220: vb.forwardTo(getRequestContext());
221: }
222: }
223:
224: /**
225: * Called when Cancel button is clicked. Moves to gateway select page
226: */
227: public void handleCancelButtonRequest(RequestInvocationEvent event)
228: throws ModelControlException {
229: /* Forward to the create rule viewbean */
230: ViewBean vb = getViewBean(GatewaySelectViewBean.class);
231: vb.forwardTo(getRequestContext());
232: }
233:
234: public void handleServiceNameHrefRequest(
235: RequestInvocationEvent event) throws ModelControlException {
236: /* Forward to the create rule viewbean */
237: ViewBean vb = getViewBean(GatewaySelectViewBean.class);
238: vb.forwardTo(getRequestContext());
239: }
240:
241: public GatewayAdminModelManager getGWModelMgr() {
242: if (modelManager == null) {
243: modelManager = (GatewayAdminModelManager) getRequestContext()
244: .getModelManager();
245: }
246: return modelManager;
247: }
248:
249: }
|