KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > ui > wizards > AddServerPropertiesVisualPanel


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 package org.netbeans.modules.j2ee.oc4j.ui.wizards;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import javax.swing.event.DocumentListener JavaDoc;
32 import org.netbeans.modules.j2ee.oc4j.ui.wizards.AddServerPropertiesVisualPanel.ServerType;
33 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author pblaha
39  */

40 public class AddServerPropertiesVisualPanel extends javax.swing.JPanel JavaDoc {
41     
42     private String JavaDoc j2eeLocalHome;
43     private final List JavaDoc <ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
44     
45     /** Creates new form AddServerPropertiesVisualPanel1 */
46     public AddServerPropertiesVisualPanel(String JavaDoc j2eeLocalHome) {
47         this.j2eeLocalHome = j2eeLocalHome;
48         
49         setName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "TITLE_Properties"));
50         
51         initComponents();
52         
53         DocumentListener JavaDoc changeListener = new DocumentListener JavaDoc() {
54             public void changedUpdate(DocumentEvent JavaDoc e) {
55                 fireChange();
56             }
57             
58             public void removeUpdate(DocumentEvent JavaDoc e) {
59                 fireChange();
60             }
61             
62             public void insertUpdate(DocumentEvent JavaDoc e) {
63                 fireChange();
64             }
65         };
66         
67         hostTxt.getDocument().addDocumentListener(changeListener);
68         adminPortTxt.getDocument().addDocumentListener(changeListener);
69         portTxt.getDocument().addDocumentListener(changeListener);
70         passwordTxt.getDocument().addDocumentListener(changeListener);
71         
72         typeComboBox.addItemListener(new ItemListener JavaDoc() {
73             public void itemStateChanged(ItemEvent JavaDoc evt) {
74                 ServerType t = (ServerType) evt.getItem();
75                 
76                 if (t.equals(LOCAL)) {
77                     hostTxt.setText(LOCALHOST);
78                     hostTxt.setEnabled(false);
79                     usersComboBox.setEditable(false);
80                     webSiteComboBox.setEnabled(true);
81                 } else {
82                     hostTxt.setText("");
83                     hostTxt.setEnabled(true);
84                     usersComboBox.setEditable(true);
85                     webSiteComboBox.setSelectedItem(DEFAULT_WEB_SITE);
86                     webSiteComboBox.setEnabled(false);
87                     setInitialization(false);
88                 }
89             }
90         });
91         
92         setInitValues();
93     }
94     
95     public void setInitialization(boolean active) {
96         initializationPanel.setVisible(active);
97     }
98     
99     public void addChangeListener(ChangeListener JavaDoc l) {
100         synchronized (listeners) {
101             listeners.add(l);
102         }
103     }
104     
105     public void removeChangeListener(ChangeListener JavaDoc l) {
106         synchronized (listeners) {
107             listeners.remove(l);
108         }
109     }
110     
111     private void fireChange() {
112         Iterator JavaDoc it;
113         synchronized (listeners) {
114             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
115         }
116         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
117         while (it.hasNext()) {
118             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
119         }
120     }
121     
122     /** This method is called from within the constructor to
123      * initialize the form.
124      * WARNING: Do NOT modify this code. The content of this method is
125      * always regenerated by the Form Editor.
126      */

127     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
128
private void initComponents() {
129
130         userLbl = new javax.swing.JLabel JavaDoc();
131         passwordLbl = new javax.swing.JLabel JavaDoc();
132         passwordTxt = new javax.swing.JPasswordField JavaDoc();
133         adminPortLbl = new javax.swing.JLabel JavaDoc();
134         adminPortTxt = new javax.swing.JTextField JavaDoc();
135         portLbl = new javax.swing.JLabel JavaDoc();
136         portTxt = new javax.swing.JTextField JavaDoc();
137         webSiteLbl = new javax.swing.JLabel JavaDoc();
138         webSiteComboBox = new javax.swing.JComboBox JavaDoc();
139         usersComboBox = new javax.swing.JComboBox JavaDoc();
140         initializationPanel = new javax.swing.JPanel JavaDoc();
141         initializeButton = new javax.swing.JButton JavaDoc();
142         jLabel1 = new javax.swing.JLabel JavaDoc();
143         typeLbl = new javax.swing.JLabel JavaDoc();
144         typeComboBox = new javax.swing.JComboBox JavaDoc();
145         hostLbl = new javax.swing.JLabel JavaDoc();
146         hostTxt = new javax.swing.JTextField JavaDoc();
147         jSeparator1 = new javax.swing.JSeparator JavaDoc();
148
149         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/oc4j/ui/wizards/Bundle"); // NOI18N
150
org.openide.awt.Mnemonics.setLocalizedText(userLbl, bundle.getString("LBL_USER")); // NOI18N
151

152         passwordLbl.setLabelFor(passwordTxt);
153         org.openide.awt.Mnemonics.setLocalizedText(passwordLbl, bundle.getString("LBL")); // NOI18N
154

155         adminPortLbl.setLabelFor(adminPortTxt);
156         org.openide.awt.Mnemonics.setLocalizedText(adminPortLbl, bundle.getString("LBL_ADMIN_PORT")); // NOI18N
157

158         portLbl.setLabelFor(portTxt);
159         org.openide.awt.Mnemonics.setLocalizedText(portLbl, bundle.getString("LBL_HTTP_PORT")); // NOI18N
160

161         webSiteLbl.setLabelFor(webSiteComboBox);
162         org.openide.awt.Mnemonics.setLocalizedText(webSiteLbl, bundle.getString("LBL_WEB_SITE")); // NOI18N
163

164         initializationPanel.setBackground(new java.awt.Color JavaDoc(204, 204, 204));
165         initializationPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color JavaDoc(0, 0, 0)));
166
167         initializeButton.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_InitializationTitle", new Object JavaDoc[] {})); // NOI18N
168
initializeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
169             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
170                 initializeButtonActionPerformed(evt);
171             }
172         });
173
174         jLabel1.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_Initialization", new Object JavaDoc[] {})); // NOI18N
175

176         org.jdesktop.layout.GroupLayout initializationPanelLayout = new org.jdesktop.layout.GroupLayout(initializationPanel);
177         initializationPanel.setLayout(initializationPanelLayout);
178         initializationPanelLayout.setHorizontalGroup(
179             initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
180             .add(org.jdesktop.layout.GroupLayout.TRAILING, initializationPanelLayout.createSequentialGroup()
181                 .addContainerGap()
182                 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 198, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
183                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 24, Short.MAX_VALUE)
184                 .add(initializeButton)
185                 .addContainerGap())
186         );
187         initializationPanelLayout.setVerticalGroup(
188             initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
189             .add(initializationPanelLayout.createSequentialGroup()
190                 .addContainerGap()
191                 .add(initializationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
192                     .add(initializeButton)
193                     .add(jLabel1))
194                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
195         );
196
197         typeLbl.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/oc4j/ui/wizards/Bundle").getString("LBL_SERVER_TYPE").charAt(0));
198         typeLbl.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_SERVER_TYPE")); // NOI18N
199

200         hostLbl.setText(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "LBL_HOST")); // NOI18N
201

202         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
203         this.setLayout(layout);
204         layout.setHorizontalGroup(
205             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
206             .add(layout.createSequentialGroup()
207                 .addContainerGap()
208                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
209                     .add(initializationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
210                     .add(layout.createSequentialGroup()
211                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
212                             .add(hostLbl)
213                             .add(typeLbl))
214                         .add(53, 53, 53)
215                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
216                             .add(typeComboBox, 0, 250, Short.MAX_VALUE)
217                             .add(org.jdesktop.layout.GroupLayout.LEADING, hostTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)))
218                     .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
219                     .add(layout.createSequentialGroup()
220                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
221                             .add(userLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
222                             .add(passwordLbl)
223                             .add(adminPortLbl)
224                             .add(portLbl)
225                             .add(webSiteLbl))
226                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
227                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
228                             .add(webSiteComboBox, 0, 250, Short.MAX_VALUE)
229                             .add(portTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
230                             .add(adminPortTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
231                             .add(passwordTxt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
232                             .add(usersComboBox, 0, 250, Short.MAX_VALUE))))
233                 .addContainerGap())
234         );
235         layout.setVerticalGroup(
236             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
237             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
238                 .addContainerGap()
239                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
240                     .add(typeLbl)
241                     .add(typeComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
242                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
243                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
244                     .add(hostLbl)
245                     .add(hostTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
246                 .add(14, 14, 14)
247                 .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
248                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
249                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
250                     .add(userLbl)
251                     .add(usersComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
252                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
253                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
254                     .add(passwordLbl)
255                     .add(passwordTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
256                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
257                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
258                     .add(adminPortLbl)
259                     .add(adminPortTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
260                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
261                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
262                     .add(portLbl)
263                     .add(portTxt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
264                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
265                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
266                     .add(webSiteComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
267                     .add(webSiteLbl))
268                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 92, Short.MAX_VALUE)
269                 .add(initializationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
270                 .addContainerGap())
271         );
272
273         passwordTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_PASSWD_TXT")); // NOI18N
274
passwordTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_PASSWD_TXT")); // NOI18N
275
adminPortTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_ADMIN_PORT_TXT")); // NOI18N
276
adminPortTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_ADMIN_PORT_TXT")); // NOI18N
277
portTxt.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_HTTP_PORT_TXT")); // NOI18N
278
portTxt.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_HTTP_PORT_TXT")); // NOI18N
279
webSiteComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_WEB_SITES_CMB")); // NOI18N
280
webSiteComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_WEB_SITES_CMB")); // NOI18N
281

282         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_NAME_PANEL")); // NOI18N
283
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AddServerPropertiesVisualPanel.class, "A11Y_DESC_PANEL")); // NOI18N
284
}// </editor-fold>//GEN-END:initComponents
285

286 private void initializeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_initializeButtonActionPerformed
287

288     initializeButton.setEnabled(false);
289     
290     String JavaDoc password = null;
291     
292     while(password == null || password.equals(ADMIN_USER)) {
293         password = OC4JPluginUtils.requestPassword(ADMIN_USER);
294     }
295     
296     if(OC4JPluginUtils.activateUser(j2eeLocalHome, ADMIN_USER, password)) {
297         initializeButton.setEnabled(true);
298         setInitialization(false);
299         passwordTxt.setText(password);
300         fireChange();
301     }
302     
303     initializeButton.setEnabled(true);
304     fireChange();
305 }//GEN-LAST:event_initializeButtonActionPerformed
306

307 public ServerType getType() {
308     return (ServerType) typeComboBox.getSelectedItem();
309 }
310
311 public String JavaDoc getHost() {
312     return hostTxt.getText().trim();
313 }
314
315 public String JavaDoc getAdminPort() {
316     return adminPortTxt.getText().trim();
317 }
318
319 public String JavaDoc getPassword() {
320     return new String JavaDoc(passwordTxt.getPassword());
321 }
322
323 public String JavaDoc getUser() {
324     return (String JavaDoc) usersComboBox.getSelectedItem();
325 }
326
327 public String JavaDoc getPort() {
328     return portTxt.getText().trim();
329 }
330
331 public String JavaDoc getWebSite() {
332     return (String JavaDoc)webSiteComboBox.getSelectedItem();
333 }
334
335 private void setInitValues() {
336     usersComboBox.removeAllItems();
337     
338     portTxt.setText(Integer.toString(OC4JPluginUtils.getHttpPort(j2eeLocalHome, "default")));
339     adminPortTxt.setText(Integer.toString(OC4JPluginUtils.getAdminPort(j2eeLocalHome)));
340     
341     for (String JavaDoc item : OC4JPluginUtils.getWebSites(j2eeLocalHome))
342         webSiteComboBox.addItem(item);
343     
344     for (String JavaDoc item : OC4JPluginUtils.getUsers(j2eeLocalHome)) {
345         usersComboBox.addItem(item);
346     }
347     
348     typeComboBox.addItem(LOCAL);
349     typeComboBox.addItem(REMOTE);
350     
351     setInitialization(false);
352 }
353
354     // Variables declaration - do not modify//GEN-BEGIN:variables
355
private javax.swing.JLabel JavaDoc adminPortLbl;
356     private javax.swing.JTextField JavaDoc adminPortTxt;
357     private javax.swing.JLabel JavaDoc hostLbl;
358     private javax.swing.JTextField JavaDoc hostTxt;
359     private javax.swing.JPanel JavaDoc initializationPanel;
360     private javax.swing.JButton JavaDoc initializeButton;
361     private javax.swing.JLabel JavaDoc jLabel1;
362     private javax.swing.JSeparator JavaDoc jSeparator1;
363     private javax.swing.JLabel JavaDoc passwordLbl;
364     private javax.swing.JPasswordField JavaDoc passwordTxt;
365     private javax.swing.JLabel JavaDoc portLbl;
366     private javax.swing.JTextField JavaDoc portTxt;
367     private javax.swing.JComboBox JavaDoc typeComboBox;
368     private javax.swing.JLabel JavaDoc typeLbl;
369     private javax.swing.JLabel JavaDoc userLbl;
370     private javax.swing.JComboBox JavaDoc usersComboBox;
371     private javax.swing.JComboBox JavaDoc webSiteComboBox;
372     private javax.swing.JLabel JavaDoc webSiteLbl;
373     // End of variables declaration//GEN-END:variables
374

375     private final static String JavaDoc LOCALHOST = "localhost";
376     private final static String JavaDoc ADMIN_USER = "oc4jadmin";
377     private final static String JavaDoc DEFAULT_WEB_SITE = "default";
378     
379     protected final static ServerType LOCAL = new ServerType("Local Server");
380     protected final static ServerType REMOTE = new ServerType("Remote Server");
381     
382     protected final static class ServerType {
383         
384         private String JavaDoc description;
385         
386         public ServerType(String JavaDoc description) {
387             this.description = description;
388         }
389         
390         @Override JavaDoc
391         public String JavaDoc toString() {
392             return description;
393         }
394     }
395 }
Popular Tags