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.net.URL;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
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.StaticTextField;
025: import com.iplanet.jato.view.html.ComboBox;
026: import com.iplanet.jato.view.html.TextField;
027: import com.iplanet.jato.view.html.OptionList;
028: import com.iplanet.jato.view.html.CheckBox;
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.admin.model.FilterGroupListModel;
036: import com.sun.portal.search.admin.resources.SearchResource;
037: import com.sun.portal.log.common.PortalLogger;
038:
039: /**
040: * This view uses model of type FilterGroupListModel to display list of filter
041: * in a tiled view in Site Definition Page
042: */
043: public class FilterGroupListView extends RequestHandlingTiledViewBase
044: implements TiledView, RequestHandler {
045: public static final String MATCH_COMBO = "match";
046: public static final String RULE_COMBO = "rule";
047: public static final String UP_SCRIPT = "MoveUp";
048: public static final String DOWN_SCRIPT = "MoveDown";
049: public static final String DEL_BUTTON = "DelFilter";
050: public static final String DEL_CHECKBOX = "Delete";
051: static String ARROWUP_IMAGE = "../ps/searchadmin/images/arrowup.gif";
052: static String ARROWDOWN_IMAGE = "../ps/searchadmin/images/arrowdown.gif";
053: public String rulesetID = null;
054:
055: // Create a logger for this class
056: private static Logger debugLogger = PortalLogger
057: .getLogger(FilterGroupListView.class);
058:
059: // private MenuListModel model = null;
060:
061: public FilterGroupListView(View parent, String name) {
062: super (parent, name);
063: setPrimaryModelClass(FilterGroupListModel.class);
064: registerChildren();
065: }
066:
067: protected void registerChildren() {
068: registerChild(MATCH_COMBO, ComboBox.class);
069: registerChild(RULE_COMBO, ComboBox.class);
070: registerChild(UP_SCRIPT, StaticTextField.class);
071: registerChild(DOWN_SCRIPT, StaticTextField.class);
072: registerChild(DEL_CHECKBOX, CheckBox.class);
073: registerChild(DEL_BUTTON, IPlanetButton.class);
074: }
075:
076: protected View createChild(String name) {
077: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
078: if (name.equals(MATCH_COMBO)) {
079: ComboBox child = new ComboBox(this , getModel(),
080: MATCH_COMBO, FilterGroupListModel.FIELD_MATCH, "",
081: null);
082: OptionList matchOptions = new OptionList(
083: pvb.getLocalizedStringArray("site.filter.options",
084: ","), // labels
085: new String[] { "deny", "allow" }); // values
086: child.setOptions(matchOptions);
087: return child;
088: }
089: if (name.equals(RULE_COMBO)) {
090: ComboBox child = new ComboBox(this , getModel(), RULE_COMBO,
091: FilterGroupListModel.FIELD_RULE, "", null);
092: child.setLabelForNoneSelected(pvb
093: .getLocalizedString("site.noneselected"));
094: OptionList ruleOptions = new OptionList(SearchResource
095: .geti18nStrings(CSConfig.getRobotConfig()
096: .getRuleNicknames(), pvb.getUserLocale()),
097: CSConfig.getRobotConfig().getRuleIDs());
098: child.setOptions(ruleOptions);
099: return child;
100: }
101: if (name.equals(UP_SCRIPT)) {
102: return new StaticTextField(this , UP_SCRIPT, "");
103: }
104: if (name.equals(DOWN_SCRIPT)) {
105: return new StaticTextField(this , DOWN_SCRIPT, "");
106: }
107: if (name.equals(DEL_BUTTON)) {
108: return new IPlanetButton(this , DEL_BUTTON, pvb
109: .getLocalizedString("delete.text"));
110: }
111: if (name.equals(DEL_CHECKBOX)) {
112: return new CheckBox(this , getModel(), DEL_CHECKBOX,
113: FilterGroupListModel.FIELD_DELETE, "true", "false",
114: false, null);
115: }
116: throw new IllegalArgumentException("Invalid child name: "
117: + name);
118: }
119:
120: /**
121: *
122: *
123: */
124: public void beginDisplay(DisplayEvent event)
125: throws ModelControlException {
126: // Ensure the primary model is non-null; if null, it would cause
127: // havoc with the various methods dependent on the primary model
128: FilterGroupListModel model = (FilterGroupListModel) getPrimaryModel();
129: if (model == null) {
130: debugLogger.finer("PSSH_CSPSA0023");
131: throw new ModelControlException("Primary model is null");
132: }
133:
134: // The model will be executed automatically here by the base class
135: super .beginDisplay(event);
136:
137: resetTileIndex();
138: }
139:
140: public boolean beginMoveDownDisplay(ChildDisplayEvent event)
141: throws ModelControlException {
142: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
143: int index = getDisplayIndex();
144: if (index < getPrimaryModel().getSize() - 1) {
145: setDisplayFieldValue(
146: DOWN_SCRIPT,
147: "<A HREF=\"javascript:moveDown("
148: + index
149: + ")\" onMouseOver=\"status='"
150: + pvb
151: .getLocalizedString("site.filter.decpriority")
152: + "';return true\">" + "<IMG SRC=\""
153: + ARROWDOWN_IMAGE + "\" BORDER=\"0\"></A>");
154: return true;
155: }
156: return false;
157: }
158:
159: public boolean beginMoveUpDisplay(ChildDisplayEvent event)
160: throws ModelControlException {
161: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
162: int index = getDisplayIndex();
163: if (index > 0) {
164: setDisplayFieldValue(
165: UP_SCRIPT,
166: "<A HREF=\"javascript:moveUp("
167: + index
168: + ")\" onMouseOver=\"status='"
169: + pvb
170: .getLocalizedString("site.filter.incpriority")
171: + "';return true\">" + "<IMG SRC=\""
172: + ARROWUP_IMAGE + "\" BORDER=\"0\"></A>");
173: return true;
174: }
175: return false;
176: }
177:
178: public boolean beginDelFilterDisplay(ChildDisplayEvent event)
179: throws ModelControlException {
180: return (getModel().getSize() > 1);
181: }
182:
183: /**
184: *
185: *
186: */
187: public FilterGroupListModel getModel() {
188: return (FilterGroupListModel) getRequestContext()
189: .getModelManager().getModel(FilterGroupListModel.class);
190: }
191:
192: /**
193: *
194: *
195: */
196: public Model[] getWebActionModels(int modelType) {
197: FilterGroupListModel model = getModel();
198:
199: switch (modelType) {
200: case MODEL_TYPE_RETRIEVE:
201: debugLogger.finer("PSSH_CSPSA0036");
202: if (this .getParentViewBean().getPageSessionAttribute(
203: "retrieved") == null) {
204: debugLogger.finer("PSSH_CSPSA0116");
205: model.setID(this .rulesetID);
206: }
207: return new Model[] { model };
208: case MODEL_TYPE_UPDATE:
209: debugLogger.finer("PSSH_CSPSA0037");
210: model.setID(this .rulesetID);
211: return new Model[] { model };
212: case MODEL_TYPE_INSERT:
213: debugLogger.finer("PSSH_CSPSA0038");
214: return new Model[] { model };
215: case MODEL_TYPE_DELETE:
216: debugLogger.finer("PSSH_CSPSA0039");
217: return new Model[] { model };
218: }
219:
220: return new Model[0];
221: }
222:
223: public void handleDelFilterRequest(RequestInvocationEvent event)
224: throws ModelControlException {
225: getParentViewBean()
226: .setPageSessionAttribute("retrieved", "true");
227: FilterGroupListModel model = getModel();
228: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
229: int selRow = tiledEvent.getTileNumber();
230: model.setDelIndex(selRow);
231: try {
232: ModelExecutionContext modExe = new ModelExecutionContextBase(
233: ModelExecutionContext.OPERATION_DELETE);
234: executeAutoDeletingModels(modExe);
235: } catch (ModelControlException e) {
236: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
237: .getMessage());
238: }
239: ViewBean viewBean = getParentViewBean();
240: viewBean.forwardTo(getRequestContext());
241: }
242: }
|