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.lang.*;
009: import java.text.*;
010: import java.util.*;
011:
012: import javax.servlet.*;
013: import javax.servlet.http.*;
014:
015: import com.sun.portal.search.admin.CSViewBeanBase;
016: import com.sun.portal.search.util.SearchConfig;
017:
018: import com.iplanet.jato.RequestContext;
019: import com.iplanet.jato.RequestHandler;
020:
021: import com.iplanet.jato.view.event.DisplayEvent;
022: import com.iplanet.jato.view.event.ChildDisplayEvent;
023: import com.iplanet.jato.view.event.RequestInvocationEvent;
024:
025: import com.iplanet.jato.view.html.OptionList;
026: import com.iplanet.jato.view.html.Option;
027: import com.iplanet.jato.view.html.CheckBox;
028: import com.iplanet.jato.view.html.TextField;
029: import com.iplanet.jato.view.html.ListBox;
030: import com.iplanet.jato.view.html.StaticTextField;
031:
032: import com.iplanet.jato.view.View;
033: import com.iplanet.jato.view.ViewBean;
034: import com.iplanet.jato.view.ViewBeanBase;
035:
036: import com.iplanet.jato.ViewBeanManager;
037:
038: import com.iplanet.jato.model.ModelControlException;
039:
040: import com.iplanet.am.console.components.view.html.IPlanetButton;
041:
042: import com.sun.portal.search.admin.model.PopularSearchModel;
043:
044: /**
045: * Schema Editor Wizard for editing database schema
046: * It extends from <code>CSViewBeanBase</code>.
047: */
048:
049: public class PopularSearchViewBean extends CSViewBeanBase implements
050: RequestHandler {
051:
052: // The "logical" name for this page.
053: public static final String PAGE_NAME = "PopularSearch";
054: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/PopularSearch.jsp";
055:
056: public static final String CHK_BROWSE = "ExcludeBrowse";
057: public static final String BTN_OK = "ok";
058: public static final String SINCE_TEXT = "SinceDate";
059: public static final String NUM_QUERY_TEXT = "NumOfQuery";
060: public static final String SEARCH_LIST = "SearchList";
061: public static final String STATUS_UPDATE_TIME = "UpdateTime";
062:
063: private PopularSearchModel model = null;
064:
065: /*
066: * Default constructor
067: *
068: */
069: public PopularSearchViewBean() {
070: super (PAGE_NAME);
071: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
072: registerChildren();
073: }
074:
075: /**
076: * Child methods
077: */
078: protected void registerChildren() {
079: // Add an entry for each child. Note, the children are not instantiated
080: // at this time. Instead, child instantiation is handled in a lazy fashion.
081:
082: registerChild(CHK_BROWSE, CheckBox.class);
083: registerChild(BTN_OK, IPlanetButton.class);
084: registerChild(SINCE_TEXT, StaticTextField.class);
085: registerChild(NUM_QUERY_TEXT, StaticTextField.class);
086: registerChild(BTN_OK, IPlanetButton.class);
087: registerChild(SEARCH_LIST, PopularSearchListView.class);
088: registerChild(this .STATUS_UPDATE_TIME, StaticTextField.class);
089: }
090:
091: protected View createChild(String name) {
092: // Create HeaderView Child
093: View child = super .createChild(name);
094: if (child != null) {
095: return child;
096:
097: } else if (name.equals(BTN_OK)) {
098: return new IPlanetButton(this , BTN_OK, "");
099: } else if (name.equals(CHK_BROWSE)) {
100: return new CheckBox(this , CHK_BROWSE, "true", "false",
101: false);
102: } else if (name.equals(SINCE_TEXT)) {
103: return new StaticTextField(this , SINCE_TEXT, "");
104: } else if (name.equals(NUM_QUERY_TEXT)) {
105: return new StaticTextField(this , NUM_QUERY_TEXT, "");
106: } else if (name.equals(SEARCH_LIST)) {
107: return new PopularSearchListView(this , SEARCH_LIST);
108: } else if (name.equals(this .STATUS_UPDATE_TIME)) {
109: return new StaticTextField(this , this .STATUS_UPDATE_TIME,
110: "");
111: }
112: throw new IllegalArgumentException("Invalid child name \""
113: + name + "\"");
114:
115: }
116:
117: public void beginDisplay(DisplayEvent event) {
118: setPageEncoding();
119: DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
120: DateFormat.LONG, getUserLocale());
121: PopularSearchListView child = (PopularSearchListView) getChild(SEARCH_LIST);
122: if (model == null) {
123: model = getModel();
124: child.setModel(model);
125: }
126: Date startAT = model.getFirstDate();
127: setDisplayFieldValue(SINCE_TEXT, ((startAT == null) ? "" : df
128: .format(startAT)));
129: setDisplayFieldValue(NUM_QUERY_TEXT, model.getNumberOfQuery());
130: setDisplayFieldValue(this .STATUS_UPDATE_TIME, df.format(model
131: .getLastUpdated()));
132: setDisplayFieldValue(BTN_OK, getLocalizedString("update.text"));
133: }
134:
135: /**
136: *
137: *
138: */
139: public boolean beginSearchListSectDisplay(ChildDisplayEvent event) {
140: return (model != null && model.getSize() > 0);
141: }
142:
143: /*
144: * Request event handler methods - for button and HREF fields
145: *
146: */
147: public void handleOkRequest(RequestInvocationEvent event)
148: throws ServletException {
149: model = getModel();
150:
151: boolean exclBrowse = getDisplayFieldBooleanValue(CHK_BROWSE);
152: model.execute(exclBrowse);
153: PopularSearchListView child = (PopularSearchListView) getChild(SEARCH_LIST);
154: child.setModel(model);
155: forwardTo();
156: }
157:
158: /*
159: * handles invocation of Reset Button
160: *
161: * @param event request invocation event
162: */
163: public void handleResetRequest(RequestInvocationEvent event) {
164: forwardTo();
165: }
166:
167: protected PopularSearchModel getModel() {
168: if (model == null) {
169: model = new PopularSearchModel();
170: model.userLocale = getUserLocale();
171: }
172: return model;
173: }
174: }
|