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 javax.servlet.http.HttpServletRequest;
008:
009: import com.iplanet.am.console.base.AMViewBeanBase;
010: import com.iplanet.am.console.components.view.html.MessageBox;
011: import com.iplanet.jato.NavigationException;
012: import com.iplanet.jato.RequestContext;
013: import com.iplanet.jato.model.ModelControlException;
014: import com.iplanet.jato.view.View;
015: import com.iplanet.jato.view.ViewBean;
016: import com.iplanet.jato.view.event.DisplayEvent;
017: import com.iplanet.jato.view.html.StaticTextField;
018: import com.sun.portal.rproxy.admin.model.GatewayModel;
019: import com.sun.portal.rproxy.admin.model.GatewayModelImpl;
020:
021: /**
022: * The viewbean that provides the delete gateway profile functionality.
023: */
024: public class GatewayDeleteViewBean extends AMViewBeanBase {
025:
026: public static final String PAGE_NAME = "GatewayDelete";
027:
028: public static final String DEFAULT_DISPLAY_URL = "/ps/gwadmin/GatewayDelete.jsp";
029:
030: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
031:
032: public static final String LBL_DELETE_TITLE = "titleDeleteGateway";
033:
034: private GatewayModel model = null;
035:
036: private GatewayAdminModelManager modelManager = null;
037:
038: /**
039: * Default constructor
040: *
041: */
042: public GatewayDeleteViewBean() {
043: super (PAGE_NAME);
044: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
045: registerChildren();
046: }
047:
048: /**
049: * Creates the child view objects for this viewbean.
050: *
051: * @param name
052: * the name of the child view object to be created.
053: * @return the child view object.
054: */
055: protected View createChild(String name) {
056: if (name.equals(LBL_DELETE_TITLE)) {
057: return new StaticTextField(this , LBL_DELETE_TITLE,
058: modelManager.getString("delete.profile.label"));
059: } else if (name.equals(CHILD_CC_MSGBOX)) {
060: return new MessageBox(this , CHILD_CC_MSGBOX, "");
061: } else {
062: throw new IllegalArgumentException(name);
063: }
064: }
065:
066: /**
067: * To register all the child view objects and their classes.
068: */
069: protected void registerChildren() {
070: registerChild(LBL_DELETE_TITLE, StaticTextField.class);
071: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
072: }
073:
074: public void beginDisplay(DisplayEvent event)
075: throws ModelControlException {
076: getModel();
077: getGWModelMgr();
078: setDisplayFieldValue(HELP_DOC_URL, modelManager
079: .getString(GatewayAdminService.SRA_BASE_HLP_URL));
080: setDisplayFieldValue(HELP_ANCHOR_TAG, model
081: .getHelpAnchorTag(GatewayAdminService.SRA_GW_HLP_URL));
082: }
083:
084: public void forwardTo(RequestContext reqContext)
085: throws NavigationException {
086: setRequestContext(reqContext);
087: MessageBox msgbox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
088: getModel();
089: GatewayAdminModelManager gwMgr = getGWModelMgr();
090: String[] profileNames = gwMgr
091: .getFromSession(GatewaySelectViewBean.SELECT_GATEWAY_SESSION_INFO);
092:
093: try {
094: model.deleteConfig(profileNames);
095: ViewBean vb = getViewBean(GatewaySelectViewBean.class);
096: vb.forwardTo(reqContext);
097: } catch (Exception e) {
098:
099: /* Display an error msgbox when excetion occurres */
100: getGWModelMgr();
101: if ((profileNames != null) && (profileNames.length > 0)) {
102: StringBuffer sb = new StringBuffer("<ul>");
103: for (int i = 0; i < profileNames.length; i++) {
104: sb.append("<li>");
105: sb.append((String) profileNames[i]);
106: sb.append("</li>");
107: }
108: sb.append("</ul>");
109: msgbox.setType(MessageBox.TYPE_ERROR);
110: msgbox.setTitle(modelManager
111: .getString("deleteprofileerrormsgbox.title")
112: + e.getMessage());
113: msgbox.setMessage(sb.toString());
114: msgbox.setVisible(true);
115: msgbox.addButton(modelManager
116: .getString("deleteprofilerrormsgbox.oklabel"),
117: getModuleURL() + "/"
118: + GatewaySelectViewBean.PAGE_NAME);
119: }
120: }
121: }
122:
123: /**
124: * Deletes the selected gateway profile(s) after the model executes.
125: *
126: * @param model
127: * the model object that just finish execution.
128: * @param context
129: * the execution context
130: */
131:
132: /*
133: * public void afterModelExecutes(Model model, int context) { if ((model
134: * instanceof GatewayModel) && (context ==
135: * WebActionHandler.RETRIEVE_CONTEXT)) { MessageBox msgbox = (MessageBox)
136: * getDisplayField(CHILD_CC_MSGBOX); GatewayModel dmodel = (GatewayModel)
137: * model; GatewayAdminModelManager gwMgr = getGWModelMgr(); String[]
138: * profileNames = gwMgr.getFromSession(
139: * GatewaySelectViewBean.SELECT_GATEWAY_SESSION_INFO);
140: *
141: * try { dmodel.deleteConfig(profileNames);
142: *
143: * ViewBean vb = getViewBean(GatewaySelectViewBean.class);
144: * vb.forwardTo(getRequestContext()); } catch (Exception e) {
145: *
146: * getGWModelMgr(); if ((profileNames != null) && (profileNames.length > 0)) {
147: * StringBuffer sb = new StringBuffer(" <ul> "); for (int i = 0; i <
148: * profileNames.length; i++) { sb.append(" <li> ");
149: * sb.append((String)profileNames[i]); sb.append(" </li> "); } sb.append("
150: * </ul> "); msgbox.setType(MessageBox.TYPE_ERROR); msgbox.setTitle(
151: * modelManager.getString("deleteprofileerrormsgbox.title") +
152: * e.getMessage()); msgbox.setMessage(sb.toString());
153: * msgbox.setVisible(true);
154: * msgbox.addButton(modelManager.getString("deleteprofilerrormsgbox.oklabel"),
155: * getModuleURL()+"/"+GatewaySelectViewBean.PAGE_NAME); } } } }
156: */
157: public GatewayAdminModelManager getGWModelMgr() {
158: if (modelManager == null) {
159: modelManager = (GatewayAdminModelManager) getRequestContext()
160: .getModelManager();
161: }
162: return modelManager;
163: }
164:
165: /**
166: * Returns the model object for the delete gateway profile UI.
167: *
168: * @return the model object for the delete gateway profile UI.
169: */
170: public GatewayModel getModel() {
171: if (model == null) {
172: HttpServletRequest req = getRequestContext().getRequest();
173: model = new GatewayModelImpl(req);
174: }
175: /*
176: * try { model = (GatewayModel)getRequestContext()
177: * .getModelManager().getModel(GatewayModelImpl.class); } catch
178: * (Throwable t) { }
179: *
180: * model.setValue(GatewayAdminModelManager.SRAP_GATEWAY_MODEL_MGR_KEY,
181: * getGWModelMgr());
182: * model.setValue(GatewaySelectModel.SRAP_GATEWAY_ADMIN_REQ_OBJ_KEY,
183: * getRequestContext().getRequest());
184: */
185: return model;
186: }
187: }
|