001: package com.sun.portal.rproxy.admin;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import javax.servlet.http.HttpServletRequest;
007:
008: import com.iplanet.am.console.base.AMMessageViewBean;
009: import com.iplanet.am.console.base.AMViewBeanBase;
010: import com.iplanet.am.console.components.view.html.IPlanetButton;
011: import com.iplanet.am.console.components.view.html.MessageBox;
012: import com.iplanet.jato.RequestContext;
013: import com.iplanet.jato.ViewBeanManager;
014: import com.iplanet.jato.model.ModelControlException;
015: import com.iplanet.jato.view.View;
016: import com.iplanet.jato.view.ViewBean;
017: import com.iplanet.jato.view.event.ChildDisplayEvent;
018: import com.iplanet.jato.view.event.DisplayEvent;
019: import com.iplanet.jato.view.event.RequestInvocationEvent;
020: import com.iplanet.jato.view.html.CheckBox;
021: import com.iplanet.jato.view.html.StaticTextField;
022: import com.sun.portal.rproxy.admin.model.GatewayModel;
023: import com.sun.portal.rproxy.admin.model.GatewayModelImpl;
024:
025: /**
026: * The viewbean that provides the select Gateway admin UI. Lists all the
027: * available gateway instance profile(s) and allow the administrator to delete
028: * or modify them. Also allows the administrators to create new gateway instance
029: * profile. The viewbean works with other viewbeans to support the above
030: * functionality.
031: */
032: public class GatewaySelectViewBean extends AMViewBeanBase {
033:
034: public static final String PAGE_NAME = "GatewaySelect";
035:
036: public static final String DEFAULT_DISPLAY_URL = "/ps/gwadmin/GatewaySelect.jsp";
037:
038: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
039:
040: public static final String CHILD_TILEDVIEW = "GatewayInstanceTiledView";
041:
042: public static final String CHILD_PAGE_TITLE = "titleHtmlPage";
043:
044: public static final String LBL_NAME = "lblName";
045:
046: public static final String LBL_SERVICE_TITLE = "serviceTitle";
047:
048: public static final String LBL_PROFILE = "profileLabel";
049:
050: public static final String LBL_ACTION = "lblAction";
051:
052: public static final String DELETE_BTN = "DeleteButton";
053:
054: public static final String CREATE_BTN = "NewButton";
055:
056: public static final String SELECT_GATEWAY_SESSION_INFO = "selectedGateway";
057:
058: private GatewayModel model = null;
059:
060: private GatewayAdminModelManager modelManager = null;
061:
062: /**
063: * This constructor will be used by the subclass view bean. It does not set
064: * the display url, and the subclass needs to do that.
065: *
066: * @param pageName
067: * The name of the page.
068: */
069: public GatewaySelectViewBean(String pageName) {
070: super (pageName);
071: registerChildren();
072: }
073:
074: /**
075: * Default constructor.
076: */
077: public GatewaySelectViewBean() {
078: super (PAGE_NAME);
079: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
080: registerChildren();
081: }
082:
083: /**
084: * Creates the child view objects for this viewbean.
085: *
086: * @param name
087: * the name of the child view object to be created.
088: * @return the child view object.
089: */
090: protected View createChild(String name) {
091: getGWModelMgr();
092: if (name.equals(CHILD_PAGE_TITLE)) {
093: return new StaticTextField(this , CHILD_PAGE_TITLE,
094: modelManager.getString("HTMLPage.title"));
095: } else if (name.equals(CHILD_CC_MSGBOX)) {
096: return new MessageBox(this , CHILD_CC_MSGBOX, "");
097: } else if (name.equals(LBL_SERVICE_TITLE)) {
098: return new StaticTextField(this , LBL_SERVICE_TITLE,
099: modelManager.getString("service.name"));
100: } else if (name.equals(LBL_PROFILE)) {
101: return new StaticTextField(this , LBL_PROFILE, modelManager
102: .getString("profile.label"));
103: } else if (name.equals(LBL_NAME)) {
104: return new StaticTextField(this , LBL_NAME, modelManager
105: .getString("name.label"));
106: } else if (name.equals(LBL_ACTION)) {
107: return new StaticTextField(this , LBL_ACTION, modelManager
108: .getString("action.label"));
109: } else if (name.equals(CHILD_TILEDVIEW)) {
110: return new GatewaySelectTiledView(this , CHILD_TILEDVIEW);
111: } else if (name.equals(CREATE_BTN)) {
112: return new IPlanetButton(this , CREATE_BTN, "");
113: } else if (name.equals(DELETE_BTN)) {
114: return new IPlanetButton(this , DELETE_BTN, "");
115: } else {
116: return super .createChild(name);
117: }
118: }
119:
120: /**
121: * To register all the child view objects and their classes.
122: */
123: protected void registerChildren() {
124: registerChild(CHILD_PAGE_TITLE, StaticTextField.class);
125: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
126: registerChild(LBL_SERVICE_TITLE, StaticTextField.class);
127: registerChild(LBL_PROFILE, StaticTextField.class);
128: registerChild(LBL_NAME, StaticTextField.class);
129: registerChild(LBL_ACTION, StaticTextField.class);
130: registerChild(CHILD_TILEDVIEW, GatewaySelectTiledView.class);
131: registerChild(CREATE_BTN, IPlanetButton.class);
132: registerChild(DELETE_BTN, IPlanetButton.class);
133: }
134:
135: public void beginDisplay(DisplayEvent event)
136: throws ModelControlException {
137: getModel();
138: setChildValues(model);
139: /*
140: * Fix for 4729870 ( Delete button getting broken up ). @ modified
141: * bshankar@sun.com
142: */
143: getGWModelMgr();
144: setDisplayFieldValue(CREATE_BTN, modelManager
145: .getString("new.button"));
146: setDisplayFieldValue(DELETE_BTN, modelManager
147: .getString("delete.button"));
148: setDisplayFieldValue(HELP_DOC_URL, modelManager
149: .getString(GatewayAdminService.SRA_BASE_HLP_URL));
150: setDisplayFieldValue(HELP_ANCHOR_TAG, model
151: .getHelpAnchorTag(GatewayAdminService.SRA_GW_HLP_URL));
152:
153: }
154:
155: /**
156: * Returns the child tiled view object.
157: *
158: * @return the child tiled view object of this viewbean.
159: */
160: public GatewaySelectTiledView getGatewayInstanceTiledView() {
161: return (GatewaySelectTiledView) getChild(CHILD_TILEDVIEW);
162: }
163:
164: /**
165: * Returns the model object used by this viewbean.
166: *
167: * @return the model object that is tied to this viewbean.
168: */
169: public GatewayModel getModel() {
170: /*
171: * if(model == null) { model = (GatewayModel) getRequestContext()
172: * .getModelManager().getModel(GatewayModel.class); }
173: * /* Set the ModelManager into the model object before we return the
174: * model
175: */
176: /*
177: * model.setValue(GatewayAdminModelManager.SRAP_GATEWAY_MODEL_MGR_KEY,
178: * getGWModelMgr());
179: *
180: */
181: if (model == null) {
182: HttpServletRequest req = getRequestContext().getRequest();
183: model = new GatewayModelImpl(req);
184: }
185: return model;
186: }
187:
188: public GatewayAdminModelManager getGWModelMgr() {
189: if (modelManager == null) {
190: modelManager = (GatewayAdminModelManager) getRequestContext()
191: .getModelManager();
192: }
193: return modelManager;
194: }
195:
196: public boolean beginDeleteButtonBlockDisplay(ChildDisplayEvent event) {
197: GatewayModel m = getModel();
198: // GatewayModel m = (GatewayModel)
199: // getRequestContext().getModelManager().getModel(GatewayModel.class);
200: // m.setValue(GatewayModel.SRAP_GATEWAY_ADMIN_REQ_OBJ_KEY,
201: // getRequestContext().getRequest());
202: return (m != null) ? (m.getGatewayProfileCount() > 1) : false;
203:
204: // GatewaySelectTiledView tileView = getGatewayInstanceTiledView();
205: // return (tileView.getNumTiles() > 1);
206: }
207:
208: /*
209: * Handles the event when the create button is clicked. @param the JATO
210: * event object
211: */
212: public void handleNewButtonRequest(RequestInvocationEvent event) {
213: /* Forward to the create rule viewbean */
214: ViewBean vb = getViewBean(GatewayCreateViewBean.class);
215: vb.forwardTo(getRequestContext());
216: }
217:
218: /*
219: * Handles the event when the delete button is clicked. @param the JATO
220: * event object @exception throws ModelControlException when error(s)
221: * occurred.
222: */
223: public void handleDeleteButtonRequest(RequestInvocationEvent event)
224: throws ModelControlException {
225:
226: GatewayModel model = getModel();
227: GatewaySelectTiledView tileView = (GatewaySelectTiledView) getChild(CHILD_TILEDVIEW);
228: int tiles = tileView.getNumTiles();
229: List selections = new ArrayList();
230:
231: for (int i = 0; i < tiles; i++) {
232: CheckBox chkBox = (CheckBox) tileView.getChild(
233: GatewaySelectTiledView.CHILD_CB_SELECT_GATEWAY, i);
234: String value = (String) chkBox.getValue();
235: if (value.equals("true")) {
236: value = (String) tileView
237: .getDisplayFieldValue(GatewaySelectTiledView.CHILD_GATEWAY_PROFILE_NAME);
238: selections.add(value);
239: }
240: }
241:
242: /* Display a recoverable error if no ruleset is selected */
243: if (selections.size() == 0) {
244: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
245: msgBox.setTitle(modelManager
246: .getString("noselectionmsgbox.title"));
247: msgBox.setMessage(modelManager
248: .getString("noselectionmsgbox.msg"));
249: msgBox.setType(MessageBox.TYPE_WARNING);
250: msgBox.setVisible(true);
251:
252: /* Redisplay the page with the error */
253: forwardTo();
254: }
255: /* Display a recoverable error if all profiles are selected for deletion */
256: else if (selections.size() == tiles) {
257: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
258: msgBox.setTitle(modelManager
259: .getString("allselectionmsgbox.title"));
260: msgBox.setMessage(modelManager
261: .getString("allselectionmsgbox.msg"));
262: msgBox.setType(MessageBox.TYPE_ERROR);
263: msgBox.setVisible(true);
264: /* Redisplay the page with the error */
265: forwardTo();
266: } else {
267: StringBuffer sb = new StringBuffer("<ul>");
268:
269: /* Confirm the delete operation using common msgbox */
270: RequestContext rc = getRequestContext();
271: ViewBeanManager mgr = rc.getViewBeanManager();
272: AMMessageViewBean amMsgVB = (AMMessageViewBean) mgr
273: .getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
274: amMsgVB.setMessageType(MessageBox.TYPE_QUESTION);
275:
276: /* Loop through the selected ruleset name(s) */
277: for (int i = 0; i < selections.size(); i++) {
278: sb.append("<li>");
279: sb.append((String) selections.get(i));
280: sb.append("</li>");
281: }
282: sb.append("</ul>");
283:
284: /* XXX localize this */
285: amMsgVB.setTitle(modelManager
286: .getString("delete.profile.confirmation"));
287: amMsgVB.setMessage(sb.toString());
288:
289: /* XXX localize this */
290: amMsgVB.addButton(modelManager.getString("yes.button"),
291: getModuleURL() + "/"
292: + GatewayDeleteViewBean.PAGE_NAME);
293: amMsgVB.addButton(modelManager.getString("no.button"),
294: getModuleURL() + "/"
295: + GatewaySelectViewBean.PAGE_NAME);
296:
297: /* Store the selected ruleset name(s) into session */
298: modelManager.storeToSession(SELECT_GATEWAY_SESSION_INFO,
299: (String[]) selections.toArray(new String[] {}));
300: amMsgVB.forwardTo(rc);
301: }
302: }
303:
304: }
|