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.StartPointsListModel;
012: import com.sun.portal.log.common.PortalLogger;
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.HREF;
027: import com.iplanet.jato.model.DatasetModel;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: /**
032: * This view uses model of type AMIndentedListModel to display a tree like
033: * heirarchichal data structure in expanded tree form. So when a tree is
034: * expanded its nodes are displayed as indented rows. The indentation is
035: * relative to the parent node.
036: * Each row has this structure: [checkbox]name[link]
037: * The checkbox and link can be turned on or off. Thus,those nodes which are only
038: * for labeling purpose, can have only the name displayed in the row. This view
039: * uses TiledView of JATO, and hence each row is a tile.
040: * Typicaly, the subclasses will use the link to display the properties
041: * associated with the name, and checkbox may be used for add/delete operations.
042: */
043: public class StartPointsListView extends RequestHandlingTiledViewBase
044: implements TiledView, RequestHandler {
045: public static final String ENABLE_TEXT = "Enable";
046: public static final String STARTPOINT_HREF = "StartPoint";
047: public static final String URL_TEXT = "UrlText";
048: public static final String SITEID_HREF = "SiteID";
049: public static final String SITENAME_TEXT = "SiteName";
050: public static final String DEPTH_TEXT = "Depth";
051:
052: // Create a Logger for this class
053: private static Logger debugLogger = PortalLogger
054: .getLogger(StartPointsListView.class);
055:
056: public StartPointsListView(View parent, String name) {
057: super (parent, name);
058: this .setPrimaryModelClass(StartPointsListModel.class);
059: //setPrimaryModel((DatasetModel) getDefaultModel());
060: registerChildren();
061: }
062:
063: protected void registerChildren() {
064: registerChild(ENABLE_TEXT, StaticTextField.class);
065: registerChild(STARTPOINT_HREF, HREF.class);
066: registerChild(URL_TEXT, StaticTextField.class);
067: registerChild(SITEID_HREF, HREF.class);
068: registerChild(SITENAME_TEXT, StaticTextField.class);
069: registerChild(DEPTH_TEXT, StaticTextField.class);
070: }
071:
072: protected View createChild(String name) {
073: View child = null;
074: if (name.equals(ENABLE_TEXT)) {
075: return new StaticTextField(this , getStartPointsListModel(),
076: ENABLE_TEXT, StartPointsListModel.FIELD_ENABLE, "",
077: null);
078: }
079: if (name.equals(this .STARTPOINT_HREF)) {
080: return new HREF(this , getStartPointsListModel(),
081: this .STARTPOINT_HREF,
082: StartPointsListModel.FIELD_STARTPOINT, "", null);
083: }
084: if (name.equals(this .URL_TEXT)) {
085: return new StaticTextField(this , getStartPointsListModel(),
086: URL_TEXT, StartPointsListModel.FIELD_STARTPOINT,
087: "", null);
088: }
089: if (name.equals(this .SITEID_HREF)) {
090: return new HREF(this , getStartPointsListModel(),
091: this .SITEID_HREF,
092: StartPointsListModel.FIELD_SITEID, "", null);
093: }
094: if (name.equals(this .SITENAME_TEXT)) {
095: return new StaticTextField(this , getStartPointsListModel(),
096: this .SITENAME_TEXT,
097: StartPointsListModel.FIELD_SITENAME, "", null);
098: }
099: if (name.equals(this .DEPTH_TEXT)) {
100: return new StaticTextField(this , getStartPointsListModel(),
101: this .DEPTH_TEXT, StartPointsListModel.FIELD_DEPTH,
102: "", null);
103: }
104:
105: throw new IllegalArgumentException("Invalid child name: "
106: + name);
107: }
108:
109: /**
110: *
111: *
112: */
113: public void beginDisplay(DisplayEvent event)
114: throws ModelControlException {
115: // Ensure the primary model is non-null; if null, it would cause
116: // havoc with the various methods dependent on the primary model
117: StartPointsListModel model = (StartPointsListModel) getPrimaryModel();
118: if (model == null) {
119: debugLogger.finer("PSSH_CSPSA0023");
120: throw new ModelControlException("Primary model is null");
121: }
122:
123: // The model will be executed automatically here by the base class
124: super .beginDisplay(event);
125:
126: resetTileIndex();
127: }
128:
129: /**
130: *
131: *
132: */
133: public Model[] getWebActionModels(int modelType) {
134: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
135: // This means it will automatically be executed via its retrieve()
136: // method when the tiled view begins display.
137:
138: switch (modelType) {
139: case MODEL_TYPE_RETRIEVE:
140: debugLogger.finer("PSSH_CSPSA0036");
141: return new Model[] { getStartPointsListModel() };
142: }
143:
144: return new Model[0];
145: }
146:
147: /**
148: *
149: *
150: */
151: public StartPointsListModel getStartPointsListModel() {
152: StartPointsListModel model = (StartPointsListModel) getRequestContext()
153: .getModelManager().getModel(StartPointsListModel.class);
154: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
155: model.userLocale = pvb.getUserLocale();
156: return model;
157: }
158:
159: /**
160: * Subclasses may override to handle appropriately. This implementation
161: * forwards to itself.
162: */
163: public void handleStartPointRequest(RequestInvocationEvent event)
164: throws ModelControlException {
165:
166: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
167: int selRow = tiledEvent.getTileNumber();
168: getPrimaryModel().setLocation(selRow);
169:
170: String target = (String) getDisplayFieldValue(this .STARTPOINT_HREF);
171: ViewBean pvb = getParentViewBean();
172: HttpServletResponse response = (pvb.getRequestContext())
173: .getResponse();
174:
175: try {
176: response.sendRedirect(target);
177: } catch (IOException e) {
178: //TOFIX: handle this
179: }
180: }
181:
182: public void handleSiteIDRequest(RequestInvocationEvent event)
183: throws ModelControlException {
184:
185: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
186: int selRow = tiledEvent.getTileNumber();
187: getPrimaryModel().setLocation(selRow);
188:
189: String target = (String) getDisplayFieldValue(this .SITEID_HREF);
190: ViewBean pvb = getParentViewBean();
191: HttpServletResponse response = (pvb.getRequestContext())
192: .getResponse();
193:
194: try {
195: response.sendRedirect("Site?id=" + target);
196: } catch (IOException e) {
197: //TOFIX: handle this
198: }
199: }
200:
201: }
|