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.FiltersListModel;
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.CheckBox;
026: import com.iplanet.jato.view.html.StaticTextField;
027: import com.iplanet.jato.view.html.RadioButtonGroup;
028: import com.iplanet.jato.view.html.HREF;
029: import com.iplanet.jato.model.DatasetModel;
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.robot.RobotConfig;
036: import com.sun.portal.search.robot.FilterRule;
037: import com.sun.portal.log.common.PortalLogger;
038:
039: /**
040: * This view uses model of type AMIndentedListModel to display a tree like
041: * heirarchichal data structure in expanded tree form. So when a tree is
042: * expanded its nodes are displayed as indented rows. The indentation is
043: * relative to the parent node.
044: * Each row has this structure: [checkbox]name[link]
045: * The checkbox and link can be turned on or off. Thus,those nodes which are only
046: * for labeling purpose, can have only the name displayed in the row. This view
047: * uses TiledView of JATO, and hence each row is a tile.
048: * Typicaly, the subclasses will use the link to display the properties
049: * associated with the name, and checkbox may be used for add/delete operations.
050: */
051: public class FiltersListView extends RequestHandlingTiledViewBase
052: implements TiledView, RequestHandler {
053: public static final String ON_OFF_RBUTTON = "OnOffRButton";
054: public static final String FILTER_HREF = "FilterLink";
055: public static final String NICK_NAME_LABEL = "NickName";
056: public static final String NEW_SITE_DEFAULT_LABEL = "NewSiteDefaultLabel";
057: public static final String SITES_INUSED = "SitesInUsed";
058: public static final String DEL_CHECKBOX = "Delete";
059: public static final String DEL_BUTTON = "DelButton";
060: private static OptionList options = new OptionList(new String[] {
061: "", "" }, // labels
062: FiltersListModel.ENABLE_VALUES); // values
063:
064: // Create a logger for this class
065: private static Logger debugLogger = PortalLogger
066: .getLogger(FiltersListView.class);
067:
068: private FiltersListModel model = null;
069:
070: public FiltersListView(View parent, String name) {
071: super (parent, name);
072: setPrimaryModelClass(FiltersListModel.class);
073: registerChildren();
074: }
075:
076: protected void registerChildren() {
077: registerChild(ON_OFF_RBUTTON, RadioButtonGroup.class);
078: registerChild(FILTER_HREF, HREF.class);
079: registerChild(NICK_NAME_LABEL, StaticTextField.class);
080: registerChild(NEW_SITE_DEFAULT_LABEL, StaticTextField.class);
081: registerChild(SITES_INUSED, StaticTextField.class);
082: registerChild(DEL_CHECKBOX, CheckBox.class);
083: //registerChild(DEL_BUTTON, Button.class);
084: }
085:
086: protected View createChild(String name) {
087: if (name.equals(ON_OFF_RBUTTON)) {
088: RadioButtonGroup child = new RadioButtonGroup(this ,
089: getModel(), ON_OFF_RBUTTON,
090: FiltersListModel.FIELD_ENABLE, "", null);
091: child.setOptions(options);
092: return child;
093: }
094: if (name.equals(FILTER_HREF)) {
095: return new HREF(this , getModel(), FILTER_HREF,
096: FiltersListModel.FIELD_ID, "", null);
097: }
098: if (name.equals(NICK_NAME_LABEL)) {
099: return new StaticTextField(this , getModel(),
100: NICK_NAME_LABEL, FiltersListModel.FIELD_NICKNAME,
101: "", null);
102: }
103: if (name.equals(SITES_INUSED)) {
104: return new StaticTextField(this , getModel(), SITES_INUSED,
105: FiltersListModel.FIELD_USEDINSITES, "", null);
106: }
107: if (name.equals(NEW_SITE_DEFAULT_LABEL)) {
108: return new StaticTextField(this , getModel(),
109: NEW_SITE_DEFAULT_LABEL,
110: FiltersListModel.FIELD_DEFAULT, "", null);
111: }
112: if (name.equals(DEL_CHECKBOX)) {
113: return new CheckBox(this , getModel(), DEL_CHECKBOX,
114: FiltersListModel.FIELD_DELETE, "true", "false",
115: false, null);
116: }
117: /* if (name.equals(DEL_BUTTON)){
118: return new Button(this, DEL_BUTTON,"");
119: }*/
120: throw new IllegalArgumentException("Invalid child name ["
121: + name + "]");
122: }
123:
124: /**
125: * The parent view bean must implement getModel method for this
126: * method to recieve a useful model reference.
127: *
128: * @return Reference to interface of type AMIndentedListModel
129: */
130: protected FiltersListModel getModel() {
131: if (model == null) {
132: model = (FiltersListModel) getRequestContext()
133: .getModelManager().getModel(FiltersListModel.class);
134: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
135: model.userLocale = pvb.getUserLocale();
136: }
137: return model;
138: }
139:
140: public boolean beginDeploymentDisplay(ChildDisplayEvent event) {
141: String inUsed = getDisplayFieldStringValue(SITES_INUSED);
142: if (inUsed != null && inUsed.length() > 0) {
143: return true;
144: }
145: return false;
146: }
147:
148: public void beginDisplay(DisplayEvent event)
149: throws ModelControlException {
150: // Ensure the primary model is non-null; if null, it would cause
151: // havoc with the various methods dependent on the primary model
152: FiltersListModel model = (FiltersListModel) getPrimaryModel();
153: if (model == null) {
154: debugLogger.finer("PSSH_CSPSA0023");
155: throw new ModelControlException("Primary model is null");
156: }
157:
158: // The model will be executed automatically here by the base class
159: super .beginDisplay(event);
160:
161: resetTileIndex();
162: }
163:
164: /**
165: *
166: *
167: */
168: public Model[] getWebActionModels(int modelType) {
169: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
170: // This means it will automatically be executed via its retrieve()
171: // method when the tiled view begins display.
172:
173: switch (modelType) {
174: case MODEL_TYPE_RETRIEVE:
175: case MODEL_TYPE_DELETE:
176: case MODEL_TYPE_UPDATE:
177: return new Model[] { getModel() };
178: }
179:
180: return new Model[0];
181: }
182:
183: /**
184: * Subclasses may override to handle appropriately. This implementation
185: * forwards to itself.
186: */
187: /* public void handleDelButtonRequest(RequestInvocationEvent event)
188: throws ModelControlException {
189: TiledViewRequestInvocationEvent tiledEvent =
190: (TiledViewRequestInvocationEvent)event;
191: int selRow = tiledEvent.getTileNumber();
192: getPrimaryModel().setLocation(selRow);
193: FiltersListModel m = getModel();
194: m.delRule(selRow);
195: ViewBean viewBean = getParentViewBean();
196: viewBean.forwardTo(getRequestContext());
197: }
198: */
199:
200: public void handleFilterLinkRequest(RequestInvocationEvent event)
201: throws ModelControlException {
202:
203: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
204: int selRow = tiledEvent.getTileNumber();
205: getPrimaryModel().setLocation(selRow);
206:
207: String target = (String) getDisplayFieldValue(FILTER_HREF);
208: ViewBean pvb = getParentViewBean();
209: HttpServletResponse response = (pvb.getRequestContext())
210: .getResponse();
211:
212: try {
213: response.sendRedirect("Filter?id=" + target);
214: } catch (IOException e) {
215: //TOFIX: handle this
216: }
217: }
218: /* public void handleMenuLinkRequest(RequestInvocationEvent event)
219: throws ModelControlException{
220: ViewBean viewBean = getParentViewBean();
221: viewBean.forwardTo(getRequestContext());
222:
223: }
224: */
225: /* public boolean nextTile() throws ModelControlException{
226: boolean movedToRow = super.nextTile();
227: if (movedToRow){
228: // Put row specific logic here
229: int index = getTileIndex();
230: FiltersListModel m = getModel();
231: String tmpStr = null;
232: tmpStr = m.getID(index);
233: setDisplayFieldValue(FILTER_HREF, tmpStr == null ? "" : tmpStr);
234: tmpStr = m.getNickName(index);
235: setDisplayFieldValue(NICK_NAME_LABEL, tmpStr == null ? "" : tmpStr);
236: tmpStr = m.DefaultLabel();
237: if (tmpStr != null) {
238: setDisplayFieldValue(this.NEW_SITE_DEFAULT_LABEL, tmpStr);
239: }
240: if (m.isOn(index)) {
241: setDisplayFieldValue(ON_OFF_RBUTTON, "true");
242: }
243: else {
244: setDisplayFieldValue(ON_OFF_RBUTTON, "false");
245: }
246: setDisplayFieldValue(DEL_BUTTON, "Del");
247: //tmpStr = m.getMenuLabel(index);
248: //setDisplayFieldValue(MENU_LABEL, tmpStr == null ? "" : tmpStr);
249: }
250: return movedToRow;
251: }
252: public void handleOkButtonRequest()
253: throws ModelControlException {
254: DatasetModel model = getPrimaryModel();
255: model.beforeFirst();
256: while ( model.next()) {
257: String on_off = (String)model.getValue(this.ON_OFF_RBUTTON);
258: FilterRule fr = CSConfig.getRobotConfig().GetRuleByIndex(model.getLocation());
259: if ( fr != null) {
260: fr.enable = RobotConfig.StringtoBoolean(on_off);
261: }
262: }
263: }
264: */
265:
266: }
|