KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > ui > AddInstanceVisualInstancePanel


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 package org.netbeans.modules.j2ee.sun.ide.j2ee.ui;
20
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import org.openide.ErrorManager;
28 import org.openide.util.NbBundle;
29
30 final class AddInstanceVisualInstancePanel extends JPanel JavaDoc {
31
32     /**
33      * Creates new form AddInstanceVisualInstancePanel
34      */

35     AddInstanceVisualInstancePanel() {
36         initComponents();
37     }
38     
39     void setDomainsList(Object JavaDoc[] domainsList) {
40         if (domainsList != null) {
41             instanceSelector.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(domainsList));
42         } else {
43             instanceSelector.setModel(new javax.swing.DefaultComboBoxModel JavaDoc());
44         }
45     }
46         
47     String JavaDoc getDomainDir() {
48         String JavaDoc tmp = (String JavaDoc) instanceSelector.getSelectedItem();
49         if (null == tmp)
50             return null;
51         int firstParen = tmp.lastIndexOf('(');
52         int lastParen = tmp.lastIndexOf(')');
53         if (firstParen < 0) {
54             ErrorManager.getDefault().log(ErrorManager.ERROR,
55                     NbBundle.getMessage(AddInstanceVisualInstancePanel.class,
56                     "ERRMSG_PARSE_DOMAIN_DIR", tmp));
57             return null;
58         }
59         if (lastParen < 0) {
60             ErrorManager.getDefault().log(ErrorManager.ERROR,
61                     NbBundle.getMessage(AddInstanceVisualInstancePanel.class,
62                     "ERRMSG_PARSE_DOMAIN_DIR", tmp));
63             return null;
64         }
65         if (lastParen < firstParen) {
66             ErrorManager.getDefault().log(ErrorManager.ERROR,
67                     NbBundle.getMessage(AddInstanceVisualInstancePanel.class,
68                     "ERRMSG_PARSE_DOMAIN_DIR", tmp));
69             return null;
70         }
71         return tmp.substring(firstParen+1,lastParen);
72     }
73
74     public String JavaDoc getName() {
75         return NbBundle.getMessage(AddInstanceVisualInstancePanel.class,
76                 "StepName_PickDefaultInstance"); // NOI18N
77
}
78     
79     // Event Handling
80
//
81
private Set JavaDoc/*<ChangeListener.*/ listenrs = new HashSet JavaDoc/*<Changelisteners.*/();
82
83     void addChangeListener(ChangeListener JavaDoc l) {
84         synchronized (listenrs) {
85             listenrs.add(l);
86         }
87     }
88     
89     void removeChangeListener(ChangeListener JavaDoc l ) {
90         synchronized (listenrs) {
91             listenrs.remove(l);
92         }
93     }
94
95     private void fireChangeEvent() {
96         Iterator JavaDoc it;
97         synchronized (listenrs) {
98             it = new HashSet JavaDoc(listenrs).iterator();
99         }
100         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
101         while (it.hasNext()) {
102             ((ChangeListener JavaDoc)it.next()).stateChanged (ev);
103         }
104     }
105     
106     /** This method is called from within the constructor to
107      * initialize the form.
108      * WARNING: Do NOT modify this code. The content of this method is
109      * always regenerated by the Form Editor.
110      */

111     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
112
private void initComponents() {
113         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
114
115         description = new javax.swing.JLabel JavaDoc();
116         instanceSelectorLabel = new javax.swing.JLabel JavaDoc();
117         instanceSelector = new javax.swing.JComboBox JavaDoc();
118         spacingHack = new javax.swing.JLabel JavaDoc();
119
120         setLayout(new java.awt.GridBagLayout JavaDoc());
121
122         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/j2ee/ui/Bundle"); // NOI18N
123
description.setText(bundle.getString("TXT_instancePanelDescription")); // NOI18N
124
description.setFocusable(false);
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridwidth = 3;
127         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
128         gridBagConstraints.weightx = 1.0;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
130         add(description, gridBagConstraints);
131         description.getAccessibleContext().setAccessibleName("Select the default domain to register");
132
133         instanceSelectorLabel.setLabelFor(instanceSelector);
134         org.openide.awt.Mnemonics.setLocalizedText(instanceSelectorLabel, org.openide.util.NbBundle.getMessage(AddInstanceVisualInstancePanel.class, "LBL_instanceSelectorLabel")); // NOI18N
135
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.gridy = 1;
137         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
138         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 5, 6);
140         add(instanceSelectorLabel, gridBagConstraints);
141
142         instanceSelector.addActionListener(new java.awt.event.ActionListener JavaDoc() {
143             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
144                 instanceSelectorActionPerformed(evt);
145             }
146         });
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridy = 1;
149         gridBagConstraints.gridwidth = 2;
150         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
152         add(instanceSelector, gridBagConstraints);
153         instanceSelector.getAccessibleContext().setAccessibleDescription(bundle.getString("DSC_instanceSelector")); // NOI18N
154

155         spacingHack.setEnabled(false);
156         spacingHack.setFocusable(false);
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridy = 3;
159         gridBagConstraints.weighty = 1.0;
160         add(spacingHack, gridBagConstraints);
161     }// </editor-fold>//GEN-END:initComponents
162

163     private void instanceSelectorActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_instanceSelectorActionPerformed
164
fireChangeEvent();
165     }//GEN-LAST:event_instanceSelectorActionPerformed
166

167
168     // Variables declaration - do not modify//GEN-BEGIN:variables
169
private javax.swing.JLabel JavaDoc description;
170     private javax.swing.JComboBox JavaDoc instanceSelector;
171     private javax.swing.JLabel JavaDoc instanceSelectorLabel;
172     private javax.swing.JLabel JavaDoc spacingHack;
173     // End of variables declaration//GEN-END:variables
174

175 }
176
177
Popular Tags