KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.text.DefaultFormatterFactory JavaDoc;
24 import javax.swing.text.NumberFormatter JavaDoc;
25 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.RMMSModelHelper;
26 import org.netbeans.modules.websvc.wsitconf.wsdlmodelext.RMModelHelper;
27 import org.netbeans.modules.xml.wsdl.model.Binding;
28 import org.openide.nodes.Node;
29
30 import javax.swing.*;
31
32 /**
33  *
34  * @author Martin Grebac
35  */

36 public class AdvancedRMPanel extends JPanel {
37
38     private Node node;
39     private Binding binding;
40     private boolean inSync = false;
41
42     private DefaultFormatterFactory JavaDoc inactff = null;
43     private DefaultFormatterFactory JavaDoc maxBufff = null;
44     
45     public AdvancedRMPanel(Binding binding) {
46         this.node = node;
47         this.binding = binding;
48         
49         inactff = new DefaultFormatterFactory JavaDoc();
50         NumberFormat JavaDoc inactivityFormat = NumberFormat.getIntegerInstance();
51         inactivityFormat.setGroupingUsed(false);
52         NumberFormatter JavaDoc inactivityFormatter = new NumberFormatter JavaDoc(inactivityFormat);
53         inactivityFormat.setMaximumIntegerDigits(8);
54         inactivityFormatter.setCommitsOnValidEdit(true);
55         inactivityFormatter.setMinimum(0);
56         inactivityFormatter.setMaximum(99999999);
57         inactff.setDefaultFormatter(inactivityFormatter);
58                 
59         maxBufff = new DefaultFormatterFactory JavaDoc();
60         NumberFormat JavaDoc maxBufFormat = NumberFormat.getIntegerInstance();
61         maxBufFormat.setGroupingUsed(false);
62         NumberFormatter JavaDoc maxBufFormatter = new NumberFormatter JavaDoc(maxBufFormat);
63         maxBufFormat.setMaximumIntegerDigits(8);
64         maxBufFormatter.setCommitsOnValidEdit(true);
65         maxBufFormatter.setMinimum(0);
66         maxBufFormatter.setMaximum(99999999);
67         maxBufff.setDefaultFormatter(maxBufFormatter);
68
69         initComponents();
70         
71         sync();
72     }
73
74     private void sync() {
75         inSync = true;
76         
77         String JavaDoc inactivityTimeout = RMModelHelper.getInactivityTimeout(binding);
78         if (inactivityTimeout == null) { // no setup exists yet - set the default
79
setInactivityTimeout(RMModelHelper.DEFAULT_TIMEOUT);
80         } else {
81             setInactivityTimeout(inactivityTimeout);
82         }
83
84         String JavaDoc maxRcvBufferSize = RMMSModelHelper.getMaxReceiveBufferSize(binding);
85         if (maxRcvBufferSize == null) { // no setup exists yet - set the default
86
setMaxRcvBufferSize(RMModelHelper.DEFAULT_MAXRCVBUFFERSIZE);
87         } else {
88             setMaxRcvBufferSize(maxRcvBufferSize);
89         }
90
91         setFlowControl(RMMSModelHelper.isFlowControlEnabled(binding));
92
93         enableDisable();
94         inSync = false;
95     }
96
97     // max receive buffer size
98
private Number JavaDoc getMaxRcvBufferSize() {
99         return (Number JavaDoc) this.maxBufTextField.getValue();
100     }
101     
102     private void setMaxRcvBufferSize(String JavaDoc value) {
103         this.maxBufTextField.setText(value);
104     }
105
106     // inactivity timeout
107
private Number JavaDoc getInactivityTimeout() {
108         return (Number JavaDoc) this.inactivityTimeoutTextfield.getValue();
109     }
110     
111     private void setInactivityTimeout(String JavaDoc value) {
112         this.inactivityTimeoutTextfield.setText(value);
113     }
114
115     // flow control
116
private void setFlowControl(Boolean JavaDoc enable) {
117         if (enable == null) {
118             this.flowControlChBox.setSelected(false);
119         } else {
120             this.flowControlChBox.setSelected(enable);
121         }
122     }
123
124     public Boolean JavaDoc getFlowControl() {
125         if (flowControlChBox.isSelected()) {
126             return Boolean.TRUE;
127         }
128         return Boolean.FALSE;
129     }
130         
131     public void storeState() {
132
133         if (flowControlChBox.isSelected()) {
134             if (!(RMMSModelHelper.isFlowControlEnabled(binding))) {
135                 RMMSModelHelper.enableFlowControl(binding);
136             }
137         } else {
138             if (RMMSModelHelper.isFlowControlEnabled(binding)) {
139                 RMMSModelHelper.disableFlowControl(binding);
140             }
141         }
142         
143         Number JavaDoc timeout = getInactivityTimeout();
144         if ((timeout == null) || (RMModelHelper.DEFAULT_TIMEOUT.equals(timeout.toString()))) {
145             RMModelHelper.setInactivityTimeout(binding, null);
146         } else {
147             RMModelHelper.setInactivityTimeout(binding, timeout.toString());
148         }
149
150         Number JavaDoc bufSize = getMaxRcvBufferSize();
151         if ((bufSize == null) || (RMModelHelper.DEFAULT_MAXRCVBUFFERSIZE.equals(bufSize.toString()))) {
152             RMMSModelHelper.setMaxReceiveBufferSize(binding, null);
153         } else {
154             RMMSModelHelper.setMaxReceiveBufferSize(binding, bufSize.toString());
155         }
156
157     }
158     
159     private void enableDisable() {
160         boolean flowSelected = flowControlChBox.isSelected();
161         maxBufLabel.setEnabled(flowSelected);
162         maxBufTextField.setEnabled(flowSelected);
163     }
164     
165     /** This method is called from within the constructor to
166      * initialize the form.
167      * WARNING: Do NOT modify this code. The content of this method is
168      * always regenerated by the Form Editor.
169      */

170     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
171
private void initComponents() {
172         flowControlChBox = new javax.swing.JCheckBox JavaDoc();
173         maxBufLabel = new javax.swing.JLabel JavaDoc();
174         inactivityTimeoutLabel = new javax.swing.JLabel JavaDoc();
175         inactivityTimeoutTextfield = new javax.swing.JFormattedTextField JavaDoc();
176         maxBufTextField = new javax.swing.JFormattedTextField JavaDoc();
177
178         flowControlChBox.setText(org.openide.util.NbBundle.getMessage(AdvancedRMPanel.class, "LBL_AdvancedRM_FlowControlChBox"));
179         flowControlChBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
180         flowControlChBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
181         flowControlChBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
182             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
183                 flowControlChBoxActionPerformed(evt);
184             }
185         });
186
187         maxBufLabel.setText(org.openide.util.NbBundle.getMessage(AdvancedRMPanel.class, "LBL_AdvancedRM_maxBufLabel"));
188
189         inactivityTimeoutLabel.setText(org.openide.util.NbBundle.getMessage(AdvancedRMPanel.class, "LBL_AdvancedRM_InactivityTimeoutLabel"));
190
191         inactivityTimeoutTextfield.setFormatterFactory(inactff);
192
193         maxBufTextField.setColumns(8);
194         maxBufTextField.setFormatterFactory(maxBufff);
195
196         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
197         this.setLayout(layout);
198         layout.setHorizontalGroup(
199             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
200             .add(layout.createSequentialGroup()
201                 .addContainerGap()
202                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
203                     .add(flowControlChBox)
204                     .add(layout.createSequentialGroup()
205                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
206                             .add(maxBufLabel)
207                             .add(inactivityTimeoutLabel))
208                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
209                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
210                             .add(inactivityTimeoutTextfield, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
211                             .add(maxBufTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))))
212                 .addContainerGap())
213         );
214         layout.setVerticalGroup(
215             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
216             .add(layout.createSequentialGroup()
217                 .addContainerGap()
218                 .add(flowControlChBox)
219                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
220                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
221                     .add(maxBufLabel)
222                     .add(maxBufTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
223                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
224                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
225                     .add(inactivityTimeoutLabel)
226                     .add(inactivityTimeoutTextfield, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
227                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
228         );
229     }// </editor-fold>//GEN-END:initComponents
230

231     private void flowControlChBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_flowControlChBoxActionPerformed
232
enableDisable();
233     }//GEN-LAST:event_flowControlChBoxActionPerformed
234

235     // Variables declaration - do not modify//GEN-BEGIN:variables
236
private javax.swing.JCheckBox JavaDoc flowControlChBox;
237     private javax.swing.JLabel JavaDoc inactivityTimeoutLabel;
238     private javax.swing.JFormattedTextField JavaDoc inactivityTimeoutTextfield;
239     private javax.swing.JLabel JavaDoc maxBufLabel;
240     private javax.swing.JFormattedTextField JavaDoc maxBufTextField;
241     // End of variables declaration//GEN-END:variables
242

243 }
244
Popular Tags