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:
012: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
013: import com.iplanet.jato.view.View;
014: import com.iplanet.jato.view.ViewBean;
015: import com.iplanet.jato.view.ViewBeanBase;
016: import com.iplanet.jato.view.TiledView;
017: import com.iplanet.jato.RequestHandler;
018: import com.iplanet.jato.model.*;
019: import com.iplanet.jato.view.event.DisplayEvent;
020: import com.iplanet.jato.view.event.RequestInvocationEvent;
021: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
022: import com.iplanet.jato.view.event.ChildDisplayEvent;
023: import com.iplanet.jato.view.html.StaticTextField;
024: import com.iplanet.jato.view.html.ComboBox;
025: import com.iplanet.jato.view.html.TextField;
026: import com.iplanet.jato.view.html.OptionList;
027: import com.iplanet.jato.view.html.CheckBox;
028: import com.iplanet.jato.view.html.HREF;
029: import com.iplanet.jato.view.html.HiddenField;
030: import com.iplanet.jato.model.DatasetModel;
031: import com.iplanet.jato.util.Encoder;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import com.sun.portal.search.admin.resources.SearchResource;
036: import com.iplanet.am.console.components.view.html.IPlanetButton;
037:
038: import com.sun.portal.search.admin.model.SchemaListModel;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: public class SchemaListView extends RequestHandlingTiledViewBase
042: implements TiledView, RequestHandler {
043: public static final String NAME_TEXT = "Name";
044: public static final String DEL_NAME_TEXT = "DelName";
045: public static final String DESC_TEXT = "Desc";
046: public static final String ALIAS_TEXT = "Alias";
047: public static final String EDIT_HREF = "EditAction";
048: /*public static final String DATATYPE_COMBO = "DataType";
049: public static final String EDITABLE_CHECKBOX = "Editable";
050: public static final String INDEXABLE_CHECKBOX = "Indexable";
051: */
052: public static final String DEL_CHECKBOX = "Delete";
053:
054: private SchemaListModel model = null;
055:
056: // Create a Logger for this class
057: private static Logger debugLogger = PortalLogger
058: .getLogger(SchemaListView.class);
059:
060: public SchemaListView(View parent, String name) {
061: super (parent, name);
062: setPrimaryModelClass(SchemaListModel.class);
063: registerChildren();
064: }
065:
066: protected void registerChildren() {
067: registerChild(NAME_TEXT, StaticTextField.class);
068: registerChild(DEL_NAME_TEXT, HiddenField.class);
069: registerChild(DESC_TEXT, StaticTextField.class);
070: registerChild(EDIT_HREF, HREF.class);
071: //registerChild(ALIAS_TEXT, TextField.class);
072: //registerChild(EDITABLE_CHECKBOX, CheckBox.class);
073: //registerChild(INDEXABLE_CHECKBOX, CheckBox.class);
074: registerChild(DEL_CHECKBOX, CheckBox.class);
075:
076: //registerChild(DATATYPE_COMBO, ComboBox.class);
077: }
078:
079: protected View createChild(String name) {
080: if (name.equals(NAME_TEXT)) {
081: return new StaticTextField(this , getModel(), NAME_TEXT,
082: SchemaListModel.FIELD_NAME, "", null);
083: }
084: if (name.equals(DEL_NAME_TEXT)) {
085: return new HiddenField(this , getModel(), DEL_NAME_TEXT,
086: SchemaListModel.FIELD_DELNAME, "", null);
087: }
088: if (name.equals(DESC_TEXT)) {
089: return new StaticTextField(this , getModel(), DESC_TEXT,
090: SchemaListModel.FIELD_DESC, "", null);
091: }
092: /*if (name.equals(ALIAS_TEXT)) {
093: return new TextField(this, getModel(), ALIAS_TEXT, SchemaListModel.FIELD_ALIAS,"", null);
094: }
095: if (name.equals(EDITABLE_CHECKBOX)){
096: return new CheckBox(this, getModel(), EDITABLE_CHECKBOX, SchemaListModel.FIELD_EDITABLE, "true", "false", false, null);
097: }
098: if (name.equals(INDEXABLE_CHECKBOX)){
099: return new CheckBox(this, getModel(), INDEXABLE_CHECKBOX, SchemaListModel.FIELD_DELETE, "true", "false", false, null);
100: }*/
101: if (name.equals(DEL_CHECKBOX)) {
102: return new CheckBox(this , getModel(), DEL_CHECKBOX,
103: SchemaListModel.FIELD_DELETE, "true", "false",
104: false, null);
105: }
106: if (name.equals(EDIT_HREF)) {
107: return new HREF(this , getModel(), EDIT_HREF,
108: SchemaListModel.FIELD_ENCODED_NAME, "");
109: }
110: /*
111: if (name.equals(DATATYPE_COMBO)){
112: ComboBox child = new ComboBox(this, getModel(), DATATYPE_COMBO, SchemaListModel.FIELD_DATATYPE, "");
113: child.setOptions(new OptionList(SchemaListModel.DATA_TYPES, SchemaListModel.DATA_TYPES));
114: return child;
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: SchemaListModel model = (SchemaListModel) 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: /**
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: case MODEL_TYPE_INSERT:
154: SchemaListModel model = getModel();
155: return new Model[] { model };
156: }
157:
158: return new Model[0];
159: }
160:
161: /**
162: *
163: *
164: */
165: public SchemaListModel getModel() {
166:
167: SchemaListModel model = (SchemaListModel) getRequestContext()
168: .getModelManager().getModel(SchemaListModel.class);
169: //model.modified = (getParentViewBean().getPageSessionAttribute("isSchemaListModelLoaded") != null);
170: //getParentViewBean().setPageSessionAttribute("isSchemaListModelLoaded", "true");
171: return model;
172: /*
173: if (model == null) {
174: model = (RobotClassRuleListModel)getRequestContext().getModelManager().getModel(
175: RobotClassRuleListModel.class);
176: CSViewBeanBase pvb = (CSViewBeanBase)getParentViewBean();
177: model.userLocale = pvb.getUserLocale();
178: }
179: return model;
180: */
181: }
182:
183: public void handleEditActionRequest(RequestInvocationEvent event)
184: throws ModelControlException {
185:
186: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
187: int selRow = tiledEvent.getTileNumber();
188: getPrimaryModel().setLocation(selRow);
189: ViewBean pvb = getParentViewBean();
190:
191: String encodedName = (String) getDisplayFieldValue(EDIT_HREF);
192: if (encodedName != null) {
193: try {
194: HttpServletResponse response = (pvb.getRequestContext())
195: .getResponse();
196:
197: try {
198: response.sendRedirect("SchemaEditor?SchemaName="
199: + encodedName);
200: } catch (IOException e) {
201: //TOFIX: handle this
202: }
203: //pvb.setPageSessionAttribute("SchemaName", schemaName);
204: } catch (Exception e) {
205: }
206: }
207: //pvb.forwardTo(getRequestContext());
208: }
209:
210: }
|