KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > SecurityRoleMappingCustomizer


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  * SecurityRoleMappingCustomizer.java
21  *
22  * Created on April 13, 2006, 12:18 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers;
26
27 import java.util.ResourceBundle JavaDoc;
28 import javax.swing.JTable JavaDoc;
29 import javax.swing.ListSelectionModel JavaDoc;
30 import javax.swing.event.ListSelectionEvent JavaDoc;
31 import javax.swing.event.ListSelectionListener JavaDoc;
32 import javax.swing.event.TableModelEvent JavaDoc;
33 import javax.swing.event.TableModelListener JavaDoc;
34
35 import org.netbeans.modules.j2ee.sun.share.PrincipalNameMapping;
36 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
37 import org.netbeans.modules.j2ee.sun.share.configbean.SecurityRoleMapping;
38 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.BaseCustomizer;
39
40
41 /**
42  *
43  * @author Peter Williams
44  */

45 public class SecurityRoleMappingCustomizer extends BaseCustomizer
46         implements ListSelectionListener JavaDoc, TableModelListener JavaDoc {
47
48     public static final ResourceBundle JavaDoc customizerBundle = ResourceBundle.getBundle(
49         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.Bundle"); // NOI18N
50

51     private SecurityRoleMapping theBean;
52
53     private PrincipalTableModel principalTableModel;
54     private GroupTableModel groupTableModel;
55
56     // true if AS 9.0+ fields are visible.
57
private boolean as90FeaturesVisible;
58
59     /**
60      * Creates new form SecurityRoleMappingCustomizer
61      */

62     public SecurityRoleMappingCustomizer() {
63         initComponents();
64         initUserComponents();
65     }
66
67     public SecurityRoleMapping getBean() {
68         return theBean;
69     }
70
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
79
80         jLblSecurityRoleName = new javax.swing.JLabel JavaDoc();
81         jTxtSecurityRoleName = new javax.swing.JTextField JavaDoc();
82         jLblAssignedPrincipals = new javax.swing.JLabel JavaDoc();
83         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
84         jTblPrincipals = new org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.FixedHeightJTable();
85         jBtnAddPrincipal = new javax.swing.JButton JavaDoc();
86         jBtnEditPrincipal = new javax.swing.JButton JavaDoc();
87         jBtnRemovePrincipal = new javax.swing.JButton JavaDoc();
88         jLblAssignedGroups = new javax.swing.JLabel JavaDoc();
89         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
90         jTblGroups = new org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.FixedHeightJTable();
91         jBtnAddGroup = new javax.swing.JButton JavaDoc();
92         jBtnEditGroup = new javax.swing.JButton JavaDoc();
93         jBtnRemoveGroup = new javax.swing.JButton JavaDoc();
94
95         setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         jLblSecurityRoleName.setLabelFor(jTxtSecurityRoleName);
98         jLblSecurityRoleName.setText("Security Role Name :");
99         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
100         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
101         add(jLblSecurityRoleName, gridBagConstraints);
102
103         jTxtSecurityRoleName.setEditable(false);
104         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
105         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
106         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
107         gridBagConstraints.weightx = 1.0;
108         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
109         add(jTxtSecurityRoleName, gridBagConstraints);
110         jTxtSecurityRoleName.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_SecurityRoleName"));
111         jTxtSecurityRoleName.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_SecurityRoleName"));
112
113         jLblAssignedPrincipals.setLabelFor(jTblPrincipals);
114         jLblAssignedPrincipals.setText(customizerBundle.getString("LBL_PrincipalsAssigned"));
115         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
117         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
119         add(jLblAssignedPrincipals, gridBagConstraints);
120
121         jScrollPane1.setViewportView(jTblPrincipals);
122         jTblPrincipals.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_PrincipalsAssigned"));
123         jTblPrincipals.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_PrincipalsAssigned"));
124
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridwidth = 2;
127         gridBagConstraints.gridheight = 3;
128         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
129         gridBagConstraints.weightx = 1.0;
130         gridBagConstraints.weighty = 1.0;
131         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
132         add(jScrollPane1, gridBagConstraints);
133
134         jBtnAddPrincipal.setText(customizerBundle.getString("LBL_AddPrincipal"));
135         jBtnAddPrincipal.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
136         jBtnAddPrincipal.addActionListener(new java.awt.event.ActionListener JavaDoc() {
137             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
138                 jBtnAddPrincipalActionPerformed(evt);
139             }
140         });
141
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
144         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
147         add(jBtnAddPrincipal, gridBagConstraints);
148         jBtnAddPrincipal.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_AddPrincipal"));
149         jBtnAddPrincipal.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_AddPrincipal"));
150
151         jBtnEditPrincipal.setText(customizerBundle.getString("LBL_EditPrincipal"));
152         jBtnEditPrincipal.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
153         jBtnEditPrincipal.addActionListener(new java.awt.event.ActionListener JavaDoc() {
154             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
155                 jBtnEditPrincipalActionPerformed(evt);
156             }
157         });
158
159         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
160         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
164         add(jBtnEditPrincipal, gridBagConstraints);
165         jBtnEditPrincipal.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_EditPrincipal"));
166         jBtnEditPrincipal.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_EditPrincipal"));
167
168         jBtnRemovePrincipal.setText(customizerBundle.getString("LBL_RemovePrincipals"));
169         jBtnRemovePrincipal.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
170         jBtnRemovePrincipal.addActionListener(new java.awt.event.ActionListener JavaDoc() {
171             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
172                 jBtnRemovePrincipalActionPerformed(evt);
173             }
174         });
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
181         add(jBtnRemovePrincipal, gridBagConstraints);
182         jBtnRemovePrincipal.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_RemovePrincipal"));
183         jBtnRemovePrincipal.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_RemovePrincipal"));
184
185         jLblAssignedGroups.setLabelFor(jTblGroups);
186         jLblAssignedGroups.setText(customizerBundle.getString("LBL_GroupsAssigned"));
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
189         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
191         add(jLblAssignedGroups, gridBagConstraints);
192
193         jScrollPane2.setViewportView(jTblGroups);
194         jTblGroups.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_GroupsAssigned"));
195         jTblGroups.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_GroupsAssigned"));
196
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridwidth = 3;
199         gridBagConstraints.gridheight = 3;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
201         gridBagConstraints.weightx = 1.0;
202         gridBagConstraints.weighty = 1.0;
203         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
204         add(jScrollPane2, gridBagConstraints);
205
206         jBtnAddGroup.setText(customizerBundle.getString("LBL_AddGroup"));
207         jBtnAddGroup.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
208         jBtnAddGroup.addActionListener(new java.awt.event.ActionListener JavaDoc() {
209             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
210                 jBtnAddGroupActionPerformed(evt);
211             }
212         });
213
214         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
215         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
216         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
217         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 5);
219         add(jBtnAddGroup, gridBagConstraints);
220         jBtnAddGroup.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_AddGroup"));
221         jBtnAddGroup.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_AddGroup"));
222
223         jBtnEditGroup.setText(customizerBundle.getString("LBL_EditGroup"));
224         jBtnEditGroup.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
225         jBtnEditGroup.addActionListener(new java.awt.event.ActionListener JavaDoc() {
226             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
227                 jBtnEditGroupActionPerformed(evt);
228             }
229         });
230
231         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
232         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
233         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
236         add(jBtnEditGroup, gridBagConstraints);
237         jBtnEditGroup.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_EditGroup"));
238         jBtnEditGroup.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_EditGroup"));
239
240         jBtnRemoveGroup.setText(customizerBundle.getString("LBL_RemoveGroups"));
241         jBtnRemoveGroup.setMargin(new java.awt.Insets JavaDoc(2, 12, 2, 12));
242         jBtnRemoveGroup.addActionListener(new java.awt.event.ActionListener JavaDoc() {
243             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
244                 jBtnRemoveGroupActionPerformed(evt);
245             }
246         });
247
248         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
249         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
250         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
253         add(jBtnRemoveGroup, gridBagConstraints);
254         jBtnRemoveGroup.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_RemoveGroup"));
255         jBtnRemoveGroup.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_RemoveGroup"));
256
257     }// </editor-fold>//GEN-END:initComponents
258

259     private void jBtnRemoveGroupActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnRemoveGroupActionPerformed
260
handleRemoveAction(jTblGroups);
261     }//GEN-LAST:event_jBtnRemoveGroupActionPerformed
262

263     private void jBtnEditGroupActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnEditGroupActionPerformed
264
handleEditGroupAction();
265     }//GEN-LAST:event_jBtnEditGroupActionPerformed
266

267     private void jBtnAddGroupActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnAddGroupActionPerformed
268
handleAddGroupAction();
269     }//GEN-LAST:event_jBtnAddGroupActionPerformed
270

271     private void jBtnRemovePrincipalActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnRemovePrincipalActionPerformed
272
handleRemoveAction(jTblPrincipals);
273     }//GEN-LAST:event_jBtnRemovePrincipalActionPerformed
274

275     private void jBtnEditPrincipalActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnEditPrincipalActionPerformed
276
handleEditPrincipalAction();
277     }//GEN-LAST:event_jBtnEditPrincipalActionPerformed
278

279     private void jBtnAddPrincipalActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnAddPrincipalActionPerformed
280
handleAddPrincipalAction();
281     }//GEN-LAST:event_jBtnAddPrincipalActionPerformed
282

283
284     // Variables declaration - do not modify//GEN-BEGIN:variables
285
private javax.swing.JButton JavaDoc jBtnAddGroup;
286     private javax.swing.JButton JavaDoc jBtnAddPrincipal;
287     private javax.swing.JButton JavaDoc jBtnEditGroup;
288     private javax.swing.JButton JavaDoc jBtnEditPrincipal;
289     private javax.swing.JButton JavaDoc jBtnRemoveGroup;
290     private javax.swing.JButton JavaDoc jBtnRemovePrincipal;
291     private javax.swing.JLabel JavaDoc jLblAssignedGroups;
292     private javax.swing.JLabel JavaDoc jLblAssignedPrincipals;
293     private javax.swing.JLabel JavaDoc jLblSecurityRoleName;
294     private javax.swing.JScrollPane JavaDoc jScrollPane1;
295     private javax.swing.JScrollPane JavaDoc jScrollPane2;
296     private org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.FixedHeightJTable jTblGroups;
297     private org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.FixedHeightJTable jTblPrincipals;
298     private javax.swing.JTextField JavaDoc jTxtSecurityRoleName;
299     // End of variables declaration//GEN-END:variables
300

301     private void initUserComponents() {
302         as90FeaturesVisible = true;
303
304         // Add title panel
305
addTitlePanel(customizerBundle.getString("TITLE_SecurityRoleMapping")); // NOI18N
306
getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_SecurityRoleMapping")); // NOI18N
307
getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_SecurityRoleMapping")); // NOI18N
308

309         // Add error panel
310
addErrorPanel();
311     }
312
313     protected void initFields() {
314         jTxtSecurityRoleName.setText(theBean.getRoleName());
315
316         if(ASDDVersion.SUN_APPSERVER_9_0.compareTo(theBean.getAppServerVersion()) <= 0) {
317             as90FeaturesVisible = true;
318         } else {
319             as90FeaturesVisible = false;
320         }
321
322         principalTableModel = new PrincipalTableModel(theBean.getPrincipalNames(), as90FeaturesVisible ? 2 : 1);
323         jTblPrincipals.setModel(principalTableModel);
324
325         groupTableModel = new GroupTableModel(theBean.getGroupNames());
326         jTblGroups.setModel(groupTableModel);
327
328         enablePrincipalButtons();
329         enableGroupButtons();
330     }
331     
332     /** Popup a dialog that lets the user add a new principal to this mapping.
333      * The new name will not be allowed to match any existing name. The
334      * new item will be preselected afterwards. The new name will either come
335      * from the existing master list or will be a new name and automatically added
336      * to the master list.
337      */

338     private void handleAddPrincipalAction() {
339         ListSelectionModel JavaDoc selectionModel = jTblPrincipals.getSelectionModel();
340         try {
341             selectionModel.setValueIsAdjusting(true);
342             SecurityAddPrincipalPanel.addPrincipalName(this, principalTableModel, theBean.getAppServerVersion());
343
344             int index = principalTableModel.getRowCount()-1;
345             selectionModel.setSelectionInterval(index, index);
346         } finally {
347             selectionModel.setValueIsAdjusting(false);
348         }
349     }
350     
351     /** Popup a dialog that lets the user edit the selected entry. The changed
352      * name will not be allowed to match any existing name. The item will
353      * remain selected once the action is completed.
354      */

355     private void handleEditPrincipalAction() {
356         int [] selectedIndices = jTblPrincipals.getSelectedRows();
357         if(selectedIndices.length > 0) {
358             ListSelectionModel JavaDoc selectionModel = jTblPrincipals.getSelectionModel();
359             try {
360                 PrincipalNameMapping entry = principalTableModel.getElementAt(selectedIndices[0]);
361                 SecurityEditPrincipalPanel.editPrincipalName(this, entry, principalTableModel, theBean.getAppServerVersion());
362                 selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
363             } finally {
364                 selectionModel.setValueIsAdjusting(false);
365             }
366         }
367     }
368     
369     /** Popup a dialog that lets the user add a new entry to the specifed master
370      * list. The new name will not be allowed to match any existing name. The
371      * new item will be preselected afterwards. The new name will either come
372      * from the existing master list or will be a new name and automatically added
373      * to the master list.
374      */

375     private void handleAddGroupAction() {
376         ListSelectionModel JavaDoc selectionModel = jTblGroups.getSelectionModel();
377         try {
378             selectionModel.setValueIsAdjusting(true);
379             SecurityAddGroupPanel.addGroupName(this, groupTableModel);
380
381             int index = groupTableModel.getRowCount()-1;
382             selectionModel.setSelectionInterval(index, index);
383         } finally {
384             selectionModel.setValueIsAdjusting(false);
385         }
386         
387     }
388
389     /** Popup a dialog that lets the user edit the selected entry. The changed
390      * name will not be allowed to match any existing name. The item will
391      * remain selected once the action is completed.
392      */

393     private void handleEditGroupAction() {
394         int [] selectedIndices = jTblGroups.getSelectedRows();
395         if(selectedIndices.length > 0) {
396             ListSelectionModel JavaDoc selectionModel = jTblGroups.getSelectionModel();
397             try {
398                 String JavaDoc entry = groupTableModel.getElementAt(selectedIndices[0]);
399                 SecurityEditGroupPanel.editGroupName(this, entry, groupTableModel);
400                 selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
401             } finally {
402                 selectionModel.setValueIsAdjusting(false);
403             }
404         }
405     }
406     
407     /** Remove all selected items from the specified table.
408      */

409     private void handleRemoveAction(JTable JavaDoc theTable) {
410         int [] selectedIndices = theTable.getSelectedRows();
411         if(selectedIndices.length > 0) {
412             ListSelectionModel JavaDoc selectionModel = theTable.getSelectionModel();
413             try {
414                 SecurityMappingTableModel theModel = (SecurityMappingTableModel) theTable.getModel();
415                 selectionModel.setValueIsAdjusting(true);
416                 theModel.removeElements(selectedIndices);
417                 int numElements = theTable.getModel().getRowCount();
418                 if(numElements > 0) {
419                     int newSelectedIndex = selectedIndices[0];
420                     if(newSelectedIndex >= numElements) {
421                         newSelectedIndex = numElements-1;
422                     }
423                     selectionModel.setSelectionInterval(newSelectedIndex, newSelectedIndex);
424                 } else {
425                     selectionModel.clearSelection();
426                 }
427             } finally {
428                 selectionModel.setValueIsAdjusting(false);
429             }
430         }
431     }
432
433     /** Enable the edit and remove buttons for the principal table based on how
434      * many rows are selected.
435      * Add is available always (thus no change here).
436      * Edit is available when exactly one item is selected.
437      * Remove is available when at least one item is selected.
438      */

439     private void enablePrincipalButtons() {
440         int numSelectedRows = jTblPrincipals.getSelectedRowCount();
441         jBtnEditPrincipal.setEnabled(numSelectedRows == 1);
442         jBtnRemovePrincipal.setEnabled(numSelectedRows > 0);
443     }
444
445     /** Enable the edit and remove buttons for the group table based on how
446      * many rows are selected.
447      * Add is available always (thus no change here).
448      * Edit is available when exactly one item is selected.
449      * Remove is available when at least one item is selected.
450      */

451     private void enableGroupButtons() {
452         int numSelectedRows = jTblGroups.getSelectedRowCount();
453         jBtnEditGroup.setEnabled(numSelectedRows == 1);
454         jBtnRemoveGroup.setEnabled(numSelectedRows > 0);
455     }
456
457     /** Adds selection listeners to the lists for proper button enabling.
458      */

459     protected void addListeners() {
460         super.addListeners();
461
462         jTblPrincipals.getSelectionModel().addListSelectionListener(this);
463         principalTableModel.addTableModelListener(this);
464         jTblGroups.getSelectionModel().addListSelectionListener(this);
465         groupTableModel.addTableModelListener(this);
466     }
467
468     /** Removes previously added selection listeners.
469      */

470     protected void removeListeners() {
471         super.removeListeners();
472         
473         groupTableModel.removeTableModelListener(this);
474         jTblGroups.getSelectionModel().removeListSelectionListener(this);
475         principalTableModel.removeTableModelListener(this);
476         jTblPrincipals.getSelectionModel().removeListSelectionListener(this);
477     }
478
479     protected boolean setBean(Object JavaDoc bean) {
480         boolean result = super.setBean(bean);
481
482         if(bean instanceof SecurityRoleMapping) {
483             theBean = (SecurityRoleMapping) bean;
484             result = true;
485         } else {
486             // if bean is not a SecurityRoleMapping, then it shouldn't have passed Base either.
487
assert (result == false) :
488                 "SecurityRoleMappingCustomizer was passed wrong bean type in setBean(Object bean)"; // NOI18N
489

490             theBean = null;
491             result = false;
492         }
493
494         return result;
495     }
496
497     public String JavaDoc getHelpId() {
498         return "AS_CFG_SecurityRoleMapping"; // NOI18N
499
}
500
501     /**
502      * Implementation of the ListSelectionListener interface
503      */

504     public void valueChanged(ListSelectionEvent JavaDoc listSelectionEvent) {
505         if(!listSelectionEvent.getValueIsAdjusting()) {
506             Object JavaDoc source = listSelectionEvent.getSource();
507             if(source instanceof ListSelectionModel JavaDoc) {
508                 ListSelectionModel JavaDoc selectionModel = (ListSelectionModel JavaDoc) source;
509                 if(jTblPrincipals.getSelectionModel() == selectionModel) {
510                     enablePrincipalButtons();
511                 } else if(jTblGroups.getSelectionModel() == selectionModel) {
512                     enableGroupButtons();
513                 }
514             }
515         }
516     }
517
518     /**
519      * Implementation of the TableModelListener interface
520      */

521     public void tableChanged(TableModelEvent JavaDoc tableModelEvent) {
522         Object JavaDoc source = tableModelEvent.getSource();
523         theBean.setDirty();
524     }
525     
526 // public void partitionStateChanged(ErrorMessageDB.PartitionState oldState, ErrorMessageDB.PartitionState newState) {
527
// if(newState.getPartition() == getPartition()) {
528
// showErrors();
529
// }
530
//
531
// if(oldState.hasMessages() != newState.hasMessages()) {
532
// securityTabbedPanel.setIconAt(newState.getPartition().getTabIndex(), newState.hasMessages() ? panelErrorIcon : null);
533
// }
534
// }
535

536     /** Retrieve the partition that should be associated with the current
537      * selected tab.
538      *
539      * @return ValidationError.Partition
540      */

541 // public ValidationError.Partition getPartition() {
542
// switch(securityTabbedPanel.getSelectedIndex()) {
543
// case 1:
544
// return ValidationError.PARTITION_SECURITY_MASTER;
545
// default:
546
// return ValidationError.PARTITION_SECURITY_ASSIGN;
547
// }
548
// }
549
}
550
Popular Tags