KickJava   Java API By Example, From Geeks To Geeks.

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


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;
21
22 import java.awt.Dialog JavaDoc;
23 import javax.swing.undo.UndoManager JavaDoc;
24 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants;
25 import org.netbeans.modules.websvc.wsitconf.ui.service.subpanels.TargetsPanel;
26 import org.netbeans.modules.websvc.wsitconf.util.UndoCounter;
27 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.ProfilesModelHelper;
28 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityPolicyModelHelper;
29 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.SecurityTokensModelHelper;
30 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel;
31 import org.netbeans.modules.xml.multiview.ui.SectionView;
32 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
33 import org.netbeans.modules.xml.wsdl.model.Binding;
34 import org.netbeans.modules.xml.wsdl.model.BindingInput;
35 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
36 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
37 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
38 import org.netbeans.modules.xml.xam.ComponentEvent;
39 import org.netbeans.modules.xml.xam.ComponentListener;
40 import org.openide.DialogDescriptor;
41 import org.openide.DialogDisplayer;
42 import org.openide.nodes.Node;
43
44 import javax.swing.*;
45 import org.openide.util.NbBundle;
46
47 /**
48  *
49  * @author Martin Grebac
50  */

51 public class InputPanel extends SectionInnerPanel {
52
53     private WSDLModel model;
54     private Node node;
55     private BindingInput input;
56     private BindingOperation operation;
57     private Binding binding;
58     private UndoManager JavaDoc undoManager;
59     private boolean inSync = false;
60
61     private boolean signed = false;
62     private boolean endorsing = false;
63     
64     public InputPanel(SectionView view, Node node, BindingInput input, UndoManager JavaDoc undoManager) {
65         super(view);
66         this.model = input.getModel();
67         this.node = node;
68         this.input = input;
69         this.operation = (BindingOperation)input.getParent();
70         this.binding = (Binding)input.getParent().getParent();
71         this.undoManager = undoManager;
72         initComponents();
73         
74         tokenComboLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
75         tokenCombo.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
76         signedChBox.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
77         endorsingChBox.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
78
79         addImmediateModifier(tokenCombo);
80         addImmediateModifier(signedChBox);
81         addImmediateModifier(endorsingChBox);
82
83         inSync = true;
84         tokenCombo.removeAllItems();
85         tokenCombo.addItem(ComboConstants.NONE);
86         tokenCombo.addItem(ComboConstants.USERNAME);
87         tokenCombo.addItem(ComboConstants.X509);
88         tokenCombo.addItem(ComboConstants.SAML);
89         tokenCombo.addItem(ComboConstants.ISSUED);
90 // tokenCombo.addItem(ComboConstants.KERBEROS);
91
inSync = false;
92
93         sync();
94
95         model.addComponentListener(new ComponentListener() {
96             public void valueChanged(ComponentEvent evt) {
97                 sync();
98             }
99             public void childrenAdded(ComponentEvent evt) {
100                 sync();
101             }
102             public void childrenDeleted(ComponentEvent evt) {
103                 sync();
104             }
105         });
106         
107     }
108
109     private void sync() {
110         inSync = true;
111
112         WSDLComponent token = null;
113         
114         WSDLComponent t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SUPPORTING);
115         if (t != null) {
116             token = t;
117             signed = false;
118             endorsing = false;
119         }
120         t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SIGNED_SUPPORTING);
121         if (t != null) {
122             token = t;
123             signed = true;
124             endorsing = false;
125         }
126         t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.ENDORSING);
127         if (t != null) {
128             token = t;
129             signed = false;
130             endorsing = true;
131         }
132         t = SecurityTokensModelHelper.getSupportingToken(input, SecurityTokensModelHelper.SIGNED_ENDORSING);
133         if (t != null) {
134             token = t;
135             signed = true;
136             endorsing = true;
137         }
138
139         signedChBox.setSelected(signed);
140         endorsingChBox.setSelected(endorsing);
141         tokenCombo.setSelectedItem(SecurityTokensModelHelper.getTokenType(token));
142
143         enableDisable();
144         
145         inSync = false;
146     }
147
148     @Override JavaDoc
149     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
150         if (!inSync) {
151             if (source.equals(tokenCombo)) {
152                 String JavaDoc token = (String JavaDoc) tokenCombo.getSelectedItem();
153                 if (token != null) {
154                     SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing));
155                 }
156                 enableDisable();
157             }
158             if (source.equals(signedChBox)) {
159                 String JavaDoc token = (String JavaDoc) tokenCombo.getSelectedItem();
160                 signed = signedChBox.isSelected();
161                 SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing));
162                 enableDisable();
163             }
164             if (source.equals(endorsingChBox)) {
165                 String JavaDoc token = (String JavaDoc) tokenCombo.getSelectedItem();
166                 endorsing = endorsingChBox.isSelected();
167                 SecurityTokensModelHelper.setSupportingTokens(input, token, getSuppType(signed, endorsing));
168                 enableDisable();
169             }
170         }
171     }
172     
173     private int getSuppType(boolean signed, boolean endorsing) {
174         if (signed && endorsing) return SecurityTokensModelHelper.SIGNED_ENDORSING;
175         if (signed) return SecurityTokensModelHelper.SIGNED_SUPPORTING;
176         if (endorsing) return SecurityTokensModelHelper.ENDORSING;
177         return SecurityTokensModelHelper.SUPPORTING;
178     }
179
180     @Override JavaDoc
181     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
182         SectionView view = getSectionView();
183         enableDisable();
184         if (view != null) {
185             view.getErrorPanel().clearError();
186         }
187     }
188
189     @Override JavaDoc
190     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
191     }
192     
193     @Override JavaDoc
194     protected void endUIChange() { }
195
196     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) { }
197
198     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
199         return new JButton();
200     }
201     
202     private void enableDisable() {
203         //TODO - enable when generic profile is enabled
204
boolean bSecurityEnabled = SecurityPolicyModelHelper.isSecurityEnabled(binding);
205         boolean oSecurityEnabled = SecurityPolicyModelHelper.isSecurityEnabled(operation);
206         
207         String JavaDoc profile = null;
208         if (bSecurityEnabled) {
209              profile = ProfilesModelHelper.getSecurityProfile(binding);
210         }
211         if (oSecurityEnabled) {
212             profile = ProfilesModelHelper.getSecurityProfile(operation);
213         }
214
215         boolean secConversation = ProfilesModelHelper.isSCEnabled(binding);
216         boolean bindingScopeTokenPresent = SecurityTokensModelHelper.getSupportingToken(binding,
217                 SecurityTokensModelHelper.SIGNED_SUPPORTING) != null;
218         boolean securityEnabled = bSecurityEnabled || oSecurityEnabled;
219         boolean genericProfile = true;
220 // if (ComboConstants.PROF_GENERIC.equals(profile)) {
221
// genericProfile = true;
222
// }
223

224         tokenCombo.setEnabled(securityEnabled && genericProfile && !secConversation && !bindingScopeTokenPresent);
225         tokenComboLabel.setEnabled(securityEnabled && genericProfile && !secConversation && !bindingScopeTokenPresent);
226 // configButton.setEnabled(securityEnabled && genericProfile);
227
targetsButton.setEnabled(securityEnabled);
228         boolean tokenSelected = !ComboConstants.NONE.equals((String JavaDoc)tokenCombo.getSelectedItem());
229         signedChBox.setEnabled(securityEnabled && tokenSelected && genericProfile && !secConversation && !bindingScopeTokenPresent);
230         endorsingChBox.setEnabled(securityEnabled && tokenSelected && genericProfile && !secConversation && !bindingScopeTokenPresent);
231     }
232     
233     /** This method is called from within the constructor to
234      * initialize the form.
235      * WARNING: Do NOT modify this code. The content of this method is
236      * always regenerated by the Form Editor.
237      */

238     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
239
private void initComponents() {
240
241         tokenComboLabel = new javax.swing.JLabel JavaDoc();
242         tokenCombo = new javax.swing.JComboBox JavaDoc();
243         targetsButton = new javax.swing.JButton JavaDoc();
244         signedChBox = new javax.swing.JCheckBox JavaDoc();
245         endorsingChBox = new javax.swing.JCheckBox JavaDoc();
246
247         tokenComboLabel.setLabelFor(tokenCombo);
248         org.openide.awt.Mnemonics.setLocalizedText(tokenComboLabel, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_tokenComboLabel")); // NOI18N
249

250         tokenCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "X509", "Username" }));
251
252         org.openide.awt.Mnemonics.setLocalizedText(targetsButton, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_SignEncrypt")); // NOI18N
253
targetsButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
254             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
255                 targetsButtonActionPerformed(evt);
256             }
257         });
258
259         org.openide.awt.Mnemonics.setLocalizedText(signedChBox, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_Token_Signed")); // NOI18N
260
signedChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
261         signedChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
262
263         org.openide.awt.Mnemonics.setLocalizedText(endorsingChBox, org.openide.util.NbBundle.getMessage(InputPanel.class, "LBL_Token_Endorsing")); // NOI18N
264
endorsingChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
265         endorsingChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
266
267         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
268         this.setLayout(layout);
269         layout.setHorizontalGroup(
270             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
271             .add(layout.createSequentialGroup()
272                 .addContainerGap()
273                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
274                     .add(layout.createSequentialGroup()
275                         .add(10, 10, 10)
276                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
277                             .add(signedChBox)
278                             .add(endorsingChBox)))
279                     .add(layout.createSequentialGroup()
280                         .add(tokenComboLabel)
281                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
282                         .add(tokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
283                     .add(targetsButton))
284                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
285         );
286         layout.setVerticalGroup(
287             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
288             .add(layout.createSequentialGroup()
289                 .addContainerGap()
290                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
291                     .add(tokenComboLabel)
292                     .add(tokenCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
293                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
294                 .add(signedChBox)
295                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
296                 .add(endorsingChBox)
297                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
298                 .add(targetsButton)
299                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
300         );
301     }// </editor-fold>//GEN-END:initComponents
302

303     private void targetsButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_targetsButtonActionPerformed
304
UndoCounter undoCounter = new UndoCounter();
305         model.addUndoableEditListener(undoCounter);
306
307         TargetsPanel targetsPanel = new TargetsPanel(input); //NOI18N
308
DialogDescriptor dlgDesc = new DialogDescriptor(targetsPanel,
309                 NbBundle.getMessage(InputPanel.class, "LBL_Targets_Panel_Title")); //NOI18N
310
Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(dlgDesc);
311         
312         dlg.setVisible(true);
313         if (dlgDesc.getValue() == dlgDesc.CANCEL_OPTION) {
314             for (int i=0; i<undoCounter.getCounter();i++) {
315                 if (undoManager.canUndo()) {
316                     undoManager.undo();
317                 }
318             }
319         } else {
320             SecurityPolicyModelHelper.setTargets(input, targetsPanel.getTargetsModel());
321         }
322         
323         model.removeUndoableEditListener(undoCounter);
324     }//GEN-LAST:event_targetsButtonActionPerformed
325

326     // Variables declaration - do not modify//GEN-BEGIN:variables
327
private javax.swing.JCheckBox JavaDoc endorsingChBox;
328     private javax.swing.JCheckBox JavaDoc signedChBox;
329     private javax.swing.JButton JavaDoc targetsButton;
330     private javax.swing.JComboBox JavaDoc tokenCombo;
331     private javax.swing.JLabel JavaDoc tokenComboLabel;
332     // End of variables declaration//GEN-END:variables
333

334 }
335
Popular Tags