KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > PropertiesTableModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * PropertiesTableModel.java
21  *
22  * Created on October 1, 2003, 9:18 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import java.util.Vector JavaDoc;
28 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
29
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32
33 /**
34  *
35  * @author nityad
36  */

37 public class PropertiesTableModel extends javax.swing.table.AbstractTableModel JavaDoc {
38     private static java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.Bundle"); // NOI18N
39
private Vector JavaDoc data = null;
40     /** Creates a new instance of PropertiesTableModel */
41     public PropertiesTableModel(ResourceConfigData data) {
42         this.data = data.getProperties(); //NOI18N
43
}
44     
45     public int getColumnCount() {
46         return 2;
47     }
48     
49     public int getRowCount() {
50         return data.size();
51     }
52     
53     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
54         NameValuePair pair = (NameValuePair)data.elementAt(rowIndex);
55         if (columnIndex == 0)
56             return pair.getParamName();
57         else
58             return pair.getParamValue();
59     }
60     
61     public String JavaDoc getColumnName(int col) {
62         if (0 == col)
63             return bundle.getString("COL_HEADER_NAME"); //NOI18N
64
if (1 == col)
65             return bundle.getString("COL_HEADER_VALUE"); //NOI18N
66
throw new RuntimeException JavaDoc(bundle.getString("COL_HEADER_ERR_ERR_ERR")); //NOI18N
67
}
68     
69     public boolean isCellEditable(int row, int col) {
70        return true;
71     }
72     
73     public void setValueAt(Object JavaDoc value, int row, int col) {
74         if((row >=0) && (row < data.size())){
75             NameValuePair property = (NameValuePair)data.elementAt(row);
76             if (col == 0){
77                 if(! isNotUnique((String JavaDoc)value))
78                     property.setParamName((String JavaDoc)value);
79             }else if (col == 1)
80                 property.setParamValue((String JavaDoc)value);
81         }
82         fireTableDataChanged();
83     }
84
85     //Fix for bug#5026041 - Table should not accept duplicate prop names.
86
private boolean isNotUnique(String JavaDoc newVal){
87         for(int i=0; i<data.size()-1; i++){
88             NameValuePair pair = (NameValuePair)data.elementAt(i);
89             if(pair.getParamName().equals(newVal)){
90                 NotifyDescriptor d = new NotifyDescriptor.Message(bundle.getString("Err_DuplicateValue"), NotifyDescriptor.INFORMATION_MESSAGE);
91                 DialogDisplayer.getDefault().notify(d);
92                 return true;
93             }
94         }
95         return false;
96     }
97     
98     public void setData(ResourceConfigData data) {
99         this.data = data.getProperties();
100         fireTableDataChanged();
101     }
102     
103 //// private boolean changed = false;
104
}
105
Popular Tags