KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > client > subpanels > DynamicCredsPanel


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 2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.ui.client.subpanels;
21
22 import java.util.Set JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog;
25 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
26 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.CallbackHandler;
27 import org.netbeans.modules.xml.wsdl.model.Binding;
28
29 /**
30  *
31  * @author Martin Grebac
32  */

33
34 public class DynamicCredsPanel extends javax.swing.JPanel JavaDoc {
35     
36     private boolean inSync = false;
37
38     private Binding binding;
39     private boolean enable;
40     
41     private Project project;
42
43     /** Creates new form DynamicCredentials */
44     public DynamicCredsPanel(Binding b, Project project, boolean enable) {
45         this.binding = b;
46         this.enable = enable;
47         this.project = project;
48                
49         initComponents();
50         
51 // passwdHandlerField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
52
// passwdHandlerLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
53
// usernameHandlerField.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
54
// usernameHandlerLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
55
sync();
56     }
57     
58     public void sync() {
59         inSync = true;
60
61         String JavaDoc usernameCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER);
62         if (usernameCallback != null) {
63             setCallbackHandler(usernameCallback, CallbackHandler.USERNAME_CBHANDLER);
64         }
65         String JavaDoc passwdCallback = ProprietarySecurityPolicyModelHelper.getCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER);
66         if (passwdCallback != null) {
67             setCallbackHandler(passwdCallback, CallbackHandler.PASSWORD_CBHANDLER);
68         }
69         
70         enableDisable();
71         
72         inSync = false;
73     }
74     
75     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
76         if (inSync) return;
77             
78         if (source.equals(usernameHandlerField)) {
79             String JavaDoc classname = getCallbackHandler(CallbackHandler.USERNAME_CBHANDLER);
80             if ((classname != null) && (classname.length() == 0)) {
81                 classname = null;
82             }
83             ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER, classname, null, true);
84             return;
85         }
86
87         if (source.equals(passwdHandlerField)) {
88             String JavaDoc classname = getCallbackHandler(CallbackHandler.PASSWORD_CBHANDLER);
89             if ((classname != null) && (classname.length() == 0)) {
90                 classname = null;
91             }
92             ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER, classname, null, true);
93             return;
94         }
95         
96         enableDisable();
97     }
98
99     private void enableDisable() {
100         passwdBrowseButton.setEnabled(enable);
101         passwdHandlerField.setEnabled(enable);
102         passwdHandlerLabel.setEnabled(enable);
103         usernameBrowseButton.setEnabled(enable);
104         usernameHandlerField.setEnabled(enable);
105         usernameHandlerLabel.setEnabled(enable);
106     }
107     
108     private String JavaDoc getCallbackHandler(String JavaDoc type) {
109         if (CallbackHandler.USERNAME_CBHANDLER.equals(type)) return usernameHandlerField.getText();
110         if (CallbackHandler.PASSWORD_CBHANDLER.equals(type)) return passwdHandlerField.getText();
111         return null;
112     }
113
114     private void setCallbackHandler(String JavaDoc classname, String JavaDoc type) {
115         if (CallbackHandler.USERNAME_CBHANDLER.equals(type)) this.usernameHandlerField.setText(classname);
116         if (CallbackHandler.PASSWORD_CBHANDLER.equals(type)) this.passwdHandlerField.setText(classname);
117     }
118     
119     /** This method is called from within the constructor to
120      * initialize the form.
121      * WARNING: Do NOT modify this code. The content of this method is
122      * always regenerated by the Form Editor.
123      */

124     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
125
private void initComponents() {
126
127         usernameHandlerLabel = new javax.swing.JLabel JavaDoc();
128         usernameHandlerField = new javax.swing.JTextField JavaDoc();
129         passwdHandlerLabel = new javax.swing.JLabel JavaDoc();
130         passwdHandlerField = new javax.swing.JTextField JavaDoc();
131         usernameBrowseButton = new javax.swing.JButton JavaDoc();
132         passwdBrowseButton = new javax.swing.JButton JavaDoc();
133
134         org.openide.awt.Mnemonics.setLocalizedText(usernameHandlerLabel, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_UsernameCBHLabel")); // NOI18N
135

136         usernameHandlerField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
137             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
138                 usernameHandlerFieldKeyReleased(evt);
139             }
140         });
141
142         org.openide.awt.Mnemonics.setLocalizedText(passwdHandlerLabel, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_PasswordCBHLabel")); // NOI18N
143

144         passwdHandlerField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
145             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
146                 passwdHandlerFieldKeyReleased(evt);
147             }
148         });
149
150         org.openide.awt.Mnemonics.setLocalizedText(usernameBrowseButton, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_Username_Browse")); // NOI18N
151
usernameBrowseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
152             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
153                 usernameBrowseButtonActionPerformed(evt);
154             }
155         });
156
157         org.openide.awt.Mnemonics.setLocalizedText(passwdBrowseButton, org.openide.util.NbBundle.getMessage(DynamicCredsPanel.class, "LBL_Password_Browse")); // NOI18N
158
passwdBrowseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
159             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
160                 passwdBrowseButtonActionPerformed(evt);
161             }
162         });
163
164         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
165         this.setLayout(layout);
166         layout.setHorizontalGroup(
167             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
168             .add(layout.createSequentialGroup()
169                 .addContainerGap()
170                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
171                     .add(layout.createSequentialGroup()
172                         .add(passwdHandlerLabel)
173                         .add(13, 13, 13))
174                     .add(layout.createSequentialGroup()
175                         .add(usernameHandlerLabel)
176                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
177                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
178                     .add(usernameHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
179                     .add(passwdHandlerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
180                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
181                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
182                     .add(usernameBrowseButton)
183                     .add(passwdBrowseButton))
184                 .addContainerGap())
185         );
186         layout.setVerticalGroup(
187             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
188             .add(layout.createSequentialGroup()
189                 .addContainerGap()
190                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
191                     .add(usernameBrowseButton)
192                     .add(usernameHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
193                     .add(usernameHandlerLabel))
194                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
195                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
196                     .add(passwdBrowseButton)
197                     .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
198                         .add(passwdHandlerLabel)
199                         .add(passwdHandlerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
200                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
201         );
202     }// </editor-fold>//GEN-END:initComponents
203

204 private void passwdHandlerFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_passwdHandlerFieldKeyReleased
205
setValue(passwdHandlerField, null);
206 }//GEN-LAST:event_passwdHandlerFieldKeyReleased
207

208 private void usernameHandlerFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_usernameHandlerFieldKeyReleased
209
setValue(usernameHandlerField, null);
210 }//GEN-LAST:event_usernameHandlerFieldKeyReleased
211

212     private void passwdBrowseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_passwdBrowseButtonActionPerformed
213
if (project != null) {
214             ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); //NOI18N
215
classDialog.show();
216             if (classDialog.okButtonPressed()) {
217                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
218                 for (String JavaDoc selectedClass : selectedClasses) {
219                     setCallbackHandler(selectedClass, CallbackHandler.PASSWORD_CBHANDLER);
220                     ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.PASSWORD_CBHANDLER, selectedClass, null, true);
221                     break;
222                 }
223             }
224         }
225     }//GEN-LAST:event_passwdBrowseButtonActionPerformed
226

227     private void usernameBrowseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_usernameBrowseButtonActionPerformed
228
if (project != null) {
229             ClassDialog classDialog = new ClassDialog(project, "javax.security.auth.callback.CallbackHandler"); //NOI18N
230
classDialog.show();
231             if (classDialog.okButtonPressed()) {
232                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
233                 for (String JavaDoc selectedClass : selectedClasses) {
234                     setCallbackHandler(selectedClass, CallbackHandler.USERNAME_CBHANDLER);
235                     ProprietarySecurityPolicyModelHelper.setCallbackHandler(binding, CallbackHandler.USERNAME_CBHANDLER, selectedClass, null, true);
236                     break;
237                 }
238             }
239         }
240     }//GEN-LAST:event_usernameBrowseButtonActionPerformed
241

242     
243     // Variables declaration - do not modify//GEN-BEGIN:variables
244
private javax.swing.JButton JavaDoc passwdBrowseButton;
245     private javax.swing.JTextField JavaDoc passwdHandlerField;
246     private javax.swing.JLabel JavaDoc passwdHandlerLabel;
247     private javax.swing.JButton JavaDoc usernameBrowseButton;
248     private javax.swing.JTextField JavaDoc usernameHandlerField;
249     private javax.swing.JLabel JavaDoc usernameHandlerLabel;
250     // End of variables declaration//GEN-END:variables
251

252 }
253
Popular Tags