KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > ResourceReferencesTableModel


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 package org.netbeans.modules.j2ee.ddloaders.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
23 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
24 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
25 import org.openide.NotifyDescriptor;
26 import org.openide.DialogDisplayer;
27
28 import javax.swing.table.TableCellEditor JavaDoc;
29
30 /**
31  * @author pfiala
32  */

33 public class ResourceReferencesTableModel extends InnerTableModel {
34
35     private Ejb ejb;
36     private static final int COLUMN_AUTHENTICATION = 2;
37     private static final int COLUMN_SHAREABLE = 3;
38     private static final String JavaDoc[] COLUMN_NAMES = {Utils.getBundleMessage("LBL_Name"),
39                                                   Utils.getBundleMessage("LBL_ResourceType"),
40                                                   Utils.getBundleMessage("LBL_Authentication"),
41                                                   Utils.getBundleMessage("LBL_Shareable"),
42                                                   Utils.getBundleMessage("LBL_Description")};
43     private static final int[] COLUMN_WIDTHS = new int[]{100, 200, 120, 80, 150};
44
45     public ResourceReferencesTableModel(XmlMultiViewDataSynchronizer synchronizer, Ejb ejb) {
46         super(synchronizer, COLUMN_NAMES, COLUMN_WIDTHS);
47         this.ejb = ejb;
48     }
49
50     public void setValueAt(Object JavaDoc value, int rowIndex, int columnIndex) {
51         ResourceRef resourceRef = ejb.getResourceRef(rowIndex);
52         switch (columnIndex) {
53             case 0:
54                 resourceRef.setResRefName((String JavaDoc) value);
55                 break;
56             case 1:
57                 resourceRef.setResType((String JavaDoc) value);
58                 break;
59             case 2:
60                 resourceRef.setResAuth((String JavaDoc) value);
61                 break;
62             case 3:
63                 resourceRef.setResSharingScope((String JavaDoc) value);
64                 break;
65             case 4:
66                 resourceRef.setDescription((String JavaDoc) value);
67                 break;
68         }
69         modelUpdatedFromUI();
70         fireTableCellUpdated(rowIndex, columnIndex);
71     }
72
73     public int getRowCount() {
74         return ejb.getResourceRef().length;
75     }
76
77     public Object JavaDoc getValueAt(int rowIndex, int columnIndex) {
78         ResourceRef resourceRef = ejb.getResourceRef(rowIndex);
79         switch (columnIndex) {
80             case 0:
81                 return resourceRef.getResRefName();
82             case 1:
83                 return resourceRef.getResType();
84             case 2:
85                 return resourceRef.getResAuth();
86             case 3:
87                 return resourceRef.getResSharingScope();
88             case 4:
89                 return resourceRef.getDefaultDescription();
90         }
91         return null;
92     }
93
94     public int addRow() {
95         String JavaDoc text = Utils.getBundleMessage("LBL_ReferenceName_");
96         String JavaDoc title = Utils.getBundleMessage("LBL_AddResourceReference");
97         final NotifyDescriptor.InputLine inputLine = new NotifyDescriptor.InputLine(text, title);
98         DialogDisplayer.getDefault().notify(inputLine);
99         final String JavaDoc name = inputLine.getInputText();
100         return addRow(name);
101     }
102
103     public int addRow(String JavaDoc name) {
104         if (name != null && name.trim().length() > 0) {
105             ResourceRef resourceRef = ejb.newResourceRef();
106             resourceRef.setResRefName(name);
107             ejb.addResourceRef(resourceRef);
108             modelUpdatedFromUI();
109         }
110         int row = getRowCount() - 1;
111         return row;
112     }
113     
114     public void removeRow(int row) {
115         ejb.removeResourceRef(ejb.getResourceRef(row));
116         modelUpdatedFromUI();
117     }
118
119     public boolean isCellEditable(int rowIndex, int columnIndex) {
120         return columnIndex != 0;
121     }
122
123     public TableCellEditor JavaDoc getTableCellEditor(int column) {
124         if (column == COLUMN_AUTHENTICATION) {
125             return createComboBoxCellEditor(new Object JavaDoc[]{"Application", "Container"});
126         } else if (column == COLUMN_SHAREABLE) {
127             return createComboBoxCellEditor(new Object JavaDoc[]{"Shareable", "Unshareable"});
128         } else {
129             return null;
130         }
131     }
132 }
133
Popular Tags