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.DatabaseListModel;
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.HiddenField;
027: import com.iplanet.jato.view.html.Button;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.HREF;
030: import com.iplanet.jato.model.DatasetModel;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import com.iplanet.am.console.components.view.html.IPlanetButton;
035:
036: public class DatabaseListView extends RequestHandlingTiledViewBase
037: implements TiledView, RequestHandler {
038: public static final String CHILD_NAME = "DatabaseName";
039: public static final String CHILD_DESC = "DatabaseDesc";
040: public static final String CHILD_TITLE = "DatabaseTitle";
041: public static final String CHILD_EDIT = "DatabaseEdit";
042: public static final String CHILD_HIDDENNAME = "HiddenDatabaseName";
043: public static final String CHILD_RDCOUNT = "RDCount";
044: public static final String DEL_CHECKBOX = "Select";
045:
046: // Create a logger for this class
047: private static Logger debugLogger = PortalLogger
048: .getLogger(DatabaseListView.class);
049:
050: private DatabaseListModel model = null;
051:
052: public DatabaseListView(View parent, String name) {
053: super (parent, name);
054: this .setPrimaryModelClass(DatabaseListModel.class);
055: registerChildren();
056: }
057:
058: protected void registerChildren() {
059: registerChild(CHILD_NAME, StaticTextField.class);
060: registerChild(CHILD_DESC, StaticTextField.class);
061: registerChild(CHILD_TITLE, StaticTextField.class);
062: registerChild(CHILD_HIDDENNAME, HiddenField.class);
063: registerChild(CHILD_RDCOUNT, StaticTextField.class);
064: registerChild(DEL_CHECKBOX, CheckBox.class);
065: registerChild(CHILD_EDIT, HREF.class);
066: }
067:
068: protected View createChild(String name) {
069: if (name.equals(CHILD_NAME)) {
070: return new StaticTextField(this , getModel(), CHILD_NAME,
071: DatabaseListModel.FIELD_NAME, "", null);
072: }
073: if (name.equals(CHILD_DESC)) {
074: return new StaticTextField(this , getModel(), CHILD_DESC,
075: DatabaseListModel.FIELD_DESC, "", null);
076: }
077: if (name.equals(CHILD_TITLE)) {
078: return new StaticTextField(this , getModel(), CHILD_TITLE,
079: DatabaseListModel.FIELD_TITLE, "", null);
080: }
081: if (name.equals(CHILD_HIDDENNAME)) {
082: return new StaticTextField(this , getModel(),
083: CHILD_HIDDENNAME, DatabaseListModel.FIELD_NAME, "",
084: null);
085: }
086: if (name.equals(CHILD_RDCOUNT)) {
087: return new StaticTextField(this , getModel(), CHILD_RDCOUNT,
088: DatabaseListModel.FIELD_RDCOUNT, "0", null);
089: }
090: if (name.equals(DEL_CHECKBOX)) {
091: return new CheckBox(this , getModel(), DEL_CHECKBOX,
092: DatabaseListModel.FIELD_SELECT, "true", "false",
093: false, null);
094: }
095: if (name.equals(CHILD_EDIT)) {
096: return new HREF(this , getModel(), CHILD_EDIT,
097: DatabaseListModel.FIELD_NAME, "");
098: }
099: throw new IllegalArgumentException(getClass().getName()
100: + ":Invalid child name [" + name + "]");
101: }
102:
103: /**
104: *
105: *
106: */
107: public void beginDisplay(DisplayEvent event)
108: throws ModelControlException {
109: DatabaseListModel model = (DatabaseListModel) getPrimaryModel();
110: if (model == null) {
111: debugLogger.finer("PSSH_CSPSA0023");
112: throw new ModelControlException("Primary model is null");
113: }
114:
115: super .beginDisplay(event);
116:
117: resetTileIndex();
118: }
119:
120: /**
121: *
122: *
123: */
124: public Model[] getWebActionModels(int modelType) {
125: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
126: // This means it will automatically be executed via its retrieve()
127: // method when the tiled view begins display.
128:
129: switch (modelType) {
130: case MODEL_TYPE_RETRIEVE:
131: case MODEL_TYPE_DELETE:
132: return new Model[] { getModel() };
133: }
134:
135: return new Model[0];
136: }
137:
138: /**
139: *
140: *
141: */
142: public DatabaseListModel getModel() {
143: DatabaseListModel model = (DatabaseListModel) getRequestContext()
144: .getModelManager().getModel(DatabaseListModel.class);
145: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
146: model.userLocale = pvb.getUserLocale();
147: return model;
148: }
149:
150: public void handleDatabaseEditRequest(RequestInvocationEvent event)
151: throws ModelControlException {
152: DatabaseManageViewBean pvb = (DatabaseManageViewBean) this
153: .getParentViewBean();
154: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
155: int selRow = tiledEvent.getTileNumber();
156: setTileIndex(selRow);
157: String dbName = getDisplayFieldStringValue(CHILD_HIDDENNAME);
158: pvb.setPageSessionAttribute(pvb.PARAMETER_STATUS,
159: pvb.STATUS_EDIT);
160: pvb.setPageSessionAttribute(pvb.PARAMETER_EDITDB, dbName);
161: pvb.forwardTo(getRequestContext());
162: }
163:
164: }
|