001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.net.URL;
009: import java.io.IOException;
010: import java.util.logging.Level;
011: import java.util.logging.Logger;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase;
014:
015: import javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletResponse;
017:
018: import com.iplanet.jato.RequestContext;
019:
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.ChildDisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023:
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.TextField;
026: import com.iplanet.jato.view.html.CheckBox;
027: import com.iplanet.jato.view.html.Button;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.RadioButtonGroup;
030: import com.iplanet.jato.view.html.HiddenField;
031:
032: import com.iplanet.jato.view.html.Option;
033: import com.iplanet.jato.view.html.OptionList;
034:
035: import com.iplanet.jato.view.View;
036: import com.iplanet.jato.view.ViewBean;
037: import com.iplanet.jato.view.ViewBeanBase;
038:
039: import com.iplanet.jato.ViewBeanManager;
040:
041: import com.iplanet.jato.model.*;
042:
043: import com.iplanet.am.console.components.view.html.MessageBox;
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: import com.sun.portal.search.admin.resources.SearchResource;
047: import com.sun.portal.search.admin.model.RobotClassRuleListModel;
048: import com.sun.portal.log.common.PortalLogger;
049:
050: /**
051: * iPS admin console view bean: TODO
052: */
053: public class RobotClassRuleListViewBean extends CSViewBeanBase {
054: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RobotClassRuleList.jsp";
055: public static final String PAGE_NAME = "RobotClassRuleList";
056: public static final String RobotClassRuleList_VIEW = "RobotClassRuleListView";
057: public static final String NEW_BUTTON = "NewButton";
058: public static final String DELETE_BUTTON = "DeleteButton";
059: public static final String SUBMIT_BUTTON = "SubmitButton";
060: public static final String RESET_BUTTON = "ResetButton";
061:
062: //Message Box
063: public static final String CHILD_ERROR_MSG_BOX = "errorMsgBox";
064: public static final String CHILD_WARNING_MSG_BOX = "warningMsgBox";
065:
066: // Create a Logger for this class
067: private static Logger debugLogger = PortalLogger
068: .getLogger(RobotClassRuleListViewBean.class);
069:
070: /**
071: * constructor
072: *
073: * @param PageName of this view bean
074: * @param displayURL default display URL
075: */
076: public RobotClassRuleListViewBean() {
077: super (PAGE_NAME);
078: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
079: registerChildren();
080: }
081:
082: /**
083: * register child component
084: */
085: protected void registerChildren() {
086: registerChild(RobotClassRuleList_VIEW,
087: RobotClassRuleListView.class);
088: registerChild(NEW_BUTTON, IPlanetButton.class);
089: registerChild(DELETE_BUTTON, IPlanetButton.class);
090: registerChild(SUBMIT_BUTTON, IPlanetButton.class);
091: registerChild(RESET_BUTTON, IPlanetButton.class);
092:
093: registerChild(CHILD_ERROR_MSG_BOX, MessageBox.class);
094: registerChild(CHILD_WARNING_MSG_BOX, MessageBox.class);
095:
096: }
097:
098: /**
099: * create child component
100: *
101: * @param name of component
102: * @return child component
103: */
104: protected View createChild(String name) {
105:
106: View Headerchild = super .createChild(name);
107: if (Headerchild != null)
108: return Headerchild;
109: if (name.equals(RobotClassRuleList_VIEW)) {
110: return new RobotClassRuleListView(this ,
111: RobotClassRuleList_VIEW);
112: }
113: if (name.equals(NEW_BUTTON)) {
114: return new IPlanetButton(this , NEW_BUTTON, "");
115: }
116: if (name.equals(DELETE_BUTTON)) {
117: return new IPlanetButton(this , DELETE_BUTTON, "");
118: }
119: if (name.equals(SUBMIT_BUTTON)) {
120: return new IPlanetButton(this , SUBMIT_BUTTON, "");
121: }
122: if (name.equals(RESET_BUTTON)) {
123: return new IPlanetButton(this , RESET_BUTTON, "");
124: }
125: if (name.equals(CHILD_ERROR_MSG_BOX)) {
126: return new MessageBox(this , CHILD_ERROR_MSG_BOX, "");
127: }
128: if (name.equals(CHILD_WARNING_MSG_BOX)) {
129: return new MessageBox(this , CHILD_WARNING_MSG_BOX, "");
130: }
131: throw new IllegalArgumentException("Invalid child name ["
132: + name + "]");
133: }
134:
135: /** begin displaying page. we set the required information
136: *
137: * @param event display event
138: * @throws ModelControlException if problem access value of component
139: */
140: public void beginDisplay(DisplayEvent event) {
141: // Get request attributes and store them as Page Session Attributes
142: setPageEncoding();
143: setDisplayFieldValue(SUBMIT_BUTTON,
144: getLocalizedString("submit.text"));
145: setDisplayFieldValue(RESET_BUTTON,
146: getLocalizedString("reset.text"));
147: setDisplayFieldValue(NEW_BUTTON, getLocalizedString("new.text"));
148: setDisplayFieldValue(DELETE_BUTTON,
149: getLocalizedString("delete.text"));
150: RobotClassRuleListModel model = (RobotClassRuleListModel) getRequestContext()
151: .getModelManager().getModel(
152: RobotClassRuleListModel.class);
153: if (model.getNumOfRules() == 0) {
154: IPlanetButton child = (IPlanetButton) getChild(DELETE_BUTTON);
155: child.setEnable(false);
156: }
157:
158: // checking for error message
159: String msg = getMsg("ErrorMsg");
160: MessageBox msgBox = (MessageBox) getChild(CHILD_ERROR_MSG_BOX);
161: if (msg != null) {
162: msgBox.setType(MessageBox.TYPE_ERROR);
163: msgBox.setMessage(msg);
164: msgBox.setEnabled(true);
165: } else {
166: msgBox.setEnabled(false);
167: }
168: // checking for error message
169: msg = getMsg("WarningMsg");
170: msgBox = (MessageBox) getChild(CHILD_WARNING_MSG_BOX);
171: if (msg != null) {
172: msgBox.setType(MessageBox.TYPE_WARNING);
173: msgBox.setMessage(msg);
174: msgBox.setEnabled(true);
175: } else {
176: msgBox.setEnabled(false);
177: }
178:
179: }
180:
181: public boolean beginListTableDisplay(ChildDisplayEvent event) {
182:
183: RobotClassRuleListModel model = (RobotClassRuleListModel) ((RobotClassRuleListView) getChild(RobotClassRuleList_VIEW))
184: .getModel();
185: return (model.getNumOfRules() > 0);
186: }
187:
188: public boolean beginEmptyListDisplay(ChildDisplayEvent event) {
189: RobotClassRuleListModel model = (RobotClassRuleListModel) ((RobotClassRuleListView) getChild(RobotClassRuleList_VIEW))
190: .getModel();
191: return (model.getNumOfRules() == 0);
192: }
193:
194: public void handleResetButtonRequest(RequestInvocationEvent event)
195: throws ModelControlException {
196: //RobotClassRuleListView child = (RobotClassRuleListView) getChild(RobotClassRuleList_VIEW);
197: //child.reset();
198: clearPageSessionAttributes();
199: forwardTo();
200: }
201:
202: public void handleDeleteButtonRequest(RequestInvocationEvent event) {
203: RobotClassRuleListView child = (RobotClassRuleListView) getChild(RobotClassRuleList_VIEW);
204: try {
205: ModelExecutionContext modExe = new ModelExecutionContextBase(
206: ModelExecutionContext.OPERATION_DELETE);
207: child.executeAutoDeletingModels(modExe);
208: } catch (ModelControlException e) {
209: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
210: .getMessage());
211: }
212: //setPageSessionAttribute("WarningMsg", getLocalizedString("schema.save-modifications"));
213: forwardTo();
214: }
215:
216: public void handleNewButtonRequest(RequestInvocationEvent event)
217: throws ModelControlException {
218: RobotClassRuleListView child = (RobotClassRuleListView) getChild(RobotClassRuleList_VIEW);
219: try {
220: ModelExecutionContext modExe = new ModelExecutionContextBase(
221: ModelExecutionContext.OPERATION_INSERT);
222: child.executeAutoInsertingModels(modExe);
223: } catch (ModelControlException e) {
224: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
225: .getMessage());
226: }
227: setPageSessionAttribute("WarningMsg",
228: getLocalizedString("schema.save-modifications"));
229: forwardTo();
230: }
231:
232: public void handleSubmitButtonRequest(RequestInvocationEvent event)
233: throws ModelControlException {
234: RobotClassRuleListView child = (RobotClassRuleListView) getChild(RobotClassRuleList_VIEW);
235: try {
236: ModelExecutionContext modExe = new ModelExecutionContextBase(
237: ModelExecutionContext.OPERATION_UPDATE);
238: child.executeAutoUpdatingModels(modExe);
239: } catch (ModelControlException e) {
240: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
241: .getMessage());
242: }
243: forwardTo();
244:
245: }
246:
247: private String getMsg(String msgType) {
248: String msg = (String) getPageSessionAttribute(msgType);
249: removePageSessionAttribute(msgType);
250: return msg;
251: }
252: }
|