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.ImportListModel;
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.ImageField;
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.view.html.Button;
030: import com.iplanet.jato.view.html.CheckBox;
031: import com.iplanet.jato.model.DatasetModel;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import com.iplanet.am.console.components.view.html.IPlanetButton;
036:
037: import com.sun.portal.search.robot.RobotConfig;
038: import com.sun.portal.search.robot.FilterRule;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: /**
042: * This view uses model of type AMIndentedListModel to display a tree like
043: * heirarchichal data structure in expanded tree form. So when a tree is
044: * expanded its nodes are displayed as indented rows. The indentation is
045: * relative to the parent node.
046: * Each row has this structure: [checkbox]name[link]
047: * The checkbox and link can be turned on or off. Thus,those nodes which are only
048: * for labeling purpose, can have only the name displayed in the row. This view
049: * uses TiledView of JATO, and hence each row is a tile.
050: * Typicaly, the subclasses will use the link to display the properties
051: * associated with the name, and checkbox may be used for add/delete operations.
052: */
053: public class ImportListView extends RequestHandlingTiledViewBase
054: implements TiledView, RequestHandler {
055: public static final String ON_OFF_RBUTTON = "OnOffRButton";
056: public static final String IMPORT_HREF = "ImportLink";
057: public static final String NAME_LABEL = "NameLabel";
058: public static final String TYPE_IMAGE = "TypeImage";
059: public static final String TYPE_LABEL = "TypeLabel";
060: public static final String DEL_CHECKBOX = "Delete";
061: //public static final String DEL_BUTTON = "DelButton";
062: private static OptionList options = new OptionList(new String[] {
063: "", "" }, // labels
064: new String[] { "true", "false" }); // values
065:
066: // Create a logger for this class
067: private static Logger debugLogger = PortalLogger
068: .getLogger(ImportListView.class);
069:
070: private ImportListModel model = null;
071:
072: public ImportListView(View parent, String name) {
073: super (parent, name);
074: this .setPrimaryModelClass(ImportListModel.class);
075: registerChildren();
076: }
077:
078: protected void registerChildren() {
079: registerChild(ON_OFF_RBUTTON, RadioButtonGroup.class);
080: registerChild(TYPE_IMAGE, ImageField.class);
081: registerChild(IMPORT_HREF, HREF.class);
082: registerChild(TYPE_LABEL, StaticTextField.class);
083: registerChild(DEL_CHECKBOX, CheckBox.class);
084: //registerChild(DEL_BUTTON, IPlanetButton.class);
085: }
086:
087: protected View createChild(String name) {
088: if (name.equals(ON_OFF_RBUTTON)) {
089: RadioButtonGroup child = new RadioButtonGroup(this ,
090: getModel(), ON_OFF_RBUTTON,
091: ImportListModel.FIELD_ENABLE, "", null);
092: child.setOptions(options);
093: return child;
094: }
095: if (name.equals(TYPE_IMAGE)) {
096: return new ImageField(this , getModel(), TYPE_IMAGE,
097: ImportListModel.FIELD_IMAGE, "", null);
098: }
099: if (name.equals(IMPORT_HREF)) {
100: return new HREF(this , getModel(), IMPORT_HREF,
101: ImportListModel.FIELD_ID, "", null);
102: }
103: if (name.equals(NAME_LABEL)) {
104: return new StaticTextField(this , getModel(), NAME_LABEL,
105: ImportListModel.FIELD_NAME, "", null);
106: }
107: if (name.equals(DEL_CHECKBOX)) {
108: return new CheckBox(this , getModel(), DEL_CHECKBOX,
109: ImportListModel.FIELD_DELETE, "true", "false",
110: false, null);
111: }
112: // if (name.equals(DEL_BUTTON)){
113: // return new IPlanetButton(this, DEL_BUTTON,"Delete");
114: // }
115: throw new IllegalArgumentException("Invalid child name ["
116: + name + "]");
117: }
118:
119: /**
120: *
121: *
122: */
123: public void beginDisplay(DisplayEvent event)
124: throws ModelControlException {
125: // Ensure the primary model is non-null; if null, it would cause
126: // havoc with the various methods dependent on the primary model
127: ImportListModel model = (ImportListModel) getPrimaryModel();
128: if (model == null) {
129:
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: /**
141: *
142: *
143: */
144: public Model[] getWebActionModels(int modelType) {
145: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
146: // This means it will automatically be executed via its retrieve()
147: // method when the tiled view begins display.
148:
149: switch (modelType) {
150: case MODEL_TYPE_RETRIEVE:
151: case MODEL_TYPE_DELETE:
152: case MODEL_TYPE_UPDATE:
153: return new Model[] { getModel() };
154: }
155:
156: return new Model[0];
157: }
158:
159: /**
160: *
161: *
162: */
163: public ImportListModel getModel() {
164: ImportListModel model = (ImportListModel) getRequestContext()
165: .getModelManager().getModel(ImportListModel.class);
166: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
167: model.userLocale = pvb.getUserLocale();
168: return model;
169: }
170:
171: /**
172: * Subclasses may override to handle appropriately. This implementation
173: * forwards to itself.
174: */
175: /* public void handleDelButtonRequest(RequestInvocationEvent event)
176: throws ModelControlException {
177: TiledViewRequestInvocationEvent tiledEvent =
178: (TiledViewRequestInvocationEvent)event;
179: int selRow = tiledEvent.getTileNumber();
180: ImportConfig.DeleteImportConfigByIndex(selRow);
181: ViewBean viewBean = getParentViewBean();
182: viewBean.forwardTo(getRequestContext());
183: }
184: */
185:
186: public void handleImportLinkRequest(RequestInvocationEvent event)
187: throws ModelControlException {
188:
189: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
190: int selRow = tiledEvent.getTileNumber();
191: getPrimaryModel().setLocation(selRow);
192:
193: String target = (String) getDisplayFieldValue(IMPORT_HREF);
194: ViewBean pvb = getParentViewBean();
195: HttpServletResponse response = (pvb.getRequestContext())
196: .getResponse();
197:
198: try {
199: response.sendRedirect("ImportAgent?id=" + target);
200: } catch (IOException e) {
201: //TOFIX: handle this
202: }
203: }
204:
205: }
|