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.CheckBox;
026: import com.iplanet.jato.view.html.TextField;
027: import com.iplanet.jato.view.html.OptionList;
028: import com.iplanet.jato.view.html.Button;
029:
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: import com.sun.portal.search.admin.model.DomainGroupListModel;
037: import com.sun.portal.log.common.PortalLogger;
038:
039: /**
040: * This view uses model of type DomainGroupListModel to display a list of
041: * Domains in tiled view in Site Definition Page
042: */
043: public class DomainGroupListView extends RequestHandlingTiledViewBase
044: implements TiledView, RequestHandler {
045: public static final String DOMAIN_TEXT = "DomainAlias";
046: public static final String DEL_DOMAIN_BUTTON = "DelDomain";
047: public static final String DEL_CHECKBOX = "Delete";
048:
049: public String rulesetID = null;
050:
051: // Create a logger for this class
052: private static Logger debugLogger = PortalLogger
053: .getLogger(DomainGroupListView.class);
054:
055: public DomainGroupListView(View parent, String name) {
056: super (parent, name);
057: setPrimaryModelClass(DomainGroupListModel.class);
058: registerChildren();
059: }
060:
061: protected void registerChildren() {
062: registerChild(DOMAIN_TEXT, TextField.class);
063: registerChild(DEL_DOMAIN_BUTTON, IPlanetButton.class);
064: registerChild(DEL_CHECKBOX, CheckBox.class);
065: }
066:
067: protected View createChild(String name) {
068: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
069: if (name.equals(DOMAIN_TEXT)) {
070: return new TextField(this , getModel(), DOMAIN_TEXT,
071: DomainGroupListModel.FIELD_DOMAIN, "", null);
072: }
073: if (name.equals(DEL_CHECKBOX)) {
074: return new CheckBox(this , getModel(), DEL_CHECKBOX,
075: DomainGroupListModel.FIELD_DELETE, "true", "false",
076: false, null);
077: }
078: if (name.equals(DEL_DOMAIN_BUTTON)) {
079: return new IPlanetButton(this , DEL_DOMAIN_BUTTON, pvb
080: .getLocalizedString("delete.text"));
081: }
082: throw new IllegalArgumentException("Invalid child name: "
083: + name);
084: }
085:
086: /**
087: *
088: *
089: */
090: public void beginDisplay(DisplayEvent event)
091: throws ModelControlException {
092: // Ensure the primary model is non-null; if null, it would cause
093: // havoc with the various methods dependent on the primary model
094: DomainGroupListModel model = (DomainGroupListModel) getPrimaryModel();
095: if (model == null) {
096: debugLogger.finer("PSSH_CSPSA0023");
097: throw new ModelControlException("Primary model is null");
098: }
099:
100: // The model will be executed automatically here by the base class
101: super .beginDisplay(event);
102:
103: resetTileIndex();
104: }
105:
106: public boolean beginDelDomainDisplay(ChildDisplayEvent event)
107: throws ModelControlException {
108: return (getModel().getSize() > 1);
109: }
110:
111: /**
112: *
113: *
114: */
115: public DomainGroupListModel getModel() {
116: return (DomainGroupListModel) getRequestContext()
117: .getModelManager().getModel(DomainGroupListModel.class);
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: DomainGroupListModel model = getModel();
129:
130: switch (modelType) {
131: case MODEL_TYPE_RETRIEVE:
132: debugLogger.finer("PSSH_CSPSA0036");
133: if (this .getParentViewBean().getPageSessionAttribute(
134: "retrieved") == null) {
135: // first time do retrieve
136: model.setID(this .rulesetID);
137: }
138: return new Model[] { model };
139: case MODEL_TYPE_UPDATE:
140: debugLogger.finer("PSSH_CSPSA0037");
141: model.setID(this .rulesetID);
142: return new Model[] { model };
143: case MODEL_TYPE_INSERT:
144: debugLogger.finer("PSSH_CSPSA0038");
145: return new Model[] { model };
146: case MODEL_TYPE_DELETE:
147: debugLogger.finer("PSSH_CSPSA0039");
148: return new Model[] { model };
149: }
150:
151: return new Model[0];
152: }
153:
154: public void handleDelDomainRequest(RequestInvocationEvent event)
155: throws ModelControlException {
156: getParentViewBean()
157: .setPageSessionAttribute("retrieved", "true");
158: DomainGroupListModel model = getModel();
159: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
160: int selRow = tiledEvent.getTileNumber();
161: model.setDelIndex(selRow);
162: try {
163: ModelExecutionContext modExe = new ModelExecutionContextBase(
164: ModelExecutionContext.OPERATION_DELETE);
165: executeAutoDeletingModels(modExe);
166: } catch (ModelControlException e) {
167: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
168: .getMessage());
169: }
170:
171: ViewBean viewBean = getParentViewBean();
172: viewBean.forwardTo(getRequestContext());
173: }
174:
175: }
|