KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > 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
23 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards;
24
25 import java.util.Vector JavaDoc;
26 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair;
27
28 import org.openide.DialogDisplayer;
29 import org.openide.NotifyDescriptor;
30
31 /**
32  *
33  * Code reused from Appserver common API module
34  */

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