001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * TableUtilities.java
039: *
040: */
041:
042: package com.sun.jbi.jsf.util;
043:
044: import com.sun.data.provider.impl.ObjectListDataProvider;
045: import com.sun.data.provider.FieldKey;
046: import com.sun.data.provider.RowKey;
047: import com.sun.webui.jsf.component.TableRowGroup;
048: import java.util.ArrayList;
049: import java.util.List;
050: import java.util.Properties;
051: import java.util.logging.Logger;
052:
053: /**
054: *
055: * Provides utilities for JBI related tables
056: *
057: **/
058:
059: public final class TableUtilities {
060:
061: /**
062: * Controls printing of diagnostic messages to the log
063: */
064: private static Logger sLog = JBILogger.getInstance();
065:
066: public final static String KEY_NAME = "name";
067: public final static String KEY_TYPE = "type";
068:
069: /**
070: * Returns a list of names and types for the selected rows.
071: * @param aGroup <code>TableRowGroup</code> the table data with some rows selected.
072: * @return <code>List</code> of <code>Properties</code> objects
073: * <p> Each properties object has 'name' and 'type' keys and values.
074: */
075: public static List getSelectedRowProperties(TableRowGroup aGroup) {
076: ArrayList result = new ArrayList();
077:
078: ObjectListDataProvider dp = (ObjectListDataProvider) aGroup
079: .getSourceData();
080:
081: if (null != dp) {
082: try {
083: FieldKey fkName = dp.getFieldKey(KEY_NAME);
084: FieldKey fkType = dp.getFieldKey(KEY_TYPE);
085:
086: RowKey[] rowKeys = aGroup.getSelectedRowKeys();
087:
088: for (int cnt = 0; cnt < rowKeys.length; cnt++) {
089: Properties selectedRowProperties = new Properties();
090:
091: String compName = (String) dp.getValue(fkName,
092: rowKeys[cnt]);
093:
094: selectedRowProperties.setProperty(KEY_NAME,
095: compName);
096:
097: String compType = (String) dp.getValue(fkType,
098: rowKeys[cnt]);
099:
100: selectedRowProperties.setProperty(KEY_TYPE,
101: compType);
102:
103: result.add(selectedRowProperties);
104: }
105: } catch (Exception ex) {
106: // TBD use logging warning
107: sLog
108: .fine("OperationHandlers.getSelectedRowProperties(), caught ex="
109: + ex);
110: ex.printStackTrace(System.err);
111: }
112: } else {
113: sLog
114: .fine("OperationHandlers.getSelectedRowProperties(), cannot process dp="
115: + dp);
116: }
117:
118: sLog
119: .fine("OperationHandlers.getSelectedRowProperties(), result="
120: + result);
121: return result;
122: }
123:
124: }
|