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
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.model;
042:
043: import com.sun.data.provider.FieldKey;
044: import com.sun.data.provider.impl.ObjectArrayDataProvider;
045: import com.sun.rave.web.ui.util.MessageUtil;
046: import java.util.ArrayList;
047: import java.util.HashMap;
048: import java.util.List;
049:
050: /**
051: * Default date for the <code>Table</code> component. The following behavior is
052: * implemented:
053: * <ul>
054: * <li>Upon component creation, pre-populate the table with some dummy data</li>
055: * </ul>
056: *
057: * @author Winston Prakash
058: */
059: public class DefaultTableDataProvider extends ObjectArrayDataProvider {
060:
061: /** Default constructor. */
062: public DefaultTableDataProvider() {
063: setArray(getDefaultTableData());
064: }
065:
066: /**
067: * Create data that will be displayed when the table is first dropped
068: * in the designer
069: */
070: public Data[] getDefaultTableData() {
071: int noRows = 5;
072: int noCols = 3;
073: Data[] dataSet = new Data[noRows];
074: for (int i = 0; i < noRows; i++) {
075: String[] dataStrs = new String[noCols];
076: for (int j = 0; j < noCols; j++) {
077: dataStrs[j] = getMessage("defaultTblCell", String
078: .valueOf(i + 1), String.valueOf(j + 1));
079: }
080: dataSet[i] = new Data(dataStrs);
081: }
082: return dataSet;
083: }
084:
085: /** Return the Field Keys skiiping the 0th index
086: * which is the "class" property
087: */
088: public FieldKey[] getFieldKeys() {
089: FieldKey[] super FieldKeys = super .getFieldKeys();
090: FieldKey[] fieldKeys = new FieldKey[super FieldKeys.length - 1];
091: for (int i = 1; i < super FieldKeys.length; i++) {
092: fieldKeys[i - 1] = super FieldKeys[i];
093: }
094: return fieldKeys;
095: }
096:
097: /**
098: * Get the message substituting the arguments
099: */
100: public String getMessage(String key, String arg1, String arg2) {
101: String bundle = getClass().getPackage().getName() + ".Bundle";
102: return MessageUtil.getMessage(bundle, key, new Object[] { arg1,
103: arg2 });
104: }
105:
106: /**
107: * Data structure that holds data for three columns of a table
108: */
109: public static class Data {
110: private String[] columns = null;
111:
112: public Data(String[] cols) {
113: columns = cols;
114: }
115:
116: /** Get first column. */
117: public String getColumn1() {
118: return columns[0];
119: }
120:
121: /** Set first column. */
122: public void setColumn1(String col) {
123: columns[0] = col;
124: }
125:
126: /** Get second column. */
127: public String getColumn2() {
128: return columns[1];
129: }
130:
131: /** Set second column. */
132: public void setColumn2(String col) {
133: columns[1] = col;
134: }
135:
136: /** Get third column. */
137: public String getColumn3() {
138: return columns[2];
139: }
140:
141: /** Set third column. */
142: public void setColumn3(String col) {
143: columns[2] = col;
144: }
145: }
146:
147: }
|