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.io.IOException;
009: import java.util.StringTokenizer;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012: import java.net.URL;
013:
014: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
015: import com.iplanet.jato.view.View;
016: import com.iplanet.jato.view.ViewBean;
017: import com.iplanet.jato.view.ViewBeanBase;
018: import com.iplanet.jato.view.TiledView;
019: import com.iplanet.jato.RequestHandler;
020: import com.iplanet.jato.model.*;
021: import com.iplanet.jato.view.event.DisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
024: import com.iplanet.jato.view.event.ChildDisplayEvent;
025: import com.iplanet.jato.view.html.StaticTextField;
026: import com.iplanet.jato.view.html.ComboBox;
027: import com.iplanet.jato.view.html.TextField;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.OptionList;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032:
033: import com.iplanet.am.console.components.view.html.IPlanetButton;
034:
035: import com.sun.portal.search.admin.model.StartingGroupListModel;
036: import com.sun.portal.log.common.PortalLogger;
037:
038: /**
039: * This view uses model of type StartingGroupListModel to display a starting
040: * points tiled view in Site Definition Page
041: */
042: public class StartingGroupListView extends RequestHandlingTiledViewBase
043: implements TiledView, RequestHandler {
044: public static final String URL_TEXT = "url";
045: public static final String DEPTH_COMBO = "depth";
046: public static final String DEL_CHECKBOX = "Delete";
047: public static final String DEL_STARTING_BUTTON = "DelStarting";
048: public String rulesetID = null;
049:
050: // Create a Logger for this class
051: private static Logger debugLogger = PortalLogger
052: .getLogger(StartingGroupListView.class);
053:
054: // private MenuListModel model = null;
055:
056: public StartingGroupListView(View parent, String name) {
057: super (parent, name);
058: setPrimaryModelClass(StartingGroupListModel.class);
059: // setPrimaryModel((DatasetModel) getDefaultModel());
060: registerChildren();
061: }
062:
063: protected void registerChildren() {
064: registerChild(URL_TEXT, TextField.class);
065: registerChild(DEPTH_COMBO, ComboBox.class);
066: registerChild(DEL_CHECKBOX, CheckBox.class);
067: registerChild(DEL_STARTING_BUTTON, IPlanetButton.class);
068: }
069:
070: protected View createChild(String name) {
071: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
072: if (name.equals(URL_TEXT)) {
073: return new TextField(this , getModel(), URL_TEXT,
074: StartingGroupListModel.FIELD_URL, "", null);
075: }
076: if (name.equals(DEPTH_COMBO)) {
077: ComboBox child = new ComboBox(this , getModel(),
078: DEPTH_COMBO, StartingGroupListModel.FIELD_DEPTH,
079: "", null);
080: OptionList depthOptions = new OptionList(pvb
081: .getLocalizedStringArray(
082: "sites.depth.options.label", ","), // labels
083: pvb.getLocalizedStringArray(
084: "sites.depth.options.value", ",")); // values
085: child.setOptions(depthOptions);
086: return child;
087: }
088: if (name.equals(DEL_CHECKBOX)) {
089: return new CheckBox(this , getModel(), DEL_CHECKBOX,
090: StartingGroupListModel.FIELD_DELETE, "true",
091: "false", false, null);
092: }
093: if (name.equals(DEL_STARTING_BUTTON)) {
094: return new IPlanetButton(this , DEL_STARTING_BUTTON, pvb
095: .getLocalizedString("delete.text"));
096: }
097: throw new IllegalArgumentException("Invalid child name: "
098: + name);
099: }
100:
101: /**
102: *
103: *
104: */
105: public void beginDisplay(DisplayEvent event)
106: throws ModelControlException {
107: // Ensure the primary model is non-null; if null, it would cause
108: // havoc with the various methods dependent on the primary model
109: StartingGroupListModel model = (StartingGroupListModel) getPrimaryModel();
110: if (model == null) {
111: debugLogger.finer("PSSH_CSPSA0023");
112: throw new ModelControlException("Primary model is null");
113: }
114:
115: // The model will be executed automatically here by the base class
116: super .beginDisplay(event);
117:
118: resetTileIndex();
119: }
120:
121: public boolean beginDelStartingDisplay(ChildDisplayEvent event)
122: throws ModelControlException {
123: return (getModel().getSize() > 1);
124: }
125:
126: /**
127: *
128: *
129: */
130: public StartingGroupListModel getModel() {
131: return (StartingGroupListModel) getRequestContext()
132: .getModelManager().getModel(
133: StartingGroupListModel.class);
134: }
135:
136: /**
137: *
138: *
139: */
140: public Model[] getWebActionModels(int modelType) {
141: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
142: // This means it will automatically be executed via its retrieve()
143: // method when the tiled view begins display.
144: StartingGroupListModel model = getModel();
145:
146: switch (modelType) {
147: case MODEL_TYPE_RETRIEVE:
148: debugLogger.finer("PSSH_CSPSA0036");
149: if (this .getParentViewBean().getPageSessionAttribute(
150: "retrieved") == null) {
151: debugLogger.finer("PSSH_CSPSA0116");
152: model.setID(this .rulesetID);
153: }
154: return new Model[] { model };
155: case MODEL_TYPE_UPDATE:
156: debugLogger.finer("PSSH_CSPSA0037");
157: model.setID(this .rulesetID);
158: return new Model[] { model };
159: case MODEL_TYPE_INSERT:
160: debugLogger.finer("PSSH_CSPSA0038");
161: return new Model[] { model };
162: case MODEL_TYPE_DELETE:
163: debugLogger.finer("PSSH_CSPSA0039");
164: return new Model[] { model };
165: }
166:
167: return new Model[0];
168: }
169:
170: public void handleDelStartingRequest(RequestInvocationEvent event)
171: throws ModelControlException {
172: getParentViewBean()
173: .setPageSessionAttribute("retrieved", "true");
174: StartingGroupListModel model = getModel();
175: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
176: int selRow = tiledEvent.getTileNumber();
177: model.setDelIndex(selRow);
178: try {
179: ModelExecutionContext modExe = new ModelExecutionContextBase(
180: ModelExecutionContext.OPERATION_DELETE);
181: executeAutoDeletingModels(modExe);
182: } catch (ModelControlException e) {
183: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
184: .getMessage());
185: }
186: ViewBean viewBean = getParentViewBean();
187: viewBean.forwardTo(getRequestContext());
188: }
189:
190: }
|