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.logging.Logger;
010:
011: import com.sun.portal.search.admin.model.SitesListModel;
012:
013: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
014: import com.iplanet.jato.view.View;
015: import com.iplanet.jato.view.ViewBean;
016: import com.iplanet.jato.view.ViewBeanBase;
017: import com.iplanet.jato.view.TiledView;
018: import com.iplanet.jato.RequestHandler;
019: import com.iplanet.jato.model.*;
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.RequestInvocationEvent;
022: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
023: import com.iplanet.jato.view.event.ChildDisplayEvent;
024: import com.iplanet.jato.view.html.OptionList;
025: import com.iplanet.jato.view.html.StaticTextField;
026: import com.iplanet.jato.view.html.RadioButtonGroup;
027: import com.iplanet.jato.view.html.HREF;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.ImageField;
030: import com.iplanet.jato.model.DatasetModel;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import com.iplanet.am.console.components.view.html.IPlanetButton;
035:
036: import com.sun.portal.search.robot.RobotConfig;
037: import com.sun.portal.log.common.PortalLogger;
038:
039: public class SitesListView extends RequestHandlingTiledViewBase
040: implements TiledView, RequestHandler {
041: public static final String ON_OFF_RBUTTON = "OnOffRButton";
042: public static final String SITE_HREF = "SiteLink";
043: public static final String TYPE_IMAGE = "TypeImage";
044: public static final String NICK_NAME_LABEL = "NickName";
045: public static final String DEL_CHECKBOX = "Delete";
046: private static OptionList options = new OptionList(new String[] {
047: "", "" }, // labels
048: SitesListModel.ENABLE_VALUES); // values
049:
050: private SitesListModel model = null;
051:
052: // Create a Logger for this class
053: private static Logger debugLogger = PortalLogger
054: .getLogger(SitesListView.class);
055:
056: public SitesListView(View parent, String name) {
057: super (parent, name);
058: setPrimaryModelClass(SitesListModel.class);
059: //setPrimaryModel((DatasetModel) getDefaultModel());
060: registerChildren();
061: }
062:
063: protected void registerChildren() {
064: registerChild(ON_OFF_RBUTTON, RadioButtonGroup.class);
065: registerChild(TYPE_IMAGE, ImageField.class);
066: registerChild(SITE_HREF, HREF.class);
067: registerChild(NICK_NAME_LABEL, StaticTextField.class);
068: registerChild(DEL_CHECKBOX, CheckBox.class);
069: }
070:
071: protected View createChild(String name) {
072: if (name.equals(ON_OFF_RBUTTON)) {
073: RadioButtonGroup child = new RadioButtonGroup(this , this
074: .getModel(), ON_OFF_RBUTTON,
075: SitesListModel.FIELD_ENABLE, "", null);
076: child.setOptions(options);
077: return child;
078: }
079: if (name.equals(TYPE_IMAGE)) {
080: return new ImageField(this , getModel(), TYPE_IMAGE,
081: SitesListModel.FIELD_TYPEIMAGE, "", null);
082: }
083: if (name.equals(SITE_HREF)) {
084: return new HREF(this , getModel(), SITE_HREF,
085: SitesListModel.FIELD_SITEID, "", null);
086: }
087: if (name.equals(NICK_NAME_LABEL)) {
088: return new StaticTextField(this , getModel(),
089: NICK_NAME_LABEL, SitesListModel.FIELD_NICKNAME, "",
090: null);
091: }
092: if (name.equals(DEL_CHECKBOX)) {
093: return new CheckBox(this , getModel(), DEL_CHECKBOX,
094: SitesListModel.FIELD_DELETE, "true", "false",
095: false, null);
096: }
097: throw new IllegalArgumentException("Invalid child name ["
098: + name + "]");
099: }
100:
101: /**
102: * The parent view bean must implement getModel method for this
103: * method to recieve a useful model reference.
104: *
105: * @return Reference to interface of type AMIndentedListModel
106: */
107: /**
108: *
109: *
110: */
111: protected SitesListModel getModel() {
112: return (SitesListModel) getRequestContext().getModelManager()
113: .getModel(SitesListModel.class);
114: }
115:
116: public void beginDisplay(DisplayEvent event)
117: throws ModelControlException {
118: // Ensure the primary model is non-null; if null, it would cause
119: // havoc with the various methods dependent on the primary model
120: SitesListModel model = (SitesListModel) getPrimaryModel();
121: if (model == null) {
122: debugLogger.finer("PSSH_CSPSA0023");
123: throw new ModelControlException("Primary model is null");
124: }
125:
126: // The model will be executed automatically here by the base class
127: super .beginDisplay(event);
128:
129: resetTileIndex();
130: }
131:
132: /**
133: *
134: *
135: */
136: public Model[] getWebActionModels(int modelType) {
137: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
138: // This means it will automatically be executed via its retrieve()
139: // method when the tiled view begins display.
140:
141: switch (modelType) {
142: case MODEL_TYPE_RETRIEVE:
143: case MODEL_TYPE_UPDATE:
144: case MODEL_TYPE_DELETE:
145: return new Model[] { getModel() };
146: }
147:
148: return new Model[0];
149: }
150:
151: /**
152: * Subclasses may override to handle appropriately. This implementation
153: * forwards to itself.
154: */
155: /* public void handleDelButtonRequest(RequestInvocationEvent event)
156: throws ModelControlException {
157: TiledViewRequestInvocationEvent tiledEvent =
158: (TiledViewRequestInvocationEvent)event;
159: int selRow = tiledEvent.getTileNumber();
160: getPrimaryModel().setLocation(selRow);
161:
162: String id = getDisplayFieldStringValue(DEL_BUTTON);
163: getModel().delRuleset(id);
164: ViewBean viewBean = getParentViewBean();
165: viewBean.forwardTo(getRequestContext());
166: }
167: */
168:
169: public void handleSiteLinkRequest(RequestInvocationEvent event)
170: throws ModelControlException {
171:
172: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
173: int selRow = tiledEvent.getTileNumber();
174: getPrimaryModel().setLocation(selRow);
175:
176: String target = (String) getDisplayFieldValue(SITE_HREF);
177: ViewBean pvb = getParentViewBean();
178: HttpServletResponse response = (pvb.getRequestContext())
179: .getResponse();
180:
181: try {
182: response.sendRedirect("Site?id=" + target);
183: } catch (IOException e) {
184: //TOFIX: handle this
185: }
186: }
187:
188: }
|