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.net.URL;
009: import java.io.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase;
014: import com.sun.portal.search.admin.cli.RunImportAgent;
015: import com.sun.portal.log.common.PortalLogger;
016:
017: import javax.servlet.http.HttpServletRequest;
018: import javax.servlet.http.HttpServletResponse;
019:
020: import com.iplanet.jato.RequestContext;
021:
022: import com.iplanet.jato.view.event.DisplayEvent;
023: import com.iplanet.jato.view.event.ChildDisplayEvent;
024: import com.iplanet.jato.view.event.RequestInvocationEvent;
025:
026: import com.iplanet.jato.view.html.StaticTextField;
027: import com.iplanet.jato.view.html.TextField;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.Button;
030: import com.iplanet.jato.view.html.ComboBox;
031: import com.iplanet.jato.view.html.RadioButtonGroup;
032:
033: import com.iplanet.jato.view.html.Option;
034: import com.iplanet.jato.view.html.OptionList;
035:
036: import com.iplanet.jato.view.View;
037: import com.iplanet.jato.view.ViewBean;
038: import com.iplanet.jato.view.ViewBeanBase;
039:
040: import com.iplanet.jato.ViewBeanManager;
041:
042: import com.iplanet.jato.model.*;
043:
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: /**
047: * iPS admin console view bean: TODO
048: */
049: public class ImportAgentsViewBean extends CSViewBeanBase {
050: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/ImportAgents.jsp";
051: public static final String PAGE_NAME = "ImportAgents";
052: public static final String RUNSCRIPT_CONTENT = "RunScript";
053: public static final String NEW_BUTTON = "NewButton";
054: public static final String DELETE_BUTTON = "DeleteButton";
055: public static final String RUN_BUTTON = "RunButton";
056: public static final String IMPORTAGENT_LIST = "ImportList";
057: public static final String SUBMIT_BUTTON = "SubmitButton";
058: public static final String RESET_BUTTON = "ResetButton";
059:
060: // Create a logger for this class
061: private static Logger debugLogger = PortalLogger
062: .getLogger(ImportAgentsViewBean.class);
063:
064: /**
065: * constructor
066: *
067: * @param PageName of this view bean
068: * @param displayURL default display URL
069: */
070: public ImportAgentsViewBean() {
071: super (PAGE_NAME);
072: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
073: registerChildren();
074: }
075:
076: /**
077: * register child component
078: */
079: protected void registerChildren() {
080: registerChild(NEW_BUTTON, IPlanetButton.class);
081: registerChild(DELETE_BUTTON, IPlanetButton.class);
082: registerChild(RUN_BUTTON, IPlanetButton.class);
083: registerChild(SUBMIT_BUTTON, IPlanetButton.class);
084: registerChild(RESET_BUTTON, IPlanetButton.class);
085: registerChild(IMPORTAGENT_LIST, ImportListView.class);
086:
087: }
088:
089: /**
090: * create child component
091: *
092: * @param name of component
093: * @return child component
094: */
095: protected View createChild(String name) {
096: View Headerchild = super .createChild(name);
097: if (Headerchild != null)
098: return Headerchild;
099: if (name.equals(NEW_BUTTON)) {
100: return new IPlanetButton(this , NEW_BUTTON, "");
101: }
102: if (name.equals(DELETE_BUTTON)) {
103: return new IPlanetButton(this , DELETE_BUTTON, "");
104: }
105: if (name.equals(RUN_BUTTON)) {
106: return new IPlanetButton(this , RUN_BUTTON, "");
107: }
108: if (name.equals(SUBMIT_BUTTON)) {
109: return new IPlanetButton(this , SUBMIT_BUTTON, "");
110: }
111: if (name.equals(RESET_BUTTON)) {
112: return new IPlanetButton(this , RESET_BUTTON, "");
113: }
114: if (name.equals(IMPORTAGENT_LIST)) {
115: return new ImportListView(this , IMPORTAGENT_LIST);
116: }
117:
118: throw new IllegalArgumentException("Invalid child name ["
119: + name + "]");
120: }
121:
122: public void beginDisplay(DisplayEvent event) {
123: setPageEncoding();
124: setDisplayFieldValue(NEW_BUTTON, getLocalizedString("new.text"));
125: setDisplayFieldValue(DELETE_BUTTON,
126: getLocalizedString("delete.text"));
127: setDisplayFieldValue(RUN_BUTTON, getLocalizedString("run.text"));
128: setDisplayFieldValue(SUBMIT_BUTTON,
129: getLocalizedString("submit.text"));
130: setDisplayFieldValue(RESET_BUTTON,
131: getLocalizedString("reset.text"));
132: if (ImportConfig.numOfImportConfig() == 0) {
133: IPlanetButton child = (IPlanetButton) getChild(DELETE_BUTTON);
134: child.setEnable(false);
135: child = (IPlanetButton) getChild(RUN_BUTTON);
136: child.setEnable(false);
137: }
138: }
139:
140: public boolean beginListTableDisplay(ChildDisplayEvent event) {
141: return ImportConfig.numOfImportConfig() > 0;
142: }
143:
144: public boolean beginEmptyListDisplay(ChildDisplayEvent event) {
145: return ImportConfig.numOfImportConfig() == 0;
146: }
147:
148: public void handleNewButtonRequest(RequestInvocationEvent event) {
149: HttpServletResponse response = this .getRequestContext()
150: .getResponse();
151: try {
152: response.sendRedirect("ImportAgent");
153: } catch (IOException e) {
154: //TOFIX: handle this
155: }
156: }
157:
158: public void handleDeleteButtonRequest(RequestInvocationEvent event) {
159: ImportListView child = (ImportListView) getChild(IMPORTAGENT_LIST);
160: try {
161: ModelExecutionContext modExe = new ModelExecutionContextBase(
162: ModelExecutionContext.OPERATION_DELETE);
163: child.executeAutoDeletingModels(modExe);
164: } catch (ModelControlException e) {
165: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
166: .getMessage());
167: }
168: forwardTo();
169: }
170:
171: public void handleSubmitButtonRequest(RequestInvocationEvent event) {
172: ImportListView child = (ImportListView) getChild(IMPORTAGENT_LIST);
173: try {
174: ModelExecutionContext modExe = new ModelExecutionContextBase(
175: ModelExecutionContext.OPERATION_UPDATE);
176: child.executeAutoUpdatingModels(modExe);
177: } catch (ModelControlException e) {
178: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
179: .getMessage());
180: }
181: forwardTo();
182: }
183:
184: public void handleResetButtonRequest(RequestInvocationEvent event) {
185: forwardTo();
186: }
187:
188: }
|