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.util.Set;
009: import java.util.List;
010: import java.util.Iterator;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013:
014: import javax.servlet.http.HttpServletRequest;
015:
016: import com.iplanet.jato.RequestContext;
017:
018: import com.iplanet.jato.view.event.DisplayEvent;
019: import com.iplanet.jato.view.event.RequestInvocationEvent;
020:
021: import com.iplanet.jato.view.html.StaticTextField;
022: import com.iplanet.jato.view.html.TextField;
023: import com.iplanet.jato.view.html.CheckBox;
024: import com.iplanet.jato.view.html.Button;
025: import com.iplanet.jato.view.html.ComboBox;
026: import com.iplanet.jato.view.html.Option;
027: import com.iplanet.jato.view.html.OptionList;
028:
029: import com.iplanet.jato.view.View;
030: import com.iplanet.jato.view.ContainerView;
031: import com.iplanet.jato.RequestHandler;
032: import com.iplanet.jato.view.RequestHandlingViewBase;
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.*;
039:
040: import com.iplanet.am.console.components.view.html.IPlanetButton;
041:
042: import com.sun.portal.search.admin.model.ScheduleModel;
043: import com.sun.portal.log.common.PortalLogger;
044:
045: /**
046: * iPS admin console view bean: TODO
047: */
048: public class ScheduleView extends RequestHandlingViewBase implements
049: ContainerView, RequestHandler {
050: public static final String PAGE_NAME = "Schedule";
051: public static final String NAME = "Name";
052: public static final String DESC = "Description";
053: public static final String COMMAND = ScheduleModel.FIELD_COMMAND;
054: public static final String DIR = ScheduleModel.FIELD_DIR;
055: public static final String HOUR_LIST = "HourList";
056: public static final String MIN_LIST = "MinList";
057: public static final String SUN_CHECKBOX = "SUN";
058: public static final String MON_CHECKBOX = "MON";
059: public static final String TUE_CHECKBOX = "TUE";
060: public static final String WED_CHECKBOX = "WED";
061: public static final String THU_CHECKBOX = "THU";
062: public static final String FRI_CHECKBOX = "FRI";
063: public static final String SAT_CHECKBOX = "SAT";
064: private static OptionList hourOptions = new OptionList(
065: ScheduleModel.hourLabel, ScheduleModel.hourValues);
066: private static OptionList minOptions = new OptionList(
067: ScheduleModel.minValues, ScheduleModel.minValues);
068:
069: private ScheduleModel model = null;
070:
071: // Create a Logger for this class
072: private static Logger debugLogger = PortalLogger
073: .getLogger(ScheduleView.class);
074:
075: /**
076: * constructor
077: *
078: * @param PageName of this view bean
079: * @param displayURL default display URL
080: */
081: public ScheduleView(View parent, String name) {
082: super (parent, name);
083: registerChildren();
084: }
085:
086: /**
087: * register child component
088: */
089: protected void registerChildren() {
090: registerChild(COMMAND, TextField.class);
091: registerChild(DIR, TextField.class);
092: registerChild(NAME, StaticTextField.class);
093: registerChild(DESC, StaticTextField.class);
094: registerChild(HOUR_LIST, ComboBox.class);
095: registerChild(MIN_LIST, ComboBox.class);
096: registerChild(SUN_CHECKBOX, CheckBox.class);
097: registerChild(MON_CHECKBOX, CheckBox.class);
098: registerChild(TUE_CHECKBOX, CheckBox.class);
099: registerChild(WED_CHECKBOX, CheckBox.class);
100: registerChild(THU_CHECKBOX, CheckBox.class);
101: registerChild(FRI_CHECKBOX, CheckBox.class);
102: registerChild(SAT_CHECKBOX, CheckBox.class);
103: }
104:
105: /**
106: * create child component
107: *
108: * @param name of component
109: * @return child component
110: */
111: protected View createChild(String name) {
112: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
113: if (name.equals(this .NAME)) {
114: return new StaticTextField(this , NAME, pvb
115: .getLocalizedString("cron."
116: + getName().toLowerCase()));
117: }
118: if (name.equals(this .DESC)) {
119: return new StaticTextField(this , DESC, pvb
120: .getLocalizedString("cron."
121: + getName().toLowerCase() + ".desc"));
122: }
123: if (name.equals(COMMAND)) {
124: return new TextField(this , getModel(), COMMAND, COMMAND,
125: "", null);
126: }
127: if (name.equals(DIR)) {
128: return new TextField(this , getModel(), DIR, DIR, "", null);
129: }
130: if (name.equals(this .HOUR_LIST)) {
131: ComboBox child = new ComboBox(this , this .getModel(),
132: this .HOUR_LIST, ScheduleModel.FIELD_HOUR, "", null);
133: child.setOptions(this .hourOptions);
134: return child;
135:
136: }
137: if (name.equals(MIN_LIST)) {
138: ComboBox child = new ComboBox(this , getModel(), MIN_LIST,
139: ScheduleModel.FIELD_MIN, "", null);
140: child.setOptions(this .minOptions);
141: return child;
142: }
143: if (name.equals(SUN_CHECKBOX)) {
144: return new CheckBox(this , getModel(), SUN_CHECKBOX,
145: ScheduleModel.FIELD_SUN, "true", "false", false,
146: null);
147: }
148: if (name.equals(MON_CHECKBOX)) {
149: return new CheckBox(this , getModel(), MON_CHECKBOX,
150: ScheduleModel.FIELD_MON, "true", "false", false,
151: null);
152: }
153: if (name.equals(TUE_CHECKBOX)) {
154: return new CheckBox(this , getModel(), TUE_CHECKBOX,
155: ScheduleModel.FIELD_TUE, "true", "false", false,
156: null);
157: }
158: if (name.equals(WED_CHECKBOX)) {
159: return new CheckBox(this , getModel(), WED_CHECKBOX,
160: ScheduleModel.FIELD_WED, "true", "false", false,
161: null);
162: }
163: if (name.equals(THU_CHECKBOX)) {
164: return new CheckBox(this , getModel(), THU_CHECKBOX,
165: ScheduleModel.FIELD_THU, "true", "false", false,
166: null);
167: }
168: if (name.equals(FRI_CHECKBOX)) {
169: return new CheckBox(this , getModel(), FRI_CHECKBOX,
170: ScheduleModel.FIELD_FRI, "true", "false", false,
171: null);
172: }
173: if (name.equals(SAT_CHECKBOX)) {
174: return new CheckBox(this , getModel(), SAT_CHECKBOX,
175: ScheduleModel.FIELD_SAT, "true", "false", false,
176: null);
177: }
178: throw new IllegalArgumentException("Invalid child name ["
179: + name + "]");
180: }
181:
182: /**
183: * Creates the model instance.
184: *
185: * @returns Instance of model
186: */
187: public ScheduleModel getModel() {
188: if (model == null) {
189: //model = new ScheduleModel(this.getName());
190: model = new ScheduleModel();
191: if (model == null) {
192: /* TOFIX: Handle this case by displaying an error page.
193: * This should actually be done by making the SMDataModelImpl
194: * throw an exception and catching it.
195: */
196: } else {
197: model.setName(getName());
198:
199: try {
200: model.retrieve(null);
201: } catch (ModelControlException e) {
202: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
203: .getMessage());
204: }
205: }
206: }
207: return model;
208: }
209:
210: public void store() {
211: ScheduleModel model = getModel();
212: try {
213: model.update(null);
214: } catch (Exception e) {
215: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
216: .getMessage());
217: }
218: }
219:
220: public void reset() {
221: ScheduleModel model = getModel();
222: try {
223: model.retrieve(null);
224: } catch (Exception e) {
225: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
226: .getMessage());
227: }
228: }
229: }
|