KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > ui > service > subpanels > STSConfigServicePanel


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

19
20 package org.netbeans.modules.websvc.wsitconf.ui.service.subpanels;
21
22 import java.text.NumberFormat JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.JCheckBox JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.text.DefaultFormatterFactory JavaDoc;
27 import javax.swing.text.NumberFormatter JavaDoc;
28 import org.jdesktop.layout.GroupLayout;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.modules.websvc.wsitconf.ui.ClassDialog;
31 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProprietarySecurityPolicyModelHelper;
32 import org.netbeans.modules.websvc.wsitmodelext.security.proprietary.service.STSConfiguration;
33 import org.netbeans.modules.xml.multiview.ui.SectionView;
34 import org.netbeans.modules.xml.wsdl.model.Binding;
35 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
36
37 /**
38  *
39  * @author Martin Grebac
40  */

41 public class STSConfigServicePanel extends JPanel JavaDoc {
42     
43     private ServiceProvidersTablePanel panel;
44
45     private WSDLModel model;
46     private Binding binding;
47     private SectionView view;
48     
49     private Project project;
50
51     private boolean inSync = false;
52     
53     private DefaultFormatterFactory JavaDoc lifeTimeDff = null;
54     
55     /**
56      * Creates new form STSConfigServicePanel
57      */

58     public STSConfigServicePanel(WSDLModel model, Project p, Binding binding) {
59         this.model = model;
60         this.project = p;
61         this.binding = binding;
62
63         lifeTimeDff = new DefaultFormatterFactory JavaDoc();
64         NumberFormat JavaDoc lifetimeFormat = NumberFormat.getIntegerInstance();
65         lifetimeFormat.setGroupingUsed(false);
66         lifetimeFormat.setParseIntegerOnly(true);
67         lifetimeFormat.setMaximumFractionDigits(0);
68         NumberFormatter JavaDoc lifetimeFormatter = new NumberFormatter JavaDoc(lifetimeFormat);
69         lifetimeFormatter.setCommitsOnValidEdit(true);
70         lifetimeFormatter.setMinimum(0);
71         lifeTimeDff.setDefaultFormatter(lifetimeFormatter);
72
73         initComponents();
74
75         inSync = true;
76         ServiceProvidersTablePanel.ServiceProvidersTableModel tablemodel = new ServiceProvidersTablePanel.ServiceProvidersTableModel();
77         this.remove(serviceProvidersPanel);
78         
79         STSConfiguration stsConfig = ProprietarySecurityPolicyModelHelper.getSTSConfiguration(binding);
80         if (stsConfig == null) {
81             stsConfig = ProprietarySecurityPolicyModelHelper.createSTSConfiguration(binding);
82         }
83         serviceProvidersPanel = new ServiceProvidersTablePanel(tablemodel, model, stsConfig);
84         ((ServiceProvidersTablePanel)serviceProvidersPanel).populateModel();
85         inSync = false;
86
87         sync();
88         
89     }
90
91     private void sync() {
92         inSync = true;
93
94         String JavaDoc lifeTime = ProprietarySecurityPolicyModelHelper.getSTSLifeTime(binding);
95         if (lifeTime == null) { // no setup exists yet - set the default
96
setLifeTime(ProprietarySecurityPolicyModelHelper.DEFAULT_LIFETIME);
97             ProprietarySecurityPolicyModelHelper.setSTSLifeTime(binding, ProprietarySecurityPolicyModelHelper.DEFAULT_LIFETIME);
98         } else {
99             setLifeTime(lifeTime);
100         }
101
102         boolean encryptKey = ProprietarySecurityPolicyModelHelper.getSTSEncryptKey(binding);
103         setChBox(encryptKeyChBox, encryptKey);
104
105         boolean encryptToken = ProprietarySecurityPolicyModelHelper.getSTSEncryptToken(binding);
106         setChBox(encryptTokenChBox, encryptToken);
107         
108         String JavaDoc issuer = ProprietarySecurityPolicyModelHelper.getSTSIssuer(binding);
109         if (issuer != null) {
110             setIssuer(issuer);
111         }
112         
113         String JavaDoc cclass = ProprietarySecurityPolicyModelHelper.getSTSContractClass(binding);
114         if (cclass == null) { // no setup exists yet - set the default
115
setContractClass(ProprietarySecurityPolicyModelHelper.DEFAULT_CONTRACT_CLASS);
116             ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, ProprietarySecurityPolicyModelHelper.DEFAULT_CONTRACT_CLASS);
117         } else {
118             setContractClass(cclass);
119         }
120         
121         refreshPanels();
122         
123         inSync = false;
124     }
125     
126     private String JavaDoc getLifeTime() {
127         return this.lifeTimeTextField.getText();
128     }
129
130     private void setLifeTime(String JavaDoc time) {
131         this.lifeTimeTextField.setText(time);
132     }
133
134     private String JavaDoc getIssuer() {
135         return this.issuerField.getText();
136     }
137
138     private void setIssuer(String JavaDoc issuer) {
139         this.issuerField.setText(issuer);
140     }
141     
142     private void setChBox(JCheckBox JavaDoc chBox, Boolean JavaDoc enable) {
143         if (enable == null) {
144             chBox.setSelected(false);
145         } else {
146             chBox.setSelected(enable);
147         }
148     }
149     
150     private void setContractClass(String JavaDoc classname) {
151         this.contractTextField.setText(classname);
152     }
153
154     private String JavaDoc getContractClass() {
155         return contractTextField.getText();
156     }
157    
158     private void refreshPanels() {
159         updateLayout();
160     }
161     
162     private void updateLayout() {
163         GroupLayout layout = (GroupLayout)this.getLayout();
164         this.setLayout(layout);
165         layout.setHorizontalGroup(
166             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167             .add(layout.createSequentialGroup()
168                 .addContainerGap()
169                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
170                     .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
171                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
172                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
173                             .add(layout.createSequentialGroup()
174                                 .add(2, 2, 2)
175                                 .add(lifeTimeLabel))
176                             .add(contractLabel)
177                             .add(issuerLabel))
178                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
179                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
180                             .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
181                             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
182                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
183                                 .add(contractTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
184                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
185                                 .add(contractButton))
186                             .add(issuerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
187                         .add(10, 10, 10))
188                     .add(layout.createSequentialGroup()
189                         .add(encryptKeyChBox)
190                         .addContainerGap(493, Short.MAX_VALUE))
191                     .add(layout.createSequentialGroup()
192                         .add(encryptTokenChBox)
193                         .addContainerGap(483, Short.MAX_VALUE))))
194         );
195         layout.setVerticalGroup(
196             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
197             .add(layout.createSequentialGroup()
198                 .addContainerGap()
199                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
200                     .add(issuerLabel)
201                     .add(issuerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
202                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
203                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
204                     .add(contractLabel)
205                     .add(contractButton)
206                     .add(contractTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
207                 .add(8, 8, 8)
208                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
209                     .add(lifeTimeLabel)
210                     .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
211                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
212                 .add(encryptKeyChBox)
213                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
214                 .add(encryptTokenChBox)
215                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
216                 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
217                 .addContainerGap())
218         );
219     }
220     
221     /** This method is called from within the constructor to
222      * initialize the form.
223      * WARNING: Do NOT modify this code. The content of this method is
224      * always regenerated by the Form Editor.
225      */

226     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
227
private void initComponents() {
228
229         serviceProvidersPanel = new javax.swing.JPanel JavaDoc();
230         lifeTimeLabel = new javax.swing.JLabel JavaDoc();
231         contractLabel = new javax.swing.JLabel JavaDoc();
232         contractTextField = new javax.swing.JTextField JavaDoc();
233         contractButton = new javax.swing.JButton JavaDoc();
234         issuerLabel = new javax.swing.JLabel JavaDoc();
235         issuerField = new javax.swing.JTextField JavaDoc();
236         encryptKeyChBox = new javax.swing.JCheckBox JavaDoc();
237         encryptTokenChBox = new javax.swing.JCheckBox JavaDoc();
238         lifeTimeTextField = new javax.swing.JFormattedTextField JavaDoc();
239
240         serviceProvidersPanel.setAutoscrolls(true);
241
242         org.jdesktop.layout.GroupLayout serviceProvidersPanelLayout = new org.jdesktop.layout.GroupLayout(serviceProvidersPanel);
243         serviceProvidersPanel.setLayout(serviceProvidersPanelLayout);
244         serviceProvidersPanelLayout.setHorizontalGroup(
245             serviceProvidersPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
246             .add(0, 648, Short.MAX_VALUE)
247         );
248         serviceProvidersPanelLayout.setVerticalGroup(
249             serviceProvidersPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
250             .add(0, 90, Short.MAX_VALUE)
251         );
252
253         lifeTimeLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Lifetime")); // NOI18N
254

255         contractLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Contract")); // NOI18N
256

257         contractTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
258             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
259                 contractTextFieldKeyReleased(evt);
260             }
261         });
262
263         contractButton.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Browse")); // NOI18N
264
contractButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
265             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
266                 contractButtonActionPerformed(evt);
267             }
268         });
269
270         issuerLabel.setText(org.openide.util.NbBundle.getMessage(STSConfigServicePanel.class, "LBL_STSConfig_Issuer")); // NOI18N
271

272         issuerField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
273             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
274                 issuerFieldKeyReleased(evt);
275             }
276         });
277
278         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/wsitconf/ui/service/subpanels/Bundle"); // NOI18N
279
encryptKeyChBox.setText(bundle.getString("LBL_STSConfig_EncryptKey")); // NOI18N
280
encryptKeyChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
281         encryptKeyChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
282         encryptKeyChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
283             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
284                 encryptKeyChBoxActionPerformed(evt);
285             }
286         });
287
288         encryptTokenChBox.setText(bundle.getString("LBL_STSConfig_EncryptToken")); // NOI18N
289
encryptTokenChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
290         encryptTokenChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
291         encryptTokenChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
292             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
293                 encryptTokenChBoxActionPerformed(evt);
294             }
295         });
296
297         lifeTimeTextField.setFormatterFactory(lifeTimeDff);
298         lifeTimeTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
299             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
300                 lifeTimeTextFieldKeyReleased(evt);
301             }
302         });
303
304         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
305         this.setLayout(layout);
306         layout.setHorizontalGroup(
307             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
308             .add(layout.createSequentialGroup()
309                 .addContainerGap()
310                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
311                     .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
312                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
313                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
314                             .add(layout.createSequentialGroup()
315                                 .add(2, 2, 2)
316                                 .add(lifeTimeLabel))
317                             .add(contractLabel)
318                             .add(issuerLabel))
319                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
320                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
321                             .add(issuerField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
322                             .add(layout.createSequentialGroup()
323                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
324                                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
325                                     .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
326                                     .add(layout.createSequentialGroup()
327                                         .add(contractTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
328                                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
329                                         .add(contractButton)))))
330                         .add(10, 10, 10))
331                     .add(layout.createSequentialGroup()
332                         .add(encryptKeyChBox)
333                         .addContainerGap(523, Short.MAX_VALUE))
334                     .add(layout.createSequentialGroup()
335                         .add(encryptTokenChBox)
336                         .addContainerGap(509, Short.MAX_VALUE))))
337         );
338         layout.setVerticalGroup(
339             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
340             .add(layout.createSequentialGroup()
341                 .addContainerGap()
342                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
343                     .add(issuerLabel)
344                     .add(issuerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
345                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
346                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
347                     .add(contractLabel)
348                     .add(contractButton)
349                     .add(contractTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
350                 .add(8, 8, 8)
351                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
352                     .add(lifeTimeLabel)
353                     .add(lifeTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
354                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
355                 .add(encryptKeyChBox)
356                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
357                 .add(encryptTokenChBox)
358                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
359                 .add(serviceProvidersPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
360                 .addContainerGap())
361         );
362     }// </editor-fold>//GEN-END:initComponents
363

364     private void lifeTimeTextFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_lifeTimeTextFieldKeyReleased
365
Object JavaDoc o = lifeTimeTextField.getValue();
366         if (o instanceof Integer JavaDoc) {
367             String JavaDoc ltime = o.toString();
368             ProprietarySecurityPolicyModelHelper.setSTSLifeTime(binding, ltime);
369         }
370 }//GEN-LAST:event_lifeTimeTextFieldKeyReleased
371

372     private void encryptTokenChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_encryptTokenChBoxActionPerformed
373
ProprietarySecurityPolicyModelHelper.setSTSEncryptKey(binding, encryptTokenChBox.isSelected());
374     }//GEN-LAST:event_encryptTokenChBoxActionPerformed
375

376     private void encryptKeyChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_encryptKeyChBoxActionPerformed
377
ProprietarySecurityPolicyModelHelper.setSTSEncryptToken(binding, encryptKeyChBox.isSelected());
378     }//GEN-LAST:event_encryptKeyChBoxActionPerformed
379

380     private void contractTextFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_contractTextFieldKeyReleased
381
String JavaDoc c = contractTextField.getText();
382         ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, c);
383     }//GEN-LAST:event_contractTextFieldKeyReleased
384

385     private void issuerFieldKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_issuerFieldKeyReleased
386
String JavaDoc issuer = issuerField.getText();
387         ProprietarySecurityPolicyModelHelper.setSTSIssuer(binding, issuer);
388     }//GEN-LAST:event_issuerFieldKeyReleased
389

390     private void contractButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_contractButtonActionPerformed
391
if (project != null) {
392             ClassDialog classDialog = new ClassDialog(project, "com.sun.xml.ws.trust.WSTrustContract"); //NOI18N
393
classDialog.show();
394             if (classDialog.okButtonPressed()) {
395                 Set JavaDoc<String JavaDoc> selectedClasses = classDialog.getSelectedClasses();
396                 for (String JavaDoc selectedClass : selectedClasses) {
397                     setContractClass(selectedClass);
398                     ProprietarySecurityPolicyModelHelper.setSTSContractClass(binding, selectedClass);
399                     break;
400                 }
401             }
402         }
403     }//GEN-LAST:event_contractButtonActionPerformed
404

405     
406     // Variables declaration - do not modify//GEN-BEGIN:variables
407
private javax.swing.JButton JavaDoc contractButton;
408     private javax.swing.JLabel JavaDoc contractLabel;
409     private javax.swing.JTextField JavaDoc contractTextField;
410     private javax.swing.JCheckBox JavaDoc encryptKeyChBox;
411     private javax.swing.JCheckBox JavaDoc encryptTokenChBox;
412     private javax.swing.JTextField JavaDoc issuerField;
413     private javax.swing.JLabel JavaDoc issuerLabel;
414     private javax.swing.JLabel JavaDoc lifeTimeLabel;
415     private javax.swing.JFormattedTextField JavaDoc lifeTimeTextField;
416     private javax.swing.JPanel JavaDoc serviceProvidersPanel;
417     // End of variables declaration//GEN-END:variables
418

419 }
420
Popular Tags