001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * Author: Anurag Gupta
014: */package com.sun.portal.netfile.admin;
015:
016: // JDK classes
017: import java.io.Serializable;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.Iterator;
020: import java.util.Map;
021: import java.util.Set;
022: import java.util.StringTokenizer;
023: import java.util.Vector;
024:
025: // iPlanet JATO classes
026: import com.iplanet.jato.RequestHandler;
027: import com.iplanet.jato.model.DatasetModel;
028: import com.iplanet.jato.model.ModelControlException;
029: import com.iplanet.jato.util.Encoder;
030: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
031: import com.iplanet.jato.view.TiledView;
032: import com.iplanet.jato.view.View;
033: import com.iplanet.jato.view.ViewBean;
034: import com.iplanet.jato.view.event.DisplayEvent;
035: import com.iplanet.jato.view.event.RequestInvocationEvent;
036: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
037: import com.iplanet.jato.view.html.CheckBox;
038: import com.iplanet.jato.view.html.HiddenField;
039: import com.iplanet.jato.view.html.HREF;
040: import com.iplanet.jato.view.html.StaticTextField;
041:
042: // NetFile admin console classes
043: import com.sun.portal.netfile.admin.model.NetFileUserProfileModelImpl;
044:
045: public class NetFileHostsUserProfileTiledView extends
046: RequestHandlingTiledViewBase implements TiledView,
047: RequestHandler {
048: public static final String CHILD_CB_SELECT_HOST = "cbSelectHost";
049: public static final String CHILD_HREF_EDIT_HOST = "hrefEditHost";
050: public static final String CHILD_HREF_TEXT = "hrefText";
051: public static final String CHILD_HOST_NAME = "hostName";
052: public static final String CHILD_EDIT_LABEL = "editLabel";
053:
054: private NetFileUserProfileModelImpl model = null;
055: private NetFileAdminModelManager modelManager = null;
056: private Vector netFileHosts = null;
057:
058: /* the maximum number of tiles per page */
059: private static final int MAX_DISPLAY_TILES = 100;
060:
061: /**
062: * Default constructor.
063: * @param parent the parent view of this tileview.
064: * @param name the name of this tileview.
065: */
066: public NetFileHostsUserProfileTiledView(View parent, String name) {
067: super (parent, name);
068: setMaxDisplayTiles(MAX_DISPLAY_TILES);
069: setPrimaryModel((DatasetModel) getDefaultModel());
070: registerChildren();
071: }
072:
073: /**
074: * Register the child objects of the tileview.
075: */
076: protected void registerChildren() {
077: registerChild(CHILD_CB_SELECT_HOST, CheckBox.class);
078: registerChild(CHILD_HREF_EDIT_HOST, HREF.class);
079: registerChild(CHILD_HREF_TEXT, StaticTextField.class);
080: registerChild(CHILD_HOST_NAME, HiddenField.class);
081: registerChild(CHILD_EDIT_LABEL, StaticTextField.class);
082: }
083:
084: /**
085: * Creates and return the child view objects for the specified name.
086: * @param name the child view name.
087: * @return the child view object that corresponds to the given name.
088: */
089: protected View createChild(String name) {
090: getModel();
091: getModelMgr();
092: if (name.equals(CHILD_CB_SELECT_HOST)) {
093: return new CheckBox(this , CHILD_CB_SELECT_HOST, "true",
094: "false", false);
095: } else if (name.equals(CHILD_HREF_EDIT_HOST)) {
096: return new HREF(this , CHILD_HREF_EDIT_HOST, "");
097: } else if (name.equals(CHILD_HREF_TEXT)) {
098: return new StaticTextField(this , CHILD_HREF_EDIT_HOST, "");
099: } else if (name.equals(CHILD_HOST_NAME)) {
100: return new HiddenField(this , CHILD_HOST_NAME, "");
101: } else if (name.equals(CHILD_EDIT_LABEL)) {
102: String editLbl = modelManager.getString("edit.label");
103: if (model.isReadOnly("sunPortalNetFileCommonHostData")) {
104: editLbl = modelManager.getString("view.label");
105: }
106: return new StaticTextField(this , CHILD_EDIT_LABEL, editLbl);
107: } else {
108: throw new IllegalArgumentException(name);
109: }
110: }
111:
112: public void beginDisplay(DisplayEvent event)
113: throws ModelControlException {
114: getModel(); // Get the admin model manager and model.
115: Set s = model.getNetFileHosts();
116: netFileHosts = new Vector(s);
117: getPrimaryModel().setSize(netFileHosts.size());
118: resetTileIndex();
119: }
120:
121: protected NetFileUserProfileModelImpl getModel() {
122: if (model == null) {
123: NetFileUserProfileViewBeanBase viewBean = (NetFileUserProfileViewBeanBase) getParentViewBean();
124: model = (NetFileUserProfileModelImpl) viewBean.getModel();
125: model.initModel(viewBean.getUserDN());
126: }
127: return model;
128: }
129:
130: public NetFileAdminModelManager getModelMgr() {
131: if (modelManager == null) {
132: modelManager = (NetFileAdminModelManager) getRequestContext()
133: .getModelManager();
134: }
135: return modelManager;
136: }
137:
138: public boolean nextTile() throws ModelControlException {
139: boolean movedToRow = super .nextTile();
140: if (movedToRow) {
141: if (netFileHosts == null) {
142: getModel(); // Get the admin model manager and model.
143: Set s = model.getNetFileHosts();
144: netFileHosts = new Vector(s);
145: }
146: // getPrimaryModel().setLocation(getTileIndex());
147: if (netFileHosts != null) {
148: String nr = (String) netFileHosts.get(getTileIndex());
149: StringTokenizer tok = new StringTokenizer(nr,
150: NetFileHostsViewBean.HOST_DELIM);
151: if (tok.hasMoreElements()) {
152: String hostName = tok.nextToken();
153: hostName = hostName
154: .substring(NetFileHostsUserProfileViewBean.hostListStrHost
155: .length());
156: setDisplayFieldValue(CHILD_HREF_TEXT, hostName);
157: setDisplayFieldValue(CHILD_HOST_NAME, hostName);
158: }
159: }
160: }
161: return movedToRow;
162: }
163:
164: /**
165: * Handles the event to edit a given hostset.
166: * @param event the event to edit a given hostset.
167: * @exception throws ModelControlException when error(s) occurred.
168: */
169: public void handleHrefEditHostRequest(RequestInvocationEvent event)
170: throws ModelControlException {
171: /* Forward to the edit host viewbean. */
172: getModelMgr();
173: modelManager
174: .setCurrentNetFileHostsRow(((TiledViewRequestInvocationEvent) event)
175: .getTileNumber());
176: NetFileHostsUserProfileViewBean vb = (NetFileHostsUserProfileViewBean) getViewBean(NetFileHostsUserProfileViewBean.class);
177: passPgSessionMap(vb);
178: vb.forwardTo(getRequestContext());
179: }
180:
181: /*
182: * Returns the netFileHosts vector
183: * Called by NetFileDataViewBean when DELETE button of
184: * netfile hosts is clicked
185: */
186: public Vector getNetFileHosts() {
187: if (netFileHosts == null) {
188: getModel(); // Get the admin model manager and model.
189: Set s = model.getNetFileHosts();
190: netFileHosts = new Vector(s);
191: }
192: return netFileHosts;
193: }
194:
195: public int getNetFileHostsCount() {
196: Vector nrs = getNetFileHosts();
197: if (nrs != null) {
198: return nrs.size();
199: }
200: return 0;
201: }
202:
203: /*
204: * Gets the pageSessionAttributes map from the parent viewBean (NetFileDataViewBean)
205: * and sets these attributes for the other viewBean
206: */
207: public Map getPageSessionAttributes() {
208: NetFileUserProfileViewBeanBase viewBean = (NetFileUserProfileViewBeanBase) getParentViewBean();
209: String attrs = viewBean.getPageSessionAttributeString();
210: Map attributes = null;
211: if (attrs != null) {
212: try {
213: attributes = (Map) Encoder.deserialize(Encoder
214: .decodeHttp64(attrs), false);
215: } catch (Exception ex) {
216: attributes = null;
217: }
218: }
219: return attributes;
220: }
221:
222: public void passPgSessionMap(ViewBean other) {
223: Map attributes = getPageSessionAttributes();
224: if ((attributes != null) && (attributes.size() > 0)) {
225: Iterator iter = attributes.keySet().iterator();
226: while (iter.hasNext()) {
227: String key = (String) iter.next();
228: other.setPageSessionAttribute(key,
229: (Serializable) attributes.get(key));
230: }
231: }
232: }
233: }
|